Skip to content

Text echoes after using backtick on Windows 11 command prompt/powershell #676

Closed

Description

@andrewngo

Description

What are your expected behavior and actual behavior of your environment?

After using a backtick command, Readline behaves strangely, sometimes it echoes all input and sometimes it doesn't show my input at all.

older version of irb/reline

irb(main):001:0> `choco -v`
=> "2.2.0\n"
irb(main):002:0> irb(main):002:0> p█████████      irb(main):002:0> pu       ppppppppirb(main):002:0> put      ppirb(main):002:0> puts  irb(main):002:0> puts irb(main):002:0> puts 'irb(main):002:0' puts 'hirb(main):002:0' puts 'heirb(main):002:0' puts 'helirb(main):002:0' puts 'hellirb(main):002:0' puts 'helloirb(main):002:0' puts 'hello'hello
=> nil
irb(main):003:0> irb(main):003:0> eeeeeeeeeeeeeirb(main):003:0> ex        eeeeirb(main):003:0> exi  eeirb(main):003:0> exitee

other times (latest irb/reline) it doesn't show my input until I press 'enter'

irb(main):001> `choco -v`
=> "2.2.0\n"
i▀irb(main):002> puts 'hi'
hi
=> nil
i▀irb(main):003> exit

Terminal Emulator

What's your terminal emulator?
Windows 11 Powershell/Terminal

ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e)

*** LOCAL GEMS ***
irb (1.12.0)
reline (0.5.1)

Activity

  1. andrewngo commented on Apr 10, 2024

    @andrewngo
    Author

    Adding these gems seem to workaround the issue for me for now

    gem 'readline'
    gem 'readline-ext'
    

    edit: these gems do cause copy/paste to behave oddly so it's more of a trade-off than workaround now

  2. tompng commented on Apr 11, 2024

    @tompng
    Member

    For investigation, can you check these value before and after problem occurs?

    Reline::IOGage.get_screen_size
    Reline::IOGage.get_console_screen_buffer_info
    STDIN.winsize
    

    Does it happens with specific command or any command?

  3. andrewngo commented on Apr 11, 2024

    @andrewngo
    Author

    I don't see the issue with commands like echo "hello", but other apps like ruby -v, chromedriver -v or choco are all issues

    irb(main):002> Reline::IOGate.get_screen_size
    => [30, 120]
    irb(main):003> Reline::IOGate.get_console_screen_buffer_info
    => "x\x00\x1E\x00\x00\x00\x1D\x00\a\x00\x00\x00\x00\x00w\x00\x1D\x00x\x00\x1E\x00"
    irb(main):004> STDIN.winsize
    (irb):4:in `winsize': Bad file descriptor - <STDIN> (Errno::EBADF)
            from (irb):4:in `<main>'
            from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/irb-1.12.0/exe/irb:9:in `<top (required)>'
            from C:/Ruby31-x64/bin/irb:32:in `load'
            from C:/Ruby31-x64/bin/irb:32:in `<main>'
    

    after

    irb(main):006> `chromedriver -v`
    => "ChromeDriver 123.0.6312.122 (31f8248cdd90acbac59f700b603fed0b5967ca50-refs/branch-heads/6312@{#824})\n"
    iirb(main):007> Reline::IOGate.get_screen_size
    =>
    [1,
     1]
    iirb(main):008> Reline::IOGate.get_console_screen_buffer_info
    => nil
    i▀irb(main):009> STDIN.winsize
    (irb):9:in `winsize': Bad file descriptor - <STDIN> (Errno::EBADF)
            from (irb):9:in `<main>'
            from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/irb-1.12.0/exe/irb:9:in `<top (required)>'
            from C:/Ruby31-x64/bin/irb:32:in `load'
            from C:/Ruby31-x64/bin/irb:32:in `<main>'
    
  4. andrewngo commented on May 23, 2024

    @andrewngo
    Author

    Tried with Ruby 3.2 and reline 0.5.7 in Windows 11 Powershell, and it still behaves oddly.

    I can see that GetConsoleScreenBufferInfo is returning 0 which indicates an issue but not sure what is causing it. Fiddle.win32_last_error shows 6, which seems to map to ERROR_INVALID_HANDLE

    return if @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi) == 0

    image

  5. andrewngo commented on Sep 6, 2024

    @andrewngo
    Author

    Fix looks good to me in v.0.5.10. Thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    WindowsbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions