{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/32805","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/32805/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/32805/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/32805/events","html_url":"https://github.com/dotnet/corefx/issues/32805","id":369779709,"node_id":"MDU6SXNzdWUzNjk3Nzk3MDk=","number":32805,"title":"Terminal hardware is always left in application mode (keypad_xmit) after running a console program","user":{"login":"kkm000","id":8228229,"node_id":"MDQ6VXNlcjgyMjgyMjk=","avatar_url":"https://avatars3.githubusercontent.com/u/8228229?v=4","gravatar_id":"","url":"https://api.github.com/users/kkm000","html_url":"https://github.com/kkm000","followers_url":"https://api.github.com/users/kkm000/followers","following_url":"https://api.github.com/users/kkm000/following{/other_user}","gists_url":"https://api.github.com/users/kkm000/gists{/gist_id}","starred_url":"https://api.github.com/users/kkm000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkm000/subscriptions","organizations_url":"https://api.github.com/users/kkm000/orgs","repos_url":"https://api.github.com/users/kkm000/repos","events_url":"https://api.github.com/users/kkm000/events{/privacy}","received_events_url":"https://api.github.com/users/kkm000/received_events","type":"User","site_admin":false},"labels":[{"id":261819097,"node_id":"MDU6TGFiZWwyNjE4MTkwOTc=","url":"https://api.github.com/repos/dotnet/corefx/labels/area-System.Console","name":"area-System.Console","color":"d4c5f9","default":false},{"id":145399955,"node_id":"MDU6TGFiZWwxNDUzOTk5NTU=","url":"https://api.github.com/repos/dotnet/corefx/labels/bug","name":"bug","color":"207de5","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-10-13T08:11:10Z","updated_at":"2018-10-15T21:55:02Z","closed_at":null,"author_association":"NONE","body":"This problem has been annoying me for quite a while, and I worked around it by emitting the `rmkx` terminfo sequence in my bash prompt. But I still think it makes sense to report it. Basically, after (almost?) any `dotnet` command that involves CLR console I/O, the terminal emulator is left in the application mode (`keypad_xmit`), messing my command line handling (e. g. arrows move by word `<ESC> O C`, not by character `<ESC> C`, in readline bash prompt, etc. -- probably because of my customized `.inputrc`, designed to work with both VT100 and rxvt style emulators). Other programs behave nice; e. g., just typing `man man`, or invoking `less` or `vim` and then exiting them reverts keyboard to local keypad mode. Just for reference, this is a hopelessly headless Ubuntu 18.04 machine:\r\n```\r\n$ uname -a\r\nLinux yupana 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux\r\n$ echo $TERM\r\nxterm-256color\r\n$ dotnet --version\r\n2.1.403\r\n```\r\nI noticed by using a script(1) dump that the `smkx` aka `keypad_xmit` code is emitted more than once, but then there is no reverting `rmkx` aka `keypad_local` emitted ever. Here is, for example, how captured prologue of `dotnet build` looks (not marking literal linefeeds), that emits `keypad_xmit` twice:\r\n```\r\nScript started on 2018-10-12 23:02:55-0700\r\n. . .\r\ndotnet build -c Release -v:n\r\n<ESC>[?1h<ESC>=Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core\r\n\r\nCopyright (C) Microsoft Corporation. All rights reserved.\r\n\r\n<ESC>[?1h<ESC>=Build started 10/12/18 11:00:40 PM.\r\n```\r\nI just attempted to trace the issue down by eyeballing the console handling code. My terminal emulator is pretending to be xterm-256color compatible (MobaXTerm), and infocmp(1) does show entries for both sequences for this term type:\r\n```\r\nrmkx=\\E[?1l\\E>\r\nsmkx=\\E[?1h\\E=\r\n```\r\nThe terminfo entries have manifest numeric IDs in `/usr/include/term.h\r\n```\r\n#define keypad_local                   CUR Strings[88]\r\n#define keypad_xmit                    CUR Strings[89]\r\n```\r\nbut the index 88 is not even in the [`enum WellKnownStrings` in TermInfo.cs](https://github.com/dotnet/corefx/blob/14072950a/src/System.Console/src/System/TermInfo.cs#L61) file that reads the terminfo file directly (but `KeypadXmit = 89` is). Also, it seems that [pal_console.c](https://github.com/dotnet/corefx/blob/14072950a/src/Native/Unix/System.Native/pal_console.c) does a good job of restoring the application mode at a few points by sending the `keypad_xmit` sequence, apparently since the MR #6488 fixing the issue #5902, but unless I misunderstand it, never attempts to send a matching `keypad_local` in any of its Uninitialize() functions, where tty driver attributes are restored."},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/430028197","html_url":"https://github.com/dotnet/corefx/issues/32805#issuecomment-430028197","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/32805","id":430028197,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDAyODE5Nw==","user":{"login":"kkm000","id":8228229,"node_id":"MDQ6VXNlcjgyMjgyMjk=","avatar_url":"https://avatars3.githubusercontent.com/u/8228229?v=4","gravatar_id":"","url":"https://api.github.com/users/kkm000","html_url":"https://github.com/kkm000","followers_url":"https://api.github.com/users/kkm000/followers","following_url":"https://api.github.com/users/kkm000/following{/other_user}","gists_url":"https://api.github.com/users/kkm000/gists{/gist_id}","starred_url":"https://api.github.com/users/kkm000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkm000/subscriptions","organizations_url":"https://api.github.com/users/kkm000/orgs","repos_url":"https://api.github.com/users/kkm000/repos","events_url":"https://api.github.com/users/kkm000/events{/privacy}","received_events_url":"https://api.github.com/users/kkm000/received_events","type":"User","site_admin":false},"created_at":"2018-10-15T21:55:02Z","updated_at":"2018-10-15T21:55:02Z","author_association":"NONE","body":"@stephentoub:\r\n\r\n>  Is there a way to detect whether the current setting is already keypad_xmit?\r\n\r\nI do not believe there is, and most probably not without running into another timeout problem like #31517. But it's not really necessary. For all I know, no sane program would assume that the terminal is in the keypad mode when it starts. And I know for sure that bash (rather readline) assumes it is not :(\r\n\r\nMy understanding is that the \"local\" mode is the default, and it's always ok to revert to it. [vim does this unconditionally](https://github.com/vim/vim/blob/64f410742/src/term.c#L3578) upon exit (here [`T_KE` corresponds](https://github.com/vim/vim/blob/64f410742/src/term.c#L1603) to yet another name for `keypad_local`, the termcap `ks`/`ke` pair). [less does it pretty much always](https://github.com/vbwagner/less/blob/7b48019d/screen.c#L1575) as well (when did you last type `less --no-init`? :) ).\r\n\r\n[vim documentation has a little bit](https://github.com/vim/vim/blob/64f410742/runtime/doc/term.txt#L81) on its keypad mode control."}}
{"actor":{"display_login":"kkm000"}}