aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/fhandler_console.cc
AgeCommit message (Collapse)AuthorFilesLines
2021-05-07Cygwin: fetch Windows directory on all platforms and use throughoutCorinna Vinschen1-6/+5
Rather than fetching the system Windows directory at dll init time only on 32 bit, fetch it on all platforms. Store as WCHAR and UNICODE_STRING. Use where appropriate to simplify code. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-20Cygwin: console: Fix race issue regarding cons_master_thread().Takashi Yano1-2/+8
- With this patch, the race issue regarding starting/stopping cons_master_thread() introduced by commit ff4440fc is fixed. Addresses: https://cygwin.com/pipermail/cygwin/2021-April/248292.html
2021-04-19Cygwin: console: Fix a bug in the code to fix tab position.Takashi Yano1-1/+1
- With this patch, a bug in the code to fix tab position after resizing window is fixed.
2021-03-08Cygwin: console, pty: Stop ignoring Ctrl-C by IGNBRK.Takashi Yano via Cygwin-patches1-1/+1
- Perhaps current code misunderstand meaning of the IGNBRK. As far as I investigated, IGNBRK is concerned with break signal in serial port but there is no evidence that it has effect to ignore Ctrl-C. This patch stops ignoring Ctrl-C by IGNBRK for non-cygwin apps.
2021-02-22Cygwin: console: Prevent NULL pointer access in close().Takashi Yano via Cygwin-patches1-1/+1
- There seems to be a case that shared_console_info is not set yet when close() is called. This patch adds guard for such case.
2021-02-19Cygwin: console: Add support for FLUSHO and Ctrl-O.Takashi Yano via Cygwin-patches1-0/+11
- With this patch, FLUSHO and Ctrl-O (VDISCARD) get working.
2021-02-19Cygwin: console: Fix handling of Ctrl-S in Win7.Takashi Yano via Cygwin-patches1-223/+68
- If ENABLE_LINE_INPUT is set, Ctrl-S is handled by Windows if the OS is Windows 7. This conflicts with Ctrl-S handling in cygwin console code. This patch unsets ENABLE_LINE_INPUT flag in cygwin and set it when native app is executed.
2021-02-19Cygwin: console: Fix SIGWINCH handling in Win7.Takashi Yano via Cygwin-patches1-0/+15
- If ENABLE_VIRTUAL_TERMINAL_INPUT is not set, changing window height does not generate WINDOW_BUFFER_SIZE_EVENT. This happens if console is in the legacy mode. Therefore, with this patch, the windows size is checked every time in cons_master_thread() if the cosole is in the legacy mode.
2021-02-17Cygwin: console: Introduce new thread which handles input signal.Takashi Yano via Cygwin-patches1-1/+176
- Currently, Ctrl-Z, Ctrl-\ and SIGWINCH does not work in console if the process does not call read() or select(). This is because these are processed in process_input_message() which is called from read() or select(). This is a long standing issue of console. Addresses: https://cygwin.com/pipermail/cygwin/2020-May/244898.html https://cygwin.com/pipermail/cygwin/2021-February/247779.html With this patch, new thread which handles only input signals is introduced so that Crtl-Z, etc. work without calling read() or select(). Ctrl-S and Ctrl-Q are also handled in this thread.
2021-02-15Cygwin: console: Abort read() on signal if SA_RESTART is not set.Takashi Yano via Cygwin-patches1-4/+3
- Currently, console read() keeps reading after SIGWINCH is sent even if SA_RESTART flag is not set. With this patch, read() returns EINTR on SIGWINCH if SA_RESTART flag is not set. The same problem for SIGQUIT and SIGTSTP has also been fixed.
2021-02-01Cygwin: console: Align the behaviour against signal with pty.Takashi Yano via Cygwin-patches1-1/+2
- Currently, read() returns -1 with EINTR if the process is suspended by Ctrl-Z and resumed by fg command, while pty continues to read. For example, xxd command stops with error "Interrupted system call" after Ctrl-Z and fg. This patch aligns the behaviour with pty (and Linux).
2021-02-01Cygwin: console: Make read() thread-safe.Takashi Yano via Cygwin-patches1-5/+6
- Currently read() is somehow not thread-safe. This patch fixes the issue.
2021-01-25Cygwin: console: Add missing guard regarding attach_mutex.Takashi Yano via Cygwin-patches1-0/+27
- The commit a5333345 did not fix the problem enough. This patch provides additional guard for the issue.
2021-01-20Cygwin: console: Fix "Bad file descriptor" error in script command.Takashi Yano via Cygwin-patches1-5/+5
- After the commit 72770148, script command exits occasionally with the error "Bad file descriptor" if it is started in console on Win7 and non-cygwin process is executed. This patch fixes the issue.
2021-01-18Cygwin: pty: Prevent pty from changing code page of parent console.Takashi Yano via Cygwin-patches1-6/+32
- After commit 232fde0e, pty changes console code page when the first non-cygwin app is executed. If pty is started in real console device, pty changes the code page of root console. This causes very annoying result because changing code page changes the font of command prompt if console is in legacy mode. This patch avoids this by creating a new invisible console for the first pty started in console device.
2021-01-18Cygwin: console: Revise the code to switch xterm mode.Takashi Yano via Cygwin-patches1-42/+79
- If application changes the console mode, mode management introduced by commit 10d8c278 will be corrupted. For example, stdout of jansi v2.0.1 or later is piped to less, jansi resets the xterm mode flag ENABLE_VIRTUAL_TERMINA_PROCESSING when jansi is terminated. This causes garbled output in less because less needs this flag enabled. This patch fixes the issue.
2020-09-28Cygwin: avoid GCC 10 error with -Werror=narrowingJon Turney1-2/+2
../../../../src/winsup/cygwin/fhandler_console.cc: In member function 'const unsigned char* fhandler_console::write_normal(const unsigned char*, const unsigned char*)': ../../../../src/winsup/cygwin/fhandler_console.cc:2782:8: error: narrowing conversion of '-2' from 'int' to 'long unsigned int' [-Wnarrowing] ../../../../src/winsup/cygwin/fhandler_console.cc:2786:8: error: narrowing conversion of '-1' from 'int' to 'long unsigned int' [-Wnarrowing] ../../../../src/winsup/cygwin/fhandler_console.cc:2836:8: error: narrowing conversion of '-2' from 'int' to 'long unsigned int' [-Wnarrowing] ../../../../src/winsup/cygwin/fhandler_console.cc:2840:8: error: narrowing conversion of '-1' from 'int' to 'long unsigned int' [-Wnarrowing] A mbtowc_p function returns an int, so that seems the correct type to use here.
2020-08-27Cygwin: console: Replace WriteConsoleA() with WriteConsoleW().Takashi Yano via Cygwin-patches1-42/+47
- To allow sending non-ASCII chars to console, all WriteConsoleA() are replaced by WriteConsoleW(). Addresses: https://cygwin.com/pipermail/cygwin-patches/2020q3/010476.html
2020-08-22Cygwin: pty: Implement new pseudo console support.Takashi Yano1-43/+0
- In this implementation, pseudo console is created for each native console app. Advantages and disadvantages of this implementation over the previous implementation are as follows. Advantages: 1) No performance degradation in pty output for cygwin process. https://cygwin.com/pipermail/cygwin/2020-February/243858.html 2) Free from the problem caused by difference of behaviour of control sequences between real terminal and pseudo console. https://cygwin.com/pipermail/cygwin/2019-December/243281.html https://cygwin.com/pipermail/cygwin/2020-February/243855.html 3) Free from the problem in cgdb and emacs gud. https://cygwin.com/pipermail/cygwin/2020-January/243601.html https://cygwin.com/pipermail/cygwin/2020-March/244146.html 4) Redrawing screen on executing native console apps is not necessary. 5) cygwin-console-helper is not necessary for the pseudo console support. 6) The codes for pseudo console support are much simpler than that of the previous one. Disadvantages: 1) The cygwin program which calls console API directly does not work. 2) The apps which use console API cannot be debugged with gdb. This is because pseudo console is not activated since gdb uses CreateProcess() rather than exec(). Even with this limitation, attaching gdb to native apps, in which pseudo console is already activated, works. 3) Typeahead key inputs are discarded while native console app is executed. Simirally, typeahead key inputs while cygwin app is executed are not inherited to native console app. 4) Code page cannot be changed by chcp.com. Acctually, chcp works itself and changes code page of its own pseudo console. However, since pseudo console is recreated for another process, it cannot inherit the code page. 5) system_printf() does not work after stderr is closed. (Same with cygwin 3.0.7) 6) Startup time of native console apps is about 3 times slower than previous implemenation. 7) Pseudo console cannot be activated if it is already activated for another process on same pty.
2020-07-10Cygwin: convert sys_wcstombs/sys_mbstowcs wrapper to inline functionsCorinna Vinschen1-1/+1
This should slightly speed up especially path conversions, given there's one less function call rearranging all function arguments in registers/stack (and less stack pressure). For clarity, rename overloaded sys_wcstombs to _sys_wcstombs and sys_cp_mbstowcs to _sys_mbstowcs. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-31Cygwin: console: Discard some unsupported escape sequences.Takashi Yano via Cygwin-patches1-16/+38
- If the cygwin vim is started from a non-cygwin process which is executed in pseudo console, shift key and ctrl key do not work. In this case, vim is executed under /dev/cons*. If vim outputs escape sequence which is not supported by pseudo console, the escape sequence is leaked into the parent pty. This causes unexpected results. This patch fixes the issue by discarding "CSI > Pm m". "OSC 10;? BEL/ST" and "OSC 11;? BEL/ST" are discarded as well.
2020-05-30Cygwin: console: Make cursor keys work in vim under ConEmu.Takashi Yano via Cygwin-patches1-6/+14
- After commit 774b8996d1f3e535e8267be4eb8e751d756c2cec, cursor keys do not work in vim under ConEmu without cygwin-connector. This patch fixes the issue.
2020-03-09Cygwin: console: Fix behaviour of "ESC 8" after reset.Takashi Yano1-0/+7
- This patch matches the behaviour of "ESC 8" (DECRC) to the real xterm after full reset (RIS), soft reset (DECSTR) and "CSI 3 J".
2020-03-09Do not bother passing optional argument to WriteConsoleA.Hans-Bernhard Broeker1-28/+23
Passing a pointer to a local variable to WriteConsoleA is not actually needed if we're not going to do anything with what WriteConsoleA would put in there. For the wpbuf class the pointer argument was made optional, so it can be just left out; other call places now pass a NULL pointer instead. The local variables `wn' and `n' are no unused, so they go away.
2020-03-09Collect handling of wpixput and wpbuf into a helper class.Hans-Bernhard Broeker1-65/+76
Replace direct access to a pair of co-dependent variables by calls to methods of a class that encapsulates their relation. Also replace C #define by C++ class constant.
2020-03-02Cygwin: console: convert wpbuf_put to inline functionCorinna Vinschen1-4/+7
fix potential buffer overrun while at it Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-03-02Cygwin: console: Add a workaround for "ESC 7" and "ESC 8".Takashi Yano1-13/+40
- In xterm compatible mode, "ESC 7" and "ESC 8" do not work properly in the senario: 1) Execute /bin/ls /bin to fill screen. 2) Sned CSI?1049h to alternate screen. 3) Reduce window size. 4) Send CSI?1049l to resume screen. 5) Send "ESC 7" and "ESC 8". After sending "ESC 8", the cursor goes to incorrect position. This patch adds a workaround for this issue.
2020-03-02Cygwin: console: Prevent buffer overrun.Takashi Yano1-10/+8
- This patch prevent potential buffer overrun in the code handling escape sequences.
2020-03-02Cygwin: console: Fix setting/unsetting xterm mode for input.Takashi Yano1-2/+3
- This patch fixes the issue that xterm compatible mode for input is not correctly set/unset in some situation such as: 1) cat is stopped by ctrl-c. 2) The window size is changed in less. In case 1), request_xterm_mode_input(true) is called in read(), however, cat is stopped without request_xterm_mode_input(false). In case 2), less uses longjmp in signal handler, therefore, corresponding request_xterm_mode_input(false) is not called if the SIGWINCH signal is sent within read(). With this patch, InterlockedExchange() is used instead of InterlockedIncrement/ Decrement().
2020-03-02Cygwin: console: Revise the code to fix tab position.Takashi Yano1-12/+3
- This patch fixes the issue that the cursor position is broken if window size is changed while executing vim, less etc.
2020-02-28Cygwin: console: Adjust the detailed behaviour of ESC sequences.Takashi Yano1-7/+44
- This patch makes some detailed behaviour of ESC sequences such as "CSI Ps L" (IL), "CSI Ps M" (DL) and "ESC M" (RI) in xterm mode match with real xterm.
2020-02-26Cygwin: console: Add emulation of CSI3J on Win10 1809.Takashi Yano1-2/+17
- This patch add emulation of CSI3J, which is broken in Win10 1809, rather than ignoring it as before.
2020-02-26Cygwin: console: Add support for REP escape sequence to xterm mode.Takashi Yano1-0/+33
- In Win10 upto 1809, xterm compatible mode does not have REP escape sequence which terminfo declares. This patch adds support for "CSI Ps b" (REP). With this patch, bvi (binary editor) works normally in Win10 1809. Also, xterm compatible mode does not have "CSI Pm `" (HPA), "CSI Pm a" (HPR) and "CSI Ps e" (VPR). However, they do not appear to be declared by terminfo. Therefore, these have been pending.
2020-02-26Cygwin: console: Unify workaround code for CSI3J and CSI?1049h/l.Takashi Yano1-21/+22
- This patch unifies workaround code for CSI3J and CSI?1049h/l into the code handling other escape sequences in xterm mode.
2020-02-26Cygwin: console: Add workaround for broken IL/DL in xterm mode.Takashi Yano1-2/+154
- Cygwin console with xterm compatible mode causes problem reported in https://www.cygwin.com/ml/cygwin-patches/2020-q1/msg00212.html if background/foreground colors are set to gray/black respectively in Win10 1903/1909. This is caused by "CSI Ps L" (IL), "CSI Ps M" (DL) and "ESC M" (RI) control sequences which are broken. This patch adds a workaround for the issue.
2020-02-24Cygwin: console: Fix segfault on shared_console_info access.Takashi Yano1-12/+11
- Accessing shared_console_info before initialization causes access violation because it is a NULL pointer. The cause of the problem reported in https://cygwin.com/ml/cygwin/2020-02/msg00197.html is this NULL pointer access in request_xterm_mode_output() when it is called from close(). This patch makes sure that shared_console_info is not NULL before calling request_xterm_mode_output().
2020-02-21Cygwin: don't move cursor on NUL char at allCorinna Vinschen1-2/+3
Add a comment instead to explain that this behaviour contradicts the terminfo entry. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-02-20Cygwin: fhandler_console.cc: fix minor style issuesCorinna Vinschen1-3/+3
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-02-20Cygwin: console: ignore NUL byte on write in xterm emulation mode as wellCorinna Vinschen1-1/+3
A NUL byte in the output stream got accidentally not handled as IGN char in xterm console mode. The internal mbtowc conversion doesn't handle embedded NUL values gracefully, it always stops converting at NUL bytes. This broke the output of strings with embedded NUL bytes. Fix this by always skipping IGN chars in the "normal char output loop" and make sure not to move the cursor one position to the right, as in legacy console mode. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-02-18Cygwin: console: Add guard for set/unset xterm compatible mode.cygwin-3_1_4-releaseTakashi Yano1-37/+88
- Setting / unsetting xterm compatible mode may cause race issue between multiple processes. This patch adds guard for that.
2020-02-18Cygwin: console: Fix ioctl() FIONREAD.Takashi Yano1-4/+33
- ioctl() FIONREAD for console does not return correct value since commit cfb517f39a8bcf2d995a732d250563917600408a. This patch fixes the issue.
2020-02-17Cygwin: console: Fix code for restoring console mode.Takashi Yano1-1/+1
- Commit 774b8996d1f3e535e8267be4eb8e751d756c2cec has a bug that restores console output mode into console input. This patch fixes the issue.
2020-02-17Cygwin: console: Change timing of set/unset xterm compatible mode.cygwin-3_1_3-releaseTakashi Yano1-50/+51
- If two cygwin programs are executed simultaneousley with pipes in cmd.exe, xterm compatible mode is accidentally disabled by the process which ends first. After that, escape sequences are not handled correctly in the other app. This is the problem 2 reported in https://cygwin.com/ml/cygwin/2020-02/msg00116.html. This patch fixes the issue. This patch also fixes the problem 3. For these issues, the timing of setting and unsetting xterm compatible mode is changed. For read, xterm compatible mode is enabled only within read() or select() functions. For write, it is enabled every time write() is called, and restored on close().
2020-02-04Cygwin: console: Revise color setting codes in legacy console mode.Takashi Yano1-20/+27
- With this patch, foreground color and background color are allowed to be set simultaneously by 24 bit color escape sequence such as ESC[38;2;0;0;255;48;2;128;128;0m in legacy console mode.
2020-01-28Cygwin: console: Share readahead buffer within the same process.Takashi Yano1-1/+38
- The cause of the problem reported in https://www.cygwin.com/ml/cygwin/2020-01/msg00220.html is that the chars input before dup() cannot be read from the new file descriptor. This is because the readahead buffer (rabuf) in the console is newly created by dup(), and does not inherit from the parent. This patch fixes the issue.
2020-01-14Cygwin: console: Add code to restore console mode on close.Takashi Yano1-0/+21
- The console with 24bit color support has a problem that console mode is changed if cygwin process is executed in cmd.exe which started in cygwin shell. For example, cursor keys become not working if bash -> cmd -> true are executed in this order. This patch fixes the issue.
2020-01-14Cygwin: console: Add workaround for broken CSI3J in Win10 1809.Takashi Yano1-0/+12
- In Win10 1809, the cursor position sometimes goes out of screen by clear command in console. This seems to be caused by escape sequence CSI3J (ESC[3J). This happens only for 1809. This patch is a workaround for the issue.
2020-01-14Cygwin: console: Disable xterm mode for non cygwin process only.Takashi Yano1-19/+0
- Special function keys such as arrow keys or function keys do not work in ConEmu with cygwin-connector after commit 6a06c6bc8f8492ea09aa3ae180fe94e4ac265611. This patch fixes the issue.
2020-01-13Cygwin: console: Make suspending process work properly.Takashi Yano1-0/+2
- After commit f4b47827cf87f055687a0c52a3485d42b3e2b941, suspending process by Ctrl-Z does not work in console and results in hang up. This patch fixes the issue.
2019-11-18Cygwin: pty: Convert CamelCase names to snake_case names.Takashi Yano1-1/+1