Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Escape Sequences in Lens Terminal on Windows Server 2022 with win32-input-mode #2593

Open
unxed opened this issue Dec 23, 2024 · 2 comments

Comments

@unxed
Copy link
Contributor

unxed commented Dec 23, 2024

When running Far2l within the built-in terminal of Lens (a Kubernetes IDE) on Windows Server 2022, the win32-input-mode becomes active (TTY|w is seen), but the escape sequences generated for some keys are incorrect. For example:

  • Enter: \x1b[0;0;13;1;0;1_\x1b[13;28;13;0;0;1_
  • Ctrl-C: \x1b[17;29;0;1;8;1_\x1b[0;0;3;1;0;1_\x1b[67;46;3;0;8;1_\x1b[17;29;0;0;0;1_
  • Esc: \x1b[0;0;27;1;0;1_\x1b[27;1;27;0;0;1_

This can be worked around by setting Virtual Key Code automatically based on Unicode key value, like this:

	// Workarounds for some weird win32-input-mode setups
	// Todo: add scan codes
	// Ctrl+letters
	if (
		(!args[0] && args[2] >= 1 && args[2] <= 26 && !(args[4] & LEFT_CTRL_PRESSED)) ||
		( args[0] && args[2] >= 1 && args[2] <= 26 &&  (args[4] & LEFT_CTRL_PRESSED))
	) {
		args[0] = args[2] + 64;
		args[2] = (args[4] & SHIFT_PRESSED) ? args[0] : tolower(args[0]);
		args[4] |= LEFT_CTRL_PRESSED;
		fprintf(stderr, "W32I: Ctrl+letter hack\n");
	}
	// Ctrl+BS
	if (args[0] == 0 && args[2] == 0x7F && args[3]) {
		args[0] = VK_BACK;
		args[2] = args[0];
		args[4] |= LEFT_CTRL_PRESSED;
		fprintf(stderr, "W32I: Ctrl+BS hack\n");
	}
	// Esc
	if (args[0] == 0 && args[2] == 0x1B && args[3]) {
		args[0] = VK_ESCAPE;
		fprintf(stderr, "W32I: Esc hack\n");
	}
	// Enter
	if (args[0] == 0 && args[2] == 0x0D && args[3]) {
		args[0] = VK_RETURN;
		fprintf(stderr, "W32I: Enter hack\n");
	}
	// Enter#2: Ctrl+M encoded as win32-input-mode seq, 77 0 109 1 8 1
	if (args[0] == 'M' && !args[1] && args[2] == 'm' && args[3] && (args[4] & LEFT_CTRL_PRESSED)) {
		args[0] = VK_RETURN;
		args[2] = 0x0D;
		args[4] = 0;
		fprintf(stderr, "W32I: Enter hack #2\n");
	}

Code from here: unxed@3ecf059

Another possible solution is key tracking (received keyup without corresponding keydown? generate keydown also) like it is done in pitty4far2l:

	if (args[3] && args[0]) { // keydown
		vkc_prev = args[0];
	} else if (args[0] && vkc_prev && (vkc_prev != (DWORD)args[0])) {
		args[3] = 1;
		vkc_prev = 0;
	}

Implemented here: unxed@203582d

But there is still a problem: our "win32-input-mode double encoding hack" prevents workarounds above from working with ESC key presses.

See also:
https://t.me/far2l_ru/36896

@unxed
Copy link
Contributor Author

unxed commented Dec 23, 2024

Lens is using xterm.js for terminal implementation. xterm.js team is discussing win32-input-mode support, but it is not ready yet AFAIK:
xtermjs/xterm.js#2357

@unxed
Copy link
Contributor Author

unxed commented Dec 23, 2024

@Dazzar56 you said you can look into this then you have a bit of free time, ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant