From fe7419709ea8aa61117338bd394d1d62031c4447 Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Thu, 28 May 2026 11:19:25 +0800 Subject: [PATCH] Polish interactive help lifecycle --- README.md | 2 +- src/commands.c | 4 ++++ src/i18n_text.c | 12 ++++++------ src/input.c | 11 ++++++++++- src/tui.c | 6 ++++-- tests/test_exec_mode.sh | 2 +- tests/test_interactive_input.sh | 28 ++++++++++++++++------------ tests/test_user_lifecycle.sh | 8 ++++---- tnt.1 | 4 +++- 9 files changed, 49 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index d2018c9..a4ada81 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Ctrl+C - Exit chat :w - Short alias for :msg :inbox - Show private messages :last [N] - Show last N messages from history (max 50, default 10) -:search - Search full message history (case-insensitive) +:search - Search message history (shows last 15 matches) :mute-joins - Toggle join/leave system notifications :lang - Switch UI language for this session :help - Show concise manual diff --git a/src/commands.c b/src/commands.c index 318c720..9e53de2 100644 --- a/src/commands.c +++ b/src/commands.c @@ -118,6 +118,10 @@ void commands_dispatch(client_t *client) { end--; } } + if (cmd[0] == ':') { + cmd++; + while (*cmd == ' ') cmd++; + } /* Save to command history */ if (cmd[0] != '\0') { diff --git a/src/i18n_text.c b/src/i18n_text.c index 5fe3f60..5f009e4 100644 --- a/src/i18n_text.c +++ b/src/i18n_text.c @@ -26,12 +26,12 @@ static const i18n_string_t text_catalog[I18N_TEXT_COUNT] = { "TNT %s - SSH 匿名聊天室\r\n\r\n" ), [I18N_INSERT_HINT_WIDE] = I18N_STRING( - "Enter send · Esc browse · :help", - "Enter 发送 · Esc 浏览 · :help" + "Enter send · Esc NORMAL", + "Enter 发送 · Esc NORMAL" ), [I18N_INSERT_HINT_NARROW] = I18N_STRING( - "Enter · Esc · :help", - "Enter · Esc · :help" + "Enter · Esc", + "Enter · Esc" ), [I18N_NORMAL_LATEST] = I18N_STRING( "G latest", @@ -142,8 +142,8 @@ static const i18n_string_t text_catalog[I18N_TEXT_COUNT] = { "--- 最近 %d 条消息 ---\n" ), [I18N_SEARCH_HEADER_FORMAT] = I18N_STRING( - "--- Search: \"%s\" (%d match(es)) ---\n", - "--- 搜索: \"%s\" (%d 条匹配) ---\n" + "--- Search: \"%s\" (showing last %d match(es)) ---\n", + "--- 搜索: \"%s\" (显示最近 %d 条匹配) ---\n" ), [I18N_MUTE_JOINS_FORMAT] = I18N_STRING( "Join/leave notifications: %s\n", diff --git a/src/input.c b/src/input.c index 01eadc9..a29c902 100644 --- a/src/input.c +++ b/src/input.c @@ -235,9 +235,13 @@ static void dismiss_command_output(client_t *client) { client->command_output_scroll = 0; client->command_output_kind = TNT_COMMAND_OUTPUT_NONE; client->show_motd = false; - client->mode = MODE_NORMAL; if (was_motd) { + client->mode = MODE_INSERT; + client->follow_tail = true; + client->unread_mentions = 0; normal_scroll_to_latest(client); + } else { + client->mode = MODE_NORMAL; } tui_render_screen(client); } @@ -352,6 +356,11 @@ static bool handle_key(client_t *client, unsigned char key, char *input) { /* Handle Ctrl+C (Exit or switch to NORMAL) */ if (key == 3) { client_mode_t previous_mode = client->mode; + if (client->show_help) { + client->show_help = false; + tui_render_screen(client); + return true; + } if (client->command_output[0] != '\0') { dismiss_command_output(client); return true; diff --git a/src/tui.c b/src/tui.c index be2f185..f671b70 100644 --- a/src/tui.c +++ b/src/tui.c @@ -373,7 +373,9 @@ void tui_render_screen(client_t *client) { chips[chip_count].value_color = mode_color; chip_count++; - const char *hint = i18n_text(client->ui_lang, I18N_TITLE_HELP_HINT); + const char *hint = client->mode == MODE_NORMAL + ? i18n_text(client->ui_lang, I18N_TITLE_HELP_HINT) + : ""; int hint_width = utf8_string_width(hint); const char *mute_label = i18n_text(client->ui_lang, I18N_TITLE_MUTED); int mute_width = client->mute_joins ? utf8_string_width(mute_label) + 2 : 0; @@ -401,7 +403,7 @@ void tui_render_screen(client_t *client) { /* Decide what fits. Reserve at least 1 col of gap between left and * right halves so they never visually touch. */ - int show_hint = 1; + int show_hint = hint[0] != '\0'; int show_mute = client->mute_joins ? 1 : 0; int show_unread = unread_count > 0 ? 1 : 0; int show_whisper = whisper_count > 0 ? 1 : 0; diff --git a/tests/test_exec_mode.sh b/tests/test_exec_mode.sh index fe92c34..88ad874 100755 --- a/tests/test_exec_mode.sh +++ b/tests/test_exec_mode.sh @@ -372,7 +372,7 @@ set timeout 10 spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p $PORT sender@localhost expect "请输入用户名" send "sender\r" -expect ":help" +expect "Esc NORMAL" send "\033" expect "NORMAL" send ":" diff --git a/tests/test_interactive_input.sh b/tests/test_interactive_input.sh index da7b6f8..f02e107 100755 --- a/tests/test_interactive_input.sh +++ b/tests/test_interactive_input.sh @@ -83,7 +83,7 @@ set timeout 10 spawn ssh $SSH_OPTS anonymous@127.0.0.1 sleep 1 send -- "wrong\025editeduser\r" -expect ":help" +expect "Esc NORMAL" send -- "\003" sleep 0.2 send -- "\003" @@ -109,7 +109,7 @@ set timeout 10 spawn ssh $SSH_OPTS anonymous@127.0.0.1 sleep 1 send -- "tester\r" -expect ":help" +expect "Esc NORMAL" send -- "\033\[200~" send -- "line1\nline2\nline3" send -- "\033\[201~" @@ -184,12 +184,12 @@ set timeout 10 spawn ssh $SSH_OPTS anonymous@127.0.0.1 sleep 1 send -- "helper\r" -expect ":help" +expect "Esc NORMAL" send -- "\033" expect "NORMAL" send -- ":" expect ":" -send -- "help\r" +send -- ":help\r" expect "TNT\\(1\\) 帮助" expect "Tab 补全 @mention" expect "q:关闭" @@ -199,6 +199,10 @@ send -- "?" expect "TNT 按键参考" expect "Tab - 补全 @mention" expect "l:语言" +send -- "\003" +expect "NORMAL" +send -- "?" +expect "TNT 按键参考" send -- "l" expect "TNT KEY REFERENCE" expect "Complete @mention" @@ -235,7 +239,7 @@ stty rows 8 columns 80 spawn ssh $SSH_OPTS anonymous@127.0.0.1 sleep 1 send -- "helppager\r" -expect ":help" +expect "Esc NORMAL" send -- "\033" expect "NORMAL" send -- "?" @@ -273,7 +277,7 @@ set timeout 10 spawn ssh $SSH_OPTS anonymous@127.0.0.1 sleep 1 send -- "mistype\r" -expect ":help" +expect "Esc NORMAL" send -- "\033" expect "NORMAL" send -- ":" @@ -305,7 +309,7 @@ set timeout 10 spawn ssh $SSH_OPTS anonymous@127.0.0.1 sleep 1 send -- "localized\r" -expect ":help" +expect "Esc NORMAL" send -- "\033" expect "NORMAL" send -- ":" @@ -355,7 +359,7 @@ set timeout 10 spawn ssh $SSH_OPTS anonymous@127.0.0.1 sleep 1 send -- "usageuser\r" -expect ":help" +expect "Esc NORMAL" send -- "\033" expect "NORMAL" send -- ":" @@ -448,7 +452,7 @@ stty rows 8 columns 80 spawn ssh $SSH_OPTS anonymous@127.0.0.1 sleep 1 send -- "pageruser\r" -expect ":help" +expect "Esc NORMAL" send -- "\033" expect "NORMAL" send -- ":" @@ -492,7 +496,7 @@ stty rows 10 columns 40 spawn ssh $SSH_OPTS anonymous@127.0.0.1 sleep 1 send -- "wrapcmd\r" -expect ":help" +expect "Esc NORMAL" send -- "\033" expect "NORMAL" send -- ":" @@ -522,7 +526,7 @@ set timeout 10 spawn ssh $SSH_OPTS anonymous@127.0.0.1 sleep 1 send -- "systemuser\r" -expect ":help" +expect "Esc NORMAL" send -- "\033" expect "NORMAL" send -- ":" @@ -569,7 +573,7 @@ expect "公告" expect "维护窗口" expect "按任意键继续" send -- "x" -expect "NORMAL" +expect "INSERT" sleep 0.2 send -- "\003" sleep 0.2 diff --git a/tests/test_user_lifecycle.sh b/tests/test_user_lifecycle.sh index 432942a..1f76400 100755 --- a/tests/test_user_lifecycle.sh +++ b/tests/test_user_lifecycle.sh @@ -79,7 +79,7 @@ set timeout 30 spawn ssh $SSH_OPTS bob@127.0.0.1 sleep 1 send -- "bob\r" -expect ":help" +expect "Esc NORMAL" send -- "\033" expect "NORMAL" send -- ":" @@ -143,7 +143,7 @@ set timeout 30 spawn ssh $SSH_OPTS alice@127.0.0.1 sleep 1 send -- "alice\r" -expect ":help" +expect "Esc NORMAL" send -- "\033" expect "NORMAL" send -- "?" @@ -160,7 +160,7 @@ expect "q:关闭" send -- "q" expect "NORMAL" send -- "i" -expect ":help" +expect "Esc NORMAL" send -- "hello lifecycle alpha\r" sleep 1 send -- "\033" @@ -215,7 +215,7 @@ expect "q:关闭" send -- "q" expect "NORMAL" send -- "i" -expect ":help" +expect "Esc NORMAL" send -- "/me ships lifecycle\r" sleep 1 send -- "\003" diff --git a/tnt.1 b/tnt.1 index 62f740e..86a134b 100644 --- a/tnt.1 +++ b/tnt.1 @@ -184,6 +184,8 @@ ESC Switch to NORMAL Ctrl+W Delete last word Ctrl+U Clear input line Ctrl+C Switch to NORMAL +Up/Down Browse sent message history +Tab Complete @mention Paste Keep multi-line paste in the input buffer /me \fIaction\fR Send action message (e.g. /me waves) @\fIusername\fR Mention user (bell notification + highlight) @@ -220,7 +222,7 @@ l l. :w \fIuser text\fR Short alias for :msg :inbox Show private messages :last [\fIN\fR] Show last N messages from history (1\-50, default 10) -:search \fIkeyword\fR Case\-insensitive search across full message history +:search \fIkeyword\fR Case\-insensitive search; shows the last 15 matches :mute\-joins Toggle join/leave system notifications on/off :lang Show current UI language :lang \fIen|zh\fR Switch UI language for this session