d99kris / nchat

Terminal-based Telegram / WhatsApp client for Linux and macOS
MIT License
524 stars 40 forks source link

Alt-Left and Alt-right don't work, Alt-c and Alt-x crash nchat, some suggested changes to README #179

Closed Disonantemus closed 5 months ago

Disonantemus commented 6 months ago

Description: In README.md says:

Alt-Left    move cursor backward one word
Alt-Right   move cursor forward one word

Every time you press any of both key combinations, you get a rectangle (like a missing font) and nothing else, not doing the function that says (move cursor backward|forward one word).

How to reproduce it: Launch nchat, write some words in text input and then try Alt-Left or Alt-Right.

Workaround I did use nchat --keydump to get correct key codes for Alt-Left and Alt-Right, and change ~/.nchat/key.conf from:

backward_word=\1040
forward_word=\1057

To:

backward_word=\4001046
forward_word=\4001065

Now works as expected. I still don't know what was the problem in the 1st place.

Environment:


nchat crashes

  1. If you press Alt-c or Alt-x, with an empty text input and not selecting any previous message, nchat crashes. Output:

    /usr/include/c++/13.2.1/bits/stl_vector.h:1125: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = unsigned char; _Alloc = std::allocator<unsigned char>; reference = unsigned char&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
            Aborted (core dumped)
  2. If you send a file (like an image) and immediately try to edit that message you get:

    /usr/include/c++/13.2.1/bits/stl_vector.h:1125: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = unsigned char; _Alloc = std::allocator<unsigned char>; reference = unsigned char&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
    ^C Cancel |Aborted (core dumped)

    Whatsapp web and Android does not allow to edit a message with only an image; you can send an image with a message, and edit that message, but not remove the whole message. Maybe happens the same with other attachments.


Extra: Suggested corrections to README.md, those lines are not clear

Alt-c       copy
Alt-v       paste
Alt-x       cut
Ctrl-x      reply to selected message

Should be something more descriptive, but the following is too long (maybe say that all copy/cut/paste operations are related to system clipboard):

Alt-c       copy from selected message (or whole text input) to system clipboard
Alt-v       paste from system clipboard
Alt-x       cut from selected message (or whole text input) to system clipboard
Ctrl-x      send reply to selected message

Alt-x doesn't makes sense when a message is selected, because don't cut anything, is exactly the same as Alt-c (copy). Maybe is better that don't copy selected message.

Ctrl-x did not work for me in the beginning. I tried to do the same process as WA-web or mobile app: select message > press reply button > write reply > press send button. Took me a while to understand, that nchat is different: you need to write reply & select message (in any order) > send reply (Ctrl-x). Because of this, I did add "send" to description, to make clear that is the last step.


README.md In ~/.nchat/key.conf section should show default content, they aren't, mine has a lot of different values like this:

$ grep '\\' ~/.nchat/key.conf
backward_kill_word=\033\177
backward_word=\1040
copy=\33\143
cut=\33\170
decrease_list_width=\33\54
delete_chat=\33\144
ext_call=\33\164
ext_edit=\33\145
forward_word=\1057
increase_list_width=\33\56
kill_word=\1006
open_msg=\33\167
paste=\33\166
spell=\33\163

Maybe this was changed in my system or now default values are different.

d99kris commented 5 months ago

Hi @Disonantemus - thanks for reporting issues with detailed information and suggesting improvements!

Can I check a few things:

  1. What keyboard layout (or locale) you're using?

  2. Does Alt-c / Alt-x with no message selected work if you have some text in the input field?

  3. If you have time, could you help to check the callstack of the crash? Obtaining the callstack is described in https://github.com/d99kris/nchat/blob/master/DEBUGGING.md#core-dumps---linux but essentially you'd run coredumpctl list nchat to find the PID of the crash core dump, then use coredumpctl debug PID to start gdb and get the callstack(s) using: thread apply all bt

Generally speaking the Alt-shortcuts implementation is currently a little hacky in nchat, using hardcoded default key codes, only tested on US and SE keyboard layouts (on Mac and Linux). I have yet to find a proper way to handle Alt-shortcuts with ncurses.

d99kris commented 5 months ago

Note for myself: In the Telegram nchat users group another user reported issues with Alt-d, Alt-Del, Alt-Left and Alt-Right using Spanish keyboard layout under Droidian. Have yet to check if this is a more general issue for Spanish/other non-US keyboard layouts.

d99kris commented 5 months ago

Hi again - with the above commit I've improved the documentation based on the suggestions and updated cut behavior with a selected message (thanks again!).

For the default alt/opt nchat keybindings, one needs to configure the terminal with meta to send escape. I've added a brief FAQ section for it.

I'll close this issue for now, as I cannot reproduce the other issues/crashes reported (tested the terminals mentioned). Feel free to re-open this issue if/when you can help provide more details on the crashes (see my above comment regarding obtaining the callstack of the crash).

For the default key.conf I will leave it as-is for now, it's generated on run-time based on whether it's Linux or macOS, so I'm not sure how to better document it in the README. If you have some suggestion, feel free to share.

d99kris commented 5 months ago

Btw, If you like to try "Meta Sends Escape" in xterm (without configuring) you can ctrl left-mouse click in xterm and select it from the context menu (see attached screenshot).

xterm-meta-sends-escape
asfaltboy commented 3 months ago

I use Arch, and kitty terminal, and my nchat --keydump shows different keys for alt-left and alt-right: \4001056 and \4001075 respectively. I use these for word navigation