Skip to content

Arrows ignored by bash when it started in ConEmu #111

Closed

Description

I'm the author of ConEmu - alternative terminal for Windows. My users have created the issue ConEmu/ConEmu#629. When bash is started in ConEmu console, it totally ignores all extended keys (Arrows, Fn, etc.), so users can't access command line history with Up/Down arrows.

What is the problem with bash? Up/Down arrows properly cycle cmd.exe history, when it's started in ConEmu, but bash ignores them.

ConEmu is GUI application, so it get keyboard events via WM_KEYUP/WM_KEYDOWN and forward them to the created (usually hidden) real console using WriteConsoleInput.

Activity

  1. Maximus5 commented on Apr 12, 2016

    @Maximus5
    Author

    I've created workaround in ConEmu build 160411. However, it would be nice to know, is it a bug or intended behavior.

  2. Maximus5 commented on Apr 13, 2016

    @Maximus5
    Author

    Unfortunately, arrow keys still do not work in vim.

  3. sunilmut commented on Apr 13, 2016

    @sunilmut
    Member

    bash.exe has its own logic to read from console directly (this is as per the design today and subject to change in future releases). I am not a console expert, but I wonder if ConEmu interacting with the console directly is interfering with bash.exe's ability to process keyboard events?

  4. Maximus5 commented on Apr 13, 2016

    @Maximus5
    Author

    ConEmu use official console API WriteConsoleInput to post keypressed into the conhost input buffer. That worked perfectly until "Bash on Ubuntu" appears.

  5. sunilmut commented on Apr 13, 2016

    @sunilmut
    Member

    Ok. I am not sure I fully understand the problem here. My understanding of this issue is that bash is not able to process arrow keys when launched from within ConEmu? Can you help clarify.

  6. Maximus5 commented on Apr 13, 2016

    @Maximus5
    Author

    Short answer: Yes.

    Many words below.
    Let's take for example UpArrow key.

    When user press and release UpArrow, normal console application
    recieves two console key events:

    1. bKeyDown = TRUE; wVirtualKeyCode = VK_UP;
    2. bKeyDown = FALSE; wVirtualKeyCode = VK_UP;
      References: PeekConsoleInput, ReadConsoleInput, INPUT_RECORD, KEY_EVENT_RECORD.

    But Unix console applications expect different key sequences.
    For UpArrow keypress either ESC [ A or ESC O A sequences are expected
    depending on requested ‘DECCKM’ mode.
    References: ANSI sequence ESC [ ? 1 h and ESC [ ? 1 l.

    The bash.exe is Windows console application, therefore it's expected
    that this application would work properly with standard Windows console API
    keypresses (KEY_EVENT_RECORD, VK_UP). But, I'm not sure who, the translation
    is done when user presses UpArrow. And bash.exe recieves ESC [ A instead.

    Well, that is rude workaround, but if bash.exe is started in ConEmu with
    -cur_console:p1 switch, ConEmu does this translation and arrows magically
    start working.

    That is really rude, because ConEmu does not recieve ANSI sequences from
    linux processes. And, when user starts vim from bash prompt, ‘DECCKM’ is not changed.
    Therefore, ‘Arrows are not working in vim under ConEmu’.
    There are absolutely no way to determine that vim was started from bash,
    or vim has requested to change ‘DECCKM’ mode.
    Seems like linux processes (init, bash, vim) somehow write their console output
    directly to conhost, bypassing bash.exe. That's bad, because ConEmu has absolutely
    no control over linux processes (started from service), only bash.exe may be hooked
    to catch it's output and ‘fix’ input.

    If you would like to check, download latest ConEmu build (alpha 160411 ATM),
    and run from Win+R:

    ConEmu.exe -basic -cmd bash.exe -cur_console:p1
    
  7. Maximus5 commented on May 2, 2016

    @Maximus5
    Author

    Sure, it is. Monday, 02 May 2016, 07:09PM +03:00 from Daniel Gordon < [email protected]> :

    So Just to be clear here - you guys are talking about bash.exe - that is or is not the same thing as the new Ubuntu Subsystem in the most recent Windows 10 dev build?
    —
    You are receiving this because you authored the thread.
    Reply to this email directly or view it on GitHub

  8. DanielGGordon commented on May 2, 2016

    @DanielGGordon

    Maksim Moisiuk (@Maximus5) I deleted my comment because I figured it out on my own by looking at the top of this page 10 seconds after I posted my comment... Sorry for the confusion.

  9. dariobig commented on May 14, 2016

    @dariobig

    Hi, console2 and consoleZ, two other terminal emulators, have the same problem with arrows not working on bash.

  10. Maximus5 commented on May 14, 2016

    @Maximus5
    Author

    @bigonazzi Of course they are. Only ConEmu is able to send xterm-ish keyboard sequences, which LX kernel expects.

  11. xilun commented on May 14, 2016

    @xilun

    Just would like to add that IMO this is quite important to have WSL working properly with ConEmu, because some serious console users (myself included) are not going to be satisfied with the basic Windows Console (which is now quite better than the legacy one, but still far away from any random XWindow Console we are used to)

    For now I'm doing some dev under WSL on the Windows Console (for now coping with the international keyboard bugs it has by switching to a US layout) but I will be seriously disappointed if I can't use ConEmu for a vast majority of WSL software, and that obviously includes vim...

    Maksim Moisiuk (@Maximus5) thanks for your excellent ConEmu btw :)

  12. dariobig commented on May 14, 2016

    @dariobig

    Guillaume Knispel (@xilun) +1

    Maksim Moisiuk (@Maximus5) I like conemu, all I'm saying is that the issue is bigger than just one program and it should be addressed with high priority.

  13. Darktex commented on May 14, 2016

    @Darktex

    Guillaume Knispel (@xilun) +1

    The Windows default terminals don't have nearly enough features for any power user

  14. djmott commented on May 28, 2016

    @djmott

    Maksim Moisiuk (@Maximus5) thank you for ConEmu. It's a huge productivity improvement. MS should ditch the POS default console, give you a few million USD and ship it with every install of Windows.

  15. 61 remaining items

  16. jarun commented on Sep 8, 2017

    @jarun

    Good news. 👍 I just wasted an hour figuring out the issue and reached here.

  17. rprichard commented on Sep 8, 2017

    @rprichard

    Mike Griese (@zadjii-msft) Good to hear. A few questions:

    1. Does this also affect recognition of Ctrl-C or Ctrl-Break? That is, when ENABLE_PROCESSED_INPUT is on, will WriteConsoleInput send a signal for these key presses? It currently doesn't, and I'm guessing that won't change. (If it did, I might be able to fix Ctrl-C handling is inadequate for interactive cmd and PowerShell rprichard/winpty#116.)

    2. Is mouse input affected? There's an analogous situation where mouse input should produce VT escape sequences, and the encoding is controlled by mouse mode flags (e.g. 1006 for the "SGR mouse encoding"). I haven't gotten around to testing the console yet, so maybe WriteConsoleInput calls already do this conversion.

    3. Do you have suggestions on how programs can detect this behavior change (i.e. so that a workaround can be disabled)? For my situation (winpty), I think it'd be worth it to temporarily enable the VT input mode and test whether input is converted (by calling WriteConsoleInput then ReadConsoleInput). I'm guessing there isn't a better approach, though I suppose checking the OS version could be faster.

  18. ericblade commented on Sep 11, 2017

    @ericblade

    That is great news (not so great that it won't make Fall.. oh well :-) ) .. just curious if this means that it ended up being significantly less work than initially expected? :-D

  19. zadjii-msft commented on Sep 11, 2017

    @zadjii-msft
    Member

    Ryan Prichard (@rprichard)

    1. I don't believe it will. The change is pretty limited in scope to just the VT translator, so I don't believe any of the rest of the input is modified.
    2. Mouse is unfortunately not fixed by this change. The keyboard events were easier to move than the mouse events unfortunately. I have a work item to address that issue before the end of the next release.
    3. I don't have any good recommendations on that topic, sorry. Both the mechanisms you describe sound like they should work, though I have no idea which would be faster.

    It was a bit easier than anticipated, but like I mentioned, mouse input is actually harder than anticipated unfortunately.

  20. bgshacklett commented on Sep 11, 2017

    @bgshacklett

    Sorry, guys, I know you're being bombarded, but can you tell us how being on the Windows Insider fast track might affect the speed at which we see some of these changes?

  21. zadjii-msft commented on Sep 11, 2017

    @zadjii-msft
    Member

    Brian G. Shacklett (@bgshacklett) If you're on the fast ring, you'll see these changes pretty immediately after they hit winmain, which is usually a month or so after I commit the code on my end. Otherwise, if you're on just a non-insider's build, you'll have to wait for the entire release to be finished, which is about twice a year (based on previous Windows 10 releases)

  22. bitcrazed commented on May 22, 2018

    @bitcrazed
    Contributor

    Thanks for the discussion.

    Closing this issue since:

    1. This issue is now fixed
    2. This is the WSL issues repo, but this is an issue in Console which has its own Console GitHub Repo
    3. GitHub doesn't allow issues to be moved between repos, preserving posters' identity :(

    If you have further asks/issues, please file new issues on our Console GitHub Repo.

  23. maietta commented on Aug 27, 2023

    @maietta

    I DO NOT CARE WHAT YOU PEOPLE KEEP SAYING. THIS ISSUE IS NOT FIXED IN WINDWOS 11 AND WSL2.

    Why is this still an issue in 2023?

  24. zadjii-msft commented on Aug 28, 2023

    @zadjii-msft
    Member

    Nick Maietta (@maietta) This issue was closed 5 years ago. The console codebase has had a tremendous amount of churn since then. Whatever you're seeing now probably has a new root cause. I'd recommend filing a new issue over at https://github.com/microsoft/terminal/issues, so we can ID whatever's causing what you're seeing.

    Thanks!

  25. nikhil-swamix commented on Aug 23, 2024

    @nikhil-swamix

    for people running cli scripts in python: disable this

    Terminal › Integrated: Windows Enable Conpty

    key navigation will work, for packages like rich, fire, click cli tools...

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions