On Dec 10 10:52, Takashi Yano wrote:
> In Windows 11, the command "rlwrap cmd" outputs garbaged screen.
> This is because rlwrap treats text between NLs as a line, while
> pseudo console sometimes ommits NL before "CISm;nH". This issue
CSI
> does not happen in Windows 10. This patch fixes the issue.
>
> Reviewed-by:
> Signed-off-by: Takashi Yano <[email protected]>
> ---
> winsup/cygwin/fhandler/pty.cc | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
> index 3b0b4f073..5c02a4111 100644
> --- a/winsup/cygwin/fhandler/pty.cc
> +++ b/winsup/cygwin/fhandler/pty.cc
> @@ -2775,6 +2775,40 @@ fhandler_pty_master::pty_master_fwd_thread (const
> master_fwd_thread_param_t *p)
> else
> state = 0;
>
> + /* Workaround for rlwrap */
I think the comment should mention that this is necessary since W11
only. And maybe the code should only run on systems needing it?
Is that a problem in W11 conhost which has been fixed in OpenConsole
already, by any chance? If so, that would be a good indicator for
always including a self-built OpenConsole package into our distro...
> + /* rlwarp treats text between NLs as a line, however,
rlwrap
> + pseudo console somtimes ommits NL before "CSIm;nH". */
> + state = 0;
> + for (DWORD i = 0; i < rlen; i++)
> + if (state == 0 && outbuf[i] == '\033')
> + {
> + start_at = i;
> + state++;
> + continue;
> + }
> + else if (state == 1 && outbuf[i] == '[')
> + {
> + state++;
> + continue;
> + }
> + else if (state == 2 && (isdigit (outbuf[i]) || outbuf[i] == ';'))
> + continue;
> + else if (state == 2 && outbuf[i] == 'H')
> + {
> + /* Add "CSI H" before CR NL to avoid unexpected scroll */
> + const char *ins = "\033[H\r\n";
> + const int ins_len = strlen (ins);
> + memmove (&outbuf[start_at + ins_len], &outbuf[start_at],
> + rlen - start_at);
> + memcpy (&outbuf[start_at], ins, ins_len);
> + rlen += ins_len;
> + i += ins_len;
> + state = 0;
> + continue;
I don't understand this code. The commit message says, the pseudo
console omits NL before CSI H, so I would expect this code to add a
missing NL. But instead it adds a CSI H? What am I missing?
Thanks,
Corinna