PerBothner / DomTerm

DOM/JavaScript-based terminal-emulator/console

Home Page:https://domterm.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: kitty keyboard protocol

vlisivka opened this issue · comments

Can you extend keyboard support, using kitty keyboard protocol, which is based on fixterm protocol?

https://sw.kovidgoyal.net/kitty/keyboard-protocol.html
http://www.leonerd.org.uk/hacks/fixterms/

The design of a extended keyboard pro\otocol is controversial (as is the author of Kitty ...), as you can see here. OTOH, the Kitty protocol exists: it is documented and implemented, which is a strong point. So some questions:

  • Do you know of any programs that make use of the Kittty keyboard protocol?
  • What do you need this level of detailed keyboard information for?
  • Could a smaller extension of the standard protocol serve your needs?

There is also the xterm modified-keys protocol. It looks like the Kitty protocol is a superset/variant of the former, but I haven't looked closely. If that would suit your needs, that might be worth considering.

Yes, it seems reasonable to add support. I've got a couple of things I'm in the middle of, so it make take some time before I get to it, but hopefully not too long.

I'm have the encoding implemented, and it works with Emacs. The main issue is desirable defaults and when/how to enable the feature. Plus a weid bug where it seems that Emacs gets into a looping state - no idea what is going on so far.

Seems to work pretty well now. Please update and let me know what you think.

Seems to work well in browser, but, for an unknown reason, mouse movement is not reported when the mouse cursor is in the area with strips (after screen clear), so my test script doesn't work until I press a key to show something on the screen and then move the mouse cursor in the white area.

Peek 2021-06-27 13-56

The logic for translating mouse x/y position to row/column position starts at terminal.js:4473. I'm guessing the problem is the recently-added lines 4483-4485. And those were added because resetCursorCache gets confused if the event-target is outside a "line". Let me think about it.

Could you try again?

It works fine (for my needs) in Chromium. All I need is to highlight a button, when the mouse is over it.

If window scaled down with Ctrl+-, then mouse movements are reported in the gray area up to line 127-32 (character: 0x1f). Columns are reported correctly for all width of terminal, even with the tiniest font. IMHO, it's enough.

Thank you for fixing it!

PS.

However, telnet mapscii.me doesn't work properly.

"If window scaled down with Ctrl+-, then mouse movements are reported in the gray area up to line 127-32 (character: 0x1f)."

Sounds like you're using one of the older mouse-reporting modes. I suggest using SGR (1006) mode.

Emacs sends the following initialization sequence, with 1006 as the last and preferred mode.

"\e[?1000h\e[?1002h\e[?1006h"

If your test program is simple and standalone, could I have it?

When it comes to telnet mapscii.me that is probably a flaw in Sixel color-palette management. I'd like to update the SixelDecoder code but it's unclear what the latest code is. The author "jerch" has been doing a lot of work to add sixel support to xterm.js. Hopefully it will be done and merged in soon, which might be a good time to re-import it.

I use 1005 or 1003 mode. Here is the test script. I wrote it for quick test, so sorry for the mess.

#!/bin/bash
set -ue -o pipefail

# Enable mouse reporting mode
# See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
enable_mouse_reporting() {
  # 1003 - enable all mouse events
  # 1005 - coordinates are in UTF-8, up to two bytes
  echo -e "\e[?1003h\e[?1005h"
  stty_orig=`stty -g`
  stty -echo
}

# Disable mouse reporting mode at exit
disable_mouse_reporting() {
  echo -e "\\e[?1003l\e[?1005l"
  stty $stty_orig
}
trap disable_mouse_reporting EXIT

# ord VAR CHAR
# Store decimal code for a char into the var.
ord() {
  local var="$1"
  local char="$2"

  printf -v "$var" '%d' "'$char"
}


# Clear screen
printf "\e[H\e[2J\e[3J"

enable_mouse_reporting

x=''
y=''
while true
do
  if [[ "$y" != $'\e' ]] ; then
    read -sn 1 x || continue
  else
    x="$y"
  fi

  if [[ "$x" == $'\e' ]] ; then
    while read -rsn 1 -t .01 y; do
      if [[ "$y" != $'\e' ]] ; then
        x="$x$y"
      else
        break
      fi
    done
  fi

  printf "\e[H\e[2KKey: %q\n" "$x"

  for((i=0; i<${#x}; i++))
  do
    c="${x:i:1}"
    ord code "$c"
    printf "\e[2Kchar: '%q', code: 0x%x %d %o\n" "$c" "$code" "$code" "$code"
  done

  # Blindly assume that this is the mouse event
  ord mx "${x:4:1}"
  ord my "${x:5:1}"
  let mx=mx-32
  let my=my-32
  printf "\e[2KMouse x: $mx, y: $my\n"

  printf "\e[2K\n\e[2K\n\e[2K\n\e[2K\n\e[2K\n"

  if [[ "$x" == "q" ]]; then
    exit 0
  fi
done

1003/1005 modes should work now, even for big windows.

Yes, it works just fine. Thank you again.

"However, telnet mapscii.me doesn't work properly."

Should work now.

Yes, it works. Thank you.