Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul io gate structure #666

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Mar 25, 2024

I think the current IO gate design has a few non-functional issues:

  1. Their source don't indicate that they're IO gate classes. Usually for task-specific components like this, the files would be contained in the same folder and their would be a abstract super class to define shared methods/states.
  2. These IO gate classes are not used as classes but singleton modules. This means
    • States are all defined as class variables right when the file is required.
    • If we change any state on Reline::IOGate, like in tests, we need to reset it back through redefining the methods, which is pretty hacky.

This PR addresses the issues by:

  • Moving io gate classes into a dedicated folder
  • Converting io gate classes into normal Ruby classes and change class variable states into instance variables
  • Renaming GeneralIO to Dumb to better reflect its role

@st0012 st0012 force-pushed the overhaul-io-gate-structure branch from 978f779 to af6d3ff Compare March 25, 2024 13:18
@st0012
Copy link
Member Author

st0012 commented Mar 25, 2024

The readline test failures are caused by readline-ext manually setting IOGate. I think making it call Reline.test_mode directly may address the issue.

I'm not sure what causes the windows failure though and I don't have a windows machine. Any help would be appreciated 🙏

@tompng Do you want me to include the changes in #659 here?

@@ -22,29 +22,24 @@ module Reline
class <<self
def test_mode(ansi: false)
@original_iogate = IOGate
remove_const('IOGate')
const_set('IOGate', ansi ? Reline::ANSI : Reline::GeneralIO)
@original_screen_size = @original_iogate.get_screen_size
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this @original_screen_size and IOGate.set_screen_size(*@original_screen_size) is not needed because we don't modify @original_iogate anymore.

(perhaps this is causing windows test failure)

@tompng
Copy link
Member

tompng commented Mar 25, 2024

Looks good 👍

For #659, I think separate pull request is better

@st0012 st0012 force-pushed the overhaul-io-gate-structure branch from af6d3ff to e7855d7 Compare March 25, 2024 17:36
class Reline::Dumb < Reline::IO
RESET_COLOR = '' # Do not send color reset sequence

def initialize(encoding: Encoding.default_external)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think default value of encoding should be nil, or we need to check RUBY_PLATFORM.
If @encoding is always set, we can't get into elsif RUBY_PLATFORM =~ /mswin|mingw/ branch in def encoding and this seems to be the reason CI (irb) is failing. (but I can't reproduce the failing in my local environment...)

@tompng
Copy link
Member

tompng commented Apr 1, 2024

CI / readline can be passed by setting Reline::GeneralIO = Dumb.new, perhaps as deprecated constant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants