i-am-shodan/ReTerm

Keyboard layout changes in Zile

Closed this issue ยท 33 comments

Thanks again for the support ๐Ÿ˜ธ

By using fcd11e3, #9 got unblocked, so I can now run ReTerm. Upgrading to framework version 3.2.3.1595 to have the keyboard recognised, I now installed Zile using opkg as it's served by Entware, to try out an equivalent to Emacs.

Issue

A new keyboard issue appears: the layout changes under Zile, when it is run under ReTerm: backspace is read as C-h, arrows are read as A B C D, and the letters are working as normal.

Other situation

Running the same Zile under yaft (installed using opkg also) doesn't make the same problem. (The secondary problem there being that yaft doesn't rotate the screen.)

In both cases, when starting zile 2> err, an error also gets logged:

ERROR: ld.so: object '/opt/lib/librm2fb_client.so.1' from LD_PRELOAD cannot be preloaded (internal error): ignored.

Can I help diagnose where this issue comes from?

If you run 'cat /sys/pogo/status/lang' what two letter language code do you get?

Do the characters display fine/work correctly under bash? If no then maybe an incorrect layout was detected.

At the moment I've got implementations for UK & US folios.

How ReTerm works is that when you press a key on the folio it writes a sequence of bytes representing that key to bash's stdin. This has been good enough up to now. It's possible that the sequence I'm using for arrow keys etc isn't the most compatible and we need a different one.

