raphamorim / rio

A hardware-accelerated GPU terminal emulator focusing to run in desktops and browsers.
https://raphamorim.io/rio
MIT License
4.01k stars 129 forks source link

nvim getting opt/meta key along with the intended key in Rio #295

Closed henrythor closed 1 year ago

henrythor commented 1 year ago

OS: macOS Sonoma 14.0 (23A344) Rio: 0.0.22 installed via brew install --cask rio nvim: stable 0.9.4

I'm not quite sure what's happening under the hood here, but I have an ISO keyboard with Nordic/Icelandic layout and I'm trying to use nvim with Rio.

To type { in insert mode, for example, I would press ⌥ Opt + 7 (Alt Gr + 7 on PC keyboards).

When I use nvim in Rio, nvim will exit insert mode instead of adding the curly bracket to the screen buffer. If I use Ctrl + V to see the literal key input it will show <M-{> instead of {. Using ⌥ Opt + < to input | will similarly show <M-Bar>.

This does not happen in kitty, alacritty, Terminal, etc. It does not happen if I run nvim from within tmux in Rio. It does not happen with vim and Rio. So I'm thinking it's something to do with the way nvim interprets terminfo.

Any ideas how I can fix this? Will I have to map all the Meta/Alt sequences to the literal keys in nvim? Is this an nvim bug?

Here is nvim's parsing of terminfo:

--- Terminal info --- {{{
&term: rio
Description: rio
Boolean capabilities:
  auto_left_margin          bw         = false
  auto_right_margin         am         = true
  no_esc_ctlc               xsb        = false
  ceol_standout_glitch      xhp        = false
  eat_newline_glitch        xenl       = true
  erase_overstrike          eo         = false
  generic_type              gn         = false
  hard_copy                 hc         = false
  has_meta_key              km         = true
  has_status_line           hs         = true
  insert_null_glitch        in         = false
  memory_above              da         = false
  memory_below              db         = false
  move_insert_mode          mir        = true
  move_standout_mode        msgr       = true
  over_strike               os         = false
  status_line_esc_ok        eslok      = false
  dest_tabs_magic_smso      xt         = false
  tilde_glitch              hz         = false
  transparent_underline     ul         = false
  xon_xoff                  xon        = false
  needs_xon_xoff            nxon       = false
  prtr_silent               mc5i       = true
  hard_cursor               chts       = false
  non_rev_rmcup             nrrmc      = false
  no_pad_char               npc        = true
  non_dest_scroll_region    ndscr      = false
  can_change                ccc        = true
  back_color_erase          bce        = true
  hue_lightness_saturation  hls        = false
  col_addr_glitch           xhpa       = false
  cr_cancels_micro_mode     crxm       = false
  has_print_wheel           daisy      = false
  row_addr_glitch           xvpa       = false
  semi_auto_right_margin    sam        = false
  cpi_changes_res           cpix       = false
  lpi_changes_res           lpix       = false
  backspaces_with_bs        OTbs       = true
  crt_no_scrolling          OTns       = false
  no_correctly_working_cr   OTnc       = false
  gnu_has_meta_key          OTMT       = false
  linefeed_is_newline       OTNL       = false
  has_hardware_tabs         OTpt       = false
  return_does_clr_eol       OTxr       = false
Numeric capabilities:
  columns                   cols       = 80
  init_tabs                 it         = 8
  lines                     lines      = 24
  lines_of_memory           lm         = -1
  magic_cookie_glitch       xmc        = -1
  padding_baud_rate         pb         = -1
  virtual_terminal          vt         = -1
  width_status_line         wsl        = -1
  num_labels                nlab       = -1
  label_height              lh         = -1
  label_width               lw         = -1
  max_attributes            ma         = -1
  maximum_windows           wnum       = -1
  max_colors                colors     = 256
  max_pairs                 pairs      = 32767
  no_color_video            ncv        = -1
  buffer_capacity           bufsz      = -1
  dot_vert_spacing          spinv      = -1
  dot_horz_spacing          spinh      = -1
  max_micro_address         maddr      = -1
  max_micro_jump            mjump      = -1
  micro_col_size            mcs        = -1
  micro_line_size           mls        = -1
  number_of_pins            npins      = -1
  output_res_char           orc        = -1
  output_res_line           orl        = -1
  output_res_horz_inch      orhi       = -1
  output_res_vert_inch      orvi       = -1
  print_rate                cps        = -1
  wide_char_size            widcs      = -1
  buttons                   btns       = -1
  bit_image_entwining       bitwin     = -1
  bit_image_type            bitype     = -1
  magic_cookie_glitch_ul    OTug       = -1
  carriage_return_delay     OTdC       = -1
  new_line_delay            OTdN       = -1
  backspace_delay           OTdB       = -1
  horizontal_tab_delay      OTdT       = -1
  number_of_function_keys   OTkn       = -1
String capabilities:
  back_tab                  cbt        = ^[[Z
  bell                      bel        = ^G
  carriage_return           cr         = ^M
  change_scroll_region      csr        = ^[[%i%p1%d;%p2%dr
  clear_all_tabs            tbc        = ^[[3g
  clear_screen              clear      = ^[[H^[[2J
  clr_eol                   el         = ^[[K
  clr_eos                   ed         = ^[[J
  column_address            hpa        = ^[[%i%p1%dG
  cursor_address            cup        = ^[[%i%p1%d;%p2%dH
  cursor_down               cud1       = ^@
  cursor_home               home       = ^[[H
  cursor_invisible          civis      = ^[[?25l
  cursor_left               cub1       = ^H
  cursor_normal             cnorm      = ^[[?25h
  cursor_right              cuf1       = ^[[C
  cursor_up                 cuu1       = ^[[A
  cursor_visible            cvvis      = ^[[?12;25h
  delete_character          dch1       = ^[[P
  delete_line               dl1        = ^[[M
  dis_status_line           dsl        = ^[]2;^G
  enter_alt_charset_mode    smacs      = ^[(0
  enter_bold_mode           bold       = ^[[1m
  enter_ca_mode             smcup      = ^[[?1049h^[[22;0;0t
  enter_dim_mode            dim        = ^[[2m
  enter_insert_mode         smir       = ^[[4h
  enter_secure_mode         invis      = ^[[8m
  enter_reverse_mode        rev        = ^[[7m
  enter_standout_mode       smso       = ^[[7m
  enter_underline_mode      smul       = ^[[4m
  erase_chars               ech        = ^[[%p1%dX
  exit_alt_charset_mode     rmacs      = ^[(B
  exit_attribute_mode       sgr0       = ^[(B^[[m
  exit_ca_mode              rmcup      = ^[[?1049l^[[23;0;0t
  exit_insert_mode          rmir       = ^[[4l
  exit_standout_mode        rmso       = ^[[27m
  exit_underline_mode       rmul       = ^[[24m
  flash_screen              flash      = ^[[?5h$<100/>^[[?5l
  from_status_line          fsl        = ^G
  init_2string              is2        = ^[[!p^[[?3;4l^[[4l^[>
  insert_line               il1        = ^[[L
  key_backspace             kbs        = ^?
  key_dc                    kdch1      = ^[[3~
  key_down                  kcud1      = ^[OB
  key_f1                    kf1        = ^[OP
  key_f10                   kf10       = ^[[21~
  key_f2                    kf2        = ^[OQ
  key_f3                    kf3        = ^[OR
  key_f4                    kf4        = ^[OS
  key_f5                    kf5        = ^[[15~
  key_f6                    kf6        = ^[[17~
  key_f7                    kf7        = ^[[18~
  key_f8                    kf8        = ^[[19~
  key_f9                    kf9        = ^[[20~
  key_home                  khome      = ^[OH
  key_ic                    kich1      = ^[[2~
  key_left                  kcub1      = ^[OD
  key_npage                 knp        = ^[[6~
  key_ppage                 kpp        = ^[[5~
  key_right                 kcuf1      = ^[OC
  key_sf                    kind       = ^[[1;2B
  key_sr                    kri        = ^[[1;2A
  key_up                    kcuu1      = ^[OA
  keypad_local              rmkx       = ^[[?1l^[>
  keypad_xmit               smkx       = ^[[?1h^[=
  meta_off                  rmm        = ^[[?1034l
  meta_on                   smm        = ^[[?1034h
  parm_dch                  dch        = ^[[%p1%dP
  parm_delete_line          dl         = ^[[%p1%dM
  parm_down_cursor          cud        = ^[[%p1%dB
  parm_ich                  ich        = ^[[%p1%d@
  parm_index                indn       = ^[[%p1%dS
  parm_insert_line          il         = ^[[%p1%dL
  parm_left_cursor          cub        = ^[[%p1%dD
  parm_right_cursor         cuf        = ^[[%p1%dC
  parm_rindex               rin        = ^[[%p1%dT
  parm_up_cursor            cuu        = ^[[%p1%dA
  print_screen              mc0        = ^[[i
  prtr_off                  mc4        = ^[[4i
  prtr_on                   mc5        = ^[[5i
  repeat_char               rep        = %p1%c^[[%p2%{1}%-%db
  reset_1string             rs1        = ^[c^[]104^G
  reset_2string             rs2        = ^[[!p^[[?3;4l^[[4l^[>
  restore_cursor            rc         = ^[8
  row_address               vpa        = ^[[%i%p1%dd
  save_cursor               sc         = ^[7
  scroll_forward            ind        = ^@
  scroll_reverse            ri         = ^[M
  set_attributes            sgr        = %?%p9%t^[(0%e^[(B%;^[[0%?%p6%t;1%;%?%p5%t;2%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m
  set_tab                   hts        = ^[H
  tab                       ht         =    
  to_status_line            tsl        = ^[]2;
  key_b2                    kb2        = ^[OE
  acs_chars                 acsc       = ``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~
  key_btab                  kcbt       = ^[[Z
  enter_am_mode             smam       = ^[[?7h
  exit_am_mode              rmam       = ^[[?7l
  key_end                   kend       = ^[OF
  key_enter                 kent       = ^[OM
  key_sdc                   kDC        = ^[[3;2~
  key_send                  kEND       = ^[[1;2F
  key_shome                 kHOM       = ^[[1;2H
  key_sic                   kIC        = ^[[2;2~
  key_sleft                 kLFT       = ^[[1;2D
  key_snext                 kNXT       = ^[[6;2~
  key_sprevious             kPRV       = ^[[5;2~
  key_sright                kRIT       = ^[[1;2C
  key_f11                   kf11       = ^[[23~
  key_f12                   kf12       = ^[[24~
  key_f13                   kf13       = ^[[1;2P
  key_f14                   kf14       = ^[[1;2Q
  key_f15                   kf15       = ^[[1;2R
  key_f16                   kf16       = ^[[1;2S
  key_f17                   kf17       = ^[[15;2~
  key_f18                   kf18       = ^[[17;2~
  key_f19                   kf19       = ^[[18;2~
  key_f20                   kf20       = ^[[19;2~
  key_f21                   kf21       = ^[[20;2~
  key_f22                   kf22       = ^[[21;2~
  key_f23                   kf23       = ^[[23;2~
  key_f24                   kf24       = ^[[24;2~
  key_f25                   kf25       = ^[[1;5P
  key_f26                   kf26       = ^[[1;5Q
  key_f27                   kf27       = ^[[1;5R
  key_f28                   kf28       = ^[[1;5S
  key_f29                   kf29       = ^[[15;5~
  key_f30                   kf30       = ^[[17;5~
  key_f31                   kf31       = ^[[18;5~
  key_f32                   kf32       = ^[[19;5~
  key_f33                   kf33       = ^[[20;5~
  key_f34                   kf34       = ^[[21;5~
  key_f35                   kf35       = ^[[23;5~
  key_f36                   kf36       = ^[[24;5~
  key_f37                   kf37       = ^[[1;6P
  key_f38                   kf38       = ^[[1;6Q
  key_f39                   kf39       = ^[[1;6R
  key_f40                   kf40       = ^[[1;6S
  key_f41                   kf41       = ^[[15;6~
  key_f42                   kf42       = ^[[17;6~
  key_f43                   kf43       = ^[[18;6~
  key_f44                   kf44       = ^[[19;6~
  key_f45                   kf45       = ^[[20;6~
  key_f46                   kf46       = ^[[21;6~
  key_f47                   kf47       = ^[[23;6~
  key_f48                   kf48       = ^[[24;6~
  key_f49                   kf49       = ^[[1;3P
  key_f50                   kf50       = ^[[1;3Q
  key_f51                   kf51       = ^[[1;3R
  key_f52                   kf52       = ^[[1;3S
  key_f53                   kf53       = ^[[15;3~
  key_f54                   kf54       = ^[[17;3~
  key_f55                   kf55       = ^[[18;3~
  key_f56                   kf56       = ^[[19;3~
  key_f57                   kf57       = ^[[20;3~
  key_f58                   kf58       = ^[[21;3~
  key_f59                   kf59       = ^[[23;3~
  key_f60                   kf60       = ^[[24;3~
  key_f61                   kf61       = ^[[1;4P
  key_f62                   kf62       = ^[[1;4Q
  key_f63                   kf63       = ^[[1;4R
  clr_bol                   el1        = ^[[1K
  user6                     u6         = ^[[%i%d;%dR
  user7                     u7         = ^[[6n
  user8                     u8         = ^[[?%[;0123456789]c
  user9                     u9         = ^[[c
  orig_pair                 op         = ^[[39;49m
  orig_colors               oc         = ^[]104^G
  initialize_color          initc      = ^[]4;%p1%d;rgb:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X^[\
  enter_italics_mode        sitm       = ^[[3m
  exit_italics_mode         ritm       = ^[[23m
  key_mouse                 kmous      = ^[[M
  set_a_foreground          setaf      = ^[[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m
  set_a_background          setab      = ^[[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m
  memory_lock               meml       = ^[l
  memory_unlock             memu       = ^[m
Extended boolean capabilities:
  AX                        = true
  XF                        = true
  XT                        = true
Extended string capabilities:
  BD                        = ^[[?2004l
  Cr                        = ^[]112^G
  Cs                        = ^[]12;%p1%s^G
  E3                        = ^[[3J
  Ms                        = ^[]52;%p1%s;%p2%s^G
  Se                        = ^[[0 q
  Smulx                     = ^[[4:%p1%dm
  Ss                        = ^[[%p1%d q
  Sync                      = ^[P=%p1%ds^[\
  kDC3                      = ^[[3;3~
  kDC4                      = ^[[3;4~
  kDC5                      = ^[[3;5~
  kDC6                      = ^[[3;6~
  kDC7                      = ^[[3;7~
  kDN                       = ^[[1;2B
  kDN3                      = ^[[1;3B
  kDN4                      = ^[[1;4B
  kDN5                      = ^[[1;5B
  kDN6                      = ^[[1;6B
  kDN7                      = ^[[1;7B
  kEND3                     = ^[[1;3F
  kEND4                     = ^[[1;4F
  kEND5                     = ^[[1;5F
  kEND6                     = ^[[1;6F
  kEND7                     = ^[[1;7F
  kHOM3                     = ^[[1;3H
  kHOM4                     = ^[[1;4H
  kHOM5                     = ^[[1;5H
  kHOM6                     = ^[[1;6H
  kHOM7                     = ^[[1;7H
  kIC3                      = ^[[2;3~
  kIC4                      = ^[[2;4~
  kIC5                      = ^[[2;5~
  kIC6                      = ^[[2;6~
  kIC7                      = ^[[2;7~
  kLFT3                     = ^[[1;3D
  kLFT4                     = ^[[1;4D
  kLFT5                     = ^[[1;5D
  kLFT6                     = ^[[1;6D
  kLFT7                     = ^[[1;7D
  kNXT3                     = ^[[6;3~
  kNXT4                     = ^[[6;4~
  kNXT5                     = ^[[6;5~
  kNXT6                     = ^[[6;6~
  kNXT7                     = ^[[6;7~
  kPRV3                     = ^[[5;3~
  kPRV4                     = ^[[5;4~
  kPRV5                     = ^[[5;5~
  kPRV6                     = ^[[5;6~
  kPRV7                     = ^[[5;7~
  kRIT3                     = ^[[1;3C
  kRIT4                     = ^[[1;4C
  kRIT5                     = ^[[1;5C
  kRIT6                     = ^[[1;6C
  kRIT7                     = ^[[1;7C
  kUP                       = ^[[1;2A
  kUP3                      = ^[[1;3A
  kUP4                      = ^[[1;4A
  kUP5                      = ^[[1;5A
  kUP6                      = ^[[1;6A
  kUP7                      = ^[[1;7A
  kxIN                      = ^[[I
  kxOUT                     = ^[[O
  rmxx                      = ^[[29m
  smxx                      = ^[[9m
  ext.get_bg                = ^[]11;?^G
  ext.get_extkeys           = ^[[?u^[[c
  ext.enter_altfont_mode    = ^[[11m
  setrgbf                   = ^[[38;2;%p1%d;%p2%d;%p3%dm
  setrgbb                   = ^[[48;2;%p1%d;%p2%d;%p3%dm
  ext.save_title            = ^[[22;0t
  ext.restore_title         = ^[[23;0t
  ext.enable_lr_margin      = ^[[?69h
  ext.disable_lr_margin     = ^[[?69l
  ext.enable_bpaste         = ^[[?2004h
  ext.disable_bpaste        = ^[[?2004l
  ext.enable_focus          = ^[[?1004h
  ext.disable_focus         = ^[[?1004l
  ext.enable_mouse          = ^[[?1002h^[[?1006h
  ext.disable_mouse         = ^[[?1002l^[[?1006l
  ext.enable_mouse_move     = ^[[?1003h
  ext.disable_mouse_move    = ^[[?1003l
  ext.set_underline_color   = ^[[58:2::%p1%d:%p2%d:%p3%dm
  ext.enable_extended_keys  = ^[[>1u
  ext.disable_extended_keys = ^[[<1u
}}}
raphamorim commented 1 year ago

Hey @henrythor thanks for the detailed issue (I appreciate that ๐Ÿ™)

When you log TERM env variable inside and outside of tmux, what's the output?

henrythor commented 1 year ago

TERM=rio in Rio directly, TERM=screen-256color in Rio + tmux

raphamorim commented 1 year ago

I see, that might be the reason, but what is weird is that this was expected to happen in kitty and alacritty as well (unless you have term=kitty inside and outside of tmux).

This issue is also connected to this https://github.com/raphamorim/rio/issues/190#issuecomment-1693440273. Although for this case, if inside of tmux isn't term=kitty or term=alacritty, then I assume it might be a rio bug and needs further investigation.

henrythor commented 1 year ago

Kitty uses TERM=xterm-kitty.

Anything I can try to do to resolve this? Do you know of a console program that can debug raw terminal inputs?

Would a diff between verbose output of nvim's parsing of terminfo between Rio and some other terminal help? I'm not sure I understand it, is it mostly about characters nvim must emit to control the terminal, cursor location etc?

raphamorim commented 1 year ago

A quick workaround for this issue might be update your tmux config, in your .tmux.conf file:

set -g default-terminal "rio"

I think I might need to introduce an xterm-rio for avoid this type of problems, kitty and alacritty does have xterm-alacritty and xterm-kitty

henrythor commented 1 year ago

not sure I follow, nvim in tmux within Rio works as intended, nvim straight on Rio is not able to add the characters that depend on ⌥ Opt or Alt Gr

henrythor commented 1 year ago

I tried running tmux with rio as default-terminal and it still works

raphamorim commented 1 year ago

Ahh thank you for clarifying @henrythor

raphamorim commented 1 year ago

I pushed some changes in main, could you confirm if works for you now?

(might build a canary version soon in the CI)

henrythor commented 1 year ago

I'm not really familiar with rust but I have the latest rust from Homebrew, which is 1.72.1, but your stuff is dependent on $\ge 1.73.0$.

error: package `copa v0.0.22 (/Users/henry/Dev/rio/copa)` cannot be built because it requires rustc 1.73.0 or newer, while the currently active rustc version is 1.72.1

I tried installing rust via the homebrew recipe and --HEAD switch but the recipe is broken somehow. So I'll wait for the canary ๐Ÿ˜…

Last 15 lines from /Users/henry/Library/Logs/Homebrew/rust/03.make:

error: vendoring required, but vendor directory does not exist.
       Run `cargo vendor --sync ./src/tools/cargo/Cargo.toml --sync ./src/tools/rust-analyzer/Cargo.toml --sync ./compiler/rustc_codegen_cranelift/Cargo.toml --sync ./src/bootstrap/Cargo.toml ` to initialize the vendor directory.
Alternatively, use the pre-vendored `rustc-src` dist component.
Traceback (most recent call last):
  File "/private/tmp/rust-20231017-16008-r8pc8z/src/bootstrap/bootstrap.py", line 1149, in <module>
    main()
  File "/private/tmp/rust-20231017-16008-r8pc8z/src/bootstrap/bootstrap.py", line 1134, in main
    bootstrap(args)
  File "/private/tmp/rust-20231017-16008-r8pc8z/src/bootstrap/bootstrap.py", line 1093, in bootstrap
    build.check_vendored_status()
  File "/private/tmp/rust-20231017-16008-r8pc8z/src/bootstrap/bootstrap.py", line 1024, in check_vendored_status
    raise Exception("{} not found".format(vendor_dir))
Exception: /private/tmp/rust-20231017-16008-r8pc8z/vendor not found
make: *** [all] Error 1

READ THIS: https://docs.brew.sh/Troubleshooting

rust's formula was built from an unstable upstream --HEAD.
This build failure is expected behaviour.
Do not create issues about this on Homebrew's GitHub repositories.
Any opened issues will be immediately closed without response.
Do not ask for help from Homebrew or its maintainers on social media.
You may ask for help in Homebrew's discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.
raphamorim commented 1 year ago

An advice would be avoid install rust with homebrew often it leads to issues for me. Specially whenever building different toolchains/targets

Are you using macos? If yes, you can download the canary version here https://github.com/raphamorim/rio/releases/tag/canary

henrythor commented 1 year ago

Oki, cool. The last Canary was built 8 hours ago but I've seen you made a commit disabling kitty keyboard protocol to main since then, isn't that the relevant commit?

raphamorim commented 1 year ago

Yes, good catch. It should have been a bit more "fresh" canary ๐Ÿ‘€ Will look tomorrow why didn't triggered

raphamorim commented 1 year ago

Looks like disabling kitty keyboard protocol has fixed for other similar issues like yours #222 . Will be closing this issue for now but let me know anything