If you look at ~/.ReTerm/settings.json you can find what keystrokes are sent when each key is pressed, you should see a big table (if you don't delete the file and reload).
Perhaps you can try some different codes for arrow keys and see if they work with zile.

Yes, under bash the keyboard is fine.

I upgraded to the last Toltec version and since then I don't get the keyboard details in the ~/.ReTerm/settings.json file (I remove it all, folder included, and reinstall, and it still only gives me the no-keyboard config file:

reMarkable: ~/ cat .ReTerm/settings.json 
{
  "DontBlinkCursor": false,
  "DisableMouseAndTouch": false,
  "TouchMarksClearTime": "00:00:10",
  "CursorBlinkInterval": "00:00:00.5000000",
  "ForceBackgroundHexColor": "#FFFFFF",
  "ForceForegroundHexColor": "#000000",
  "FontPath": "",
  "FontName": "",
  "FontSize": 36,
  "KeyboardKeyLookup": null
}
reMarkable: ~/ 

Is there something else I'm missing?

(I was going to try different codes, as I had seen them in settings.json, but now I can't get them back.)

I don't maintain the Toltec piece. I haven't used it and don't know how.

My advice is to use the binaries from the GitHub releases page. That way you can be sure you are using the latest release.

Only the latest release supports changing the keyboard layout

Ok, I removed the Toltec package, set up the release-no-dotnet-runtime.zip 20230727_0630, and here is the log I get:

reMarkable: ~/ rm -r .ReTerm/
rm: can't remove '.ReTerm': No such file or directory
reMarkable: ~/ ReTerm/ReTerm.sh 
Loading settings file from: /home/root/.ReTerm/settings.json
Settings not found, creating
Created settings dir
Detected language US
Terminal width = 104
Terminal height = 39
PID = 353
HOME = /home/root
ArgumentOutOfRangeException: eventType 20 KeyboardEventType
ArgumentOutOfRangeException: eventType 20 KeyboardEventType
^C
reMarkable: ~/ cat .ReTerm/settings.json 
{
  "DontBlinkCursor": false,
  "DisableMouseAndTouch": false,
  "TouchMarksClearTime": "00:00:10",
  "CursorBlinkInterval": "00:00:00.5000000",
  "ForceBackgroundHexColor": "#FFFFFF",
  "ForceForegroundHexColor": "#000000",
  "FontPath": "",
  "FontName": "",
  "FontSize": 36,
  "KeyboardKeyLookup": null
}
reMarkable: ~/ 

Is this expected?

Interesting bug, let me look at the code and push a fix

I've pushed up a version that should fix KeyboardKeyLookup being null, can you try that

Fixed! I'll write back here after trying some keyboard layout configs. Thanks

I'm looking for the code that generates this .ReTerm/settings.json, and the only default keyboard layout and recognition I find is src/ReTerm/Settings/DefaultKeyboardLayouts.cs. Yet there the arrows show

            { KeyboardKey.Up, new Dictionary<MetaKey, List<char>>() {
                { MetaKey.None, new List<char>() { '\x1B', '\x5B', '\x41' } }
            } },

I tried copying that into settings.json, but none of the versions I try let ReTerm start. I tried '\x1B', '\x5B', '\x41' (which isn't json), "\x1B", "\x5B", "\x41", "\x1B\x5B\x41" (this would make sense since the three characters are in the same List<char>).

Instead, my settings.json has indeed

"Up": {
  "None": [
    "\u001b",
    "[",
    "A"
  ]
},

which makes sense that zile reads Up as [-A (and something before).

So my questions:

  • How is that file generated?
  • How can I just default to the DefaultKeyboardLayouts.cs content?

The internal representation is a C# dictionary, the external representation is JSON. The escaping is different between these two formats

Yes, but where is the default settings.json stored in the repo? Or how is it generated?

0x5B is the ASCII character [
0x41 is the ASCII character A

This tool can help you convert between https://www.rapidtables.com/convert/number/ascii-to-hex.html

My second question then: how does the settings.json make the difference between sections like the Up button:

            { KeyboardKey.Up, new Dictionary<MetaKey, List<char>>() {
                { MetaKey.None, new List<char>() { '\x1B', '\x5B', '\x41' } }
            } }

and say a section with multiple MetaKey lines, e.g.:

            { KeyboardKey.NumberRow3, new Dictionary<MetaKey, List<char>>() {
                { MetaKey.None, new List<char>() { '3' } } ,
                { MetaKey.Shift, new List<char>() { 'ยฃ' } },
                { MetaKey.Opt, new List<char>() { '#' } }
            } },

Oh my bad, I'm thinking out loud and now seeing the difference in the json encoding.

So could it be that what Zile receives is not the combination of the three parts encoding Up, but one part after the other? This looks related to the escape-time option in tmux, which lets a series of keypresses to be combined into a single keypress instead of seeing them as separate keypresses: https://github.com/tmux/tmux/wiki/FAQ#what-is-the-escape-time-option-is-zero-a-good-value

The three bytes are sent to the bash process all at once. There is no delay.

Just to confirm you've SSHed into you Rm2, opened Zile in a terminal like putty and tried to do whatever it is you want to do.

Yes, when I ssh into rm2, running zile works perfectly (on the screen of my laptop). The problem is when I run it inside ReTerm.

That's a good sign, it definitely means it a ReTerm problem

If there's any help I can provide to fix this one let me know!

Perhaps you could try some things out with yaft to try and understand why things are different. Are they receiving the same key presses? Is yaft writing to stdin or doing something different.

You could try changing the TERM variable. ReTerm lies and says it's xterm, your program could be behaving differently because of this.

I've had a quick look at keyboard handling in yaft. Yaft adds a repeat code on at the end. It's possible that's the problem.

You could try this by adding a final 0 press to the arrow key button pressed. So instead of sending 3 bytes it sends 4.

To try this out edit the settings file and add the extra 0 byte to the list for the arrow keys.

That sounded likely indeed, but it doesn't work. I set up/left/right/down as such:

    "Down": {
      "None": [
        "\u001b",
        "[",
        "B",
        "\u0000"
      ]
    },
    "Up": {
      "None": [
        "\u001b",
        "[",
        "A",
        "\u0000"
      ]
    },
    "Left": {
      "None": [
        "\u001b",
        "[",
        "D",
        "\u0000"
      ]
    },
    "Right": {
      "None": [
        "\u001b",
        "[",
        "C",
        "\u0000"
      ]
    },

and no change in zile. Is that the right character, is there a different encoding that makes sense maybe?

Now TERM=linux does make the arrow keys work, with or without the "\u0000" in settings.json.

Backspace is still not working, it's taken as Ctrl-h by zile. But this is a step forward!

TERM=vt100 didn't have any effect

Has zile got a mailing list? Backspace is just being sent through as \b so I don't quite understand why it doesn't like that.

This is yaft's keyboard code

https://github.com/timower/rM2-stuff/blob/master/apps/yaft/keyboard.cpp

It sends backspace through has ox7f 0x00

Do you know what TERM variable yaft uses?

Do you know what TERM variable yaft uses?

yaft-256color

And setting backspace as:

"Backspace": {
  "None": [
    "\u007f",
    "\u0000"
  ]
},

makes it work inside zile

Interesting, I'll do some testing and probably add nulls to everything

The latest release contains some major changes to fix some of these issues. The term variable is now set to xterm-256color because without that the library I use for vt100 parsing doesn't handle some things. Try it and see.

https://github.com/i-am-shodan/ReTerm/releases/tag/release_20230731_1832

I'll be checking this one day -- I had to put on hold back in July. Thanks though!