Polish interactive help lifecycle

This commit is contained in:
m1ngsama 2026-05-28 11:19:25 +08:00
parent a800b026b3
commit fe7419709e
9 changed files with 49 additions and 28 deletions

View file

@ -98,7 +98,7 @@ Ctrl+C - Exit chat
:w <user> <text> - Short alias for :msg :w <user> <text> - Short alias for :msg
:inbox - Show private messages :inbox - Show private messages
:last [N] - Show last N messages from history (max 50, default 10) :last [N] - Show last N messages from history (max 50, default 10)
:search <keyword> - Search full message history (case-insensitive) :search <keyword> - Search message history (shows last 15 matches)
:mute-joins - Toggle join/leave system notifications :mute-joins - Toggle join/leave system notifications
:lang <en|zh> - Switch UI language for this session :lang <en|zh> - Switch UI language for this session
:help - Show concise manual :help - Show concise manual

View file

@ -118,6 +118,10 @@ void commands_dispatch(client_t *client) {
end--; end--;
} }
} }
if (cmd[0] == ':') {
cmd++;
while (*cmd == ' ') cmd++;
}
/* Save to command history */ /* Save to command history */
if (cmd[0] != '\0') { if (cmd[0] != '\0') {

View file

@ -26,12 +26,12 @@ static const i18n_string_t text_catalog[I18N_TEXT_COUNT] = {
"TNT %s - SSH 匿名聊天室\r\n\r\n" "TNT %s - SSH 匿名聊天室\r\n\r\n"
), ),
[I18N_INSERT_HINT_WIDE] = I18N_STRING( [I18N_INSERT_HINT_WIDE] = I18N_STRING(
"Enter send · Esc browse · :help", "Enter send · Esc NORMAL",
"Enter 发送 · Esc 浏览 · :help" "Enter 发送 · Esc NORMAL"
), ),
[I18N_INSERT_HINT_NARROW] = I18N_STRING( [I18N_INSERT_HINT_NARROW] = I18N_STRING(
"Enter · Esc · :help", "Enter · Esc",
"Enter · Esc · :help" "Enter · Esc"
), ),
[I18N_NORMAL_LATEST] = I18N_STRING( [I18N_NORMAL_LATEST] = I18N_STRING(
"G latest", "G latest",
@ -142,8 +142,8 @@ static const i18n_string_t text_catalog[I18N_TEXT_COUNT] = {
"--- 最近 %d 条消息 ---\n" "--- 最近 %d 条消息 ---\n"
), ),
[I18N_SEARCH_HEADER_FORMAT] = I18N_STRING( [I18N_SEARCH_HEADER_FORMAT] = I18N_STRING(
"--- Search: \"%s\" (%d match(es)) ---\n", "--- Search: \"%s\" (showing last %d match(es)) ---\n",
"--- 搜索: \"%s\" (%d 条匹配) ---\n" "--- 搜索: \"%s\" (显示最近 %d 条匹配) ---\n"
), ),
[I18N_MUTE_JOINS_FORMAT] = I18N_STRING( [I18N_MUTE_JOINS_FORMAT] = I18N_STRING(
"Join/leave notifications: %s\n", "Join/leave notifications: %s\n",

View file

@ -235,9 +235,13 @@ static void dismiss_command_output(client_t *client) {
client->command_output_scroll = 0; client->command_output_scroll = 0;
client->command_output_kind = TNT_COMMAND_OUTPUT_NONE; client->command_output_kind = TNT_COMMAND_OUTPUT_NONE;
client->show_motd = false; client->show_motd = false;
client->mode = MODE_NORMAL;
if (was_motd) { if (was_motd) {
client->mode = MODE_INSERT;
client->follow_tail = true;
client->unread_mentions = 0;
normal_scroll_to_latest(client); normal_scroll_to_latest(client);
} else {
client->mode = MODE_NORMAL;
} }
tui_render_screen(client); 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) */ /* Handle Ctrl+C (Exit or switch to NORMAL) */
if (key == 3) { if (key == 3) {
client_mode_t previous_mode = client->mode; 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') { if (client->command_output[0] != '\0') {
dismiss_command_output(client); dismiss_command_output(client);
return true; return true;

View file

@ -373,7 +373,9 @@ void tui_render_screen(client_t *client) {
chips[chip_count].value_color = mode_color; chips[chip_count].value_color = mode_color;
chip_count++; 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); int hint_width = utf8_string_width(hint);
const char *mute_label = i18n_text(client->ui_lang, I18N_TITLE_MUTED); 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; 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 /* Decide what fits. Reserve at least 1 col of gap between left and
* right halves so they never visually touch. */ * 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_mute = client->mute_joins ? 1 : 0;
int show_unread = unread_count > 0 ? 1 : 0; int show_unread = unread_count > 0 ? 1 : 0;
int show_whisper = whisper_count > 0 ? 1 : 0; int show_whisper = whisper_count > 0 ? 1 : 0;

View file

@ -372,7 +372,7 @@ set timeout 10
spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p $PORT sender@localhost spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p $PORT sender@localhost
expect "请输入用户名" expect "请输入用户名"
send "sender\r" send "sender\r"
expect ":help" expect "Esc NORMAL"
send "\033" send "\033"
expect "NORMAL" expect "NORMAL"
send ":" send ":"

View file

@ -83,7 +83,7 @@ set timeout 10
spawn ssh $SSH_OPTS anonymous@127.0.0.1 spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1 sleep 1
send -- "wrong\025editeduser\r" send -- "wrong\025editeduser\r"
expect ":help" expect "Esc NORMAL"
send -- "\003" send -- "\003"
sleep 0.2 sleep 0.2
send -- "\003" send -- "\003"
@ -109,7 +109,7 @@ set timeout 10
spawn ssh $SSH_OPTS anonymous@127.0.0.1 spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1 sleep 1
send -- "tester\r" send -- "tester\r"
expect ":help" expect "Esc NORMAL"
send -- "\033\[200~" send -- "\033\[200~"
send -- "line1\nline2\nline3" send -- "line1\nline2\nline3"
send -- "\033\[201~" send -- "\033\[201~"
@ -184,12 +184,12 @@ set timeout 10
spawn ssh $SSH_OPTS anonymous@127.0.0.1 spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1 sleep 1
send -- "helper\r" send -- "helper\r"
expect ":help" expect "Esc NORMAL"
send -- "\033" send -- "\033"
expect "NORMAL" expect "NORMAL"
send -- ":" send -- ":"
expect ":" expect ":"
send -- "help\r" send -- ":help\r"
expect "TNT\\(1\\) 帮助" expect "TNT\\(1\\) 帮助"
expect "Tab 补全 @mention" expect "Tab 补全 @mention"
expect "q:关闭" expect "q:关闭"
@ -199,6 +199,10 @@ send -- "?"
expect "TNT 按键参考" expect "TNT 按键参考"
expect "Tab - 补全 @mention" expect "Tab - 补全 @mention"
expect "l:语言" expect "l:语言"
send -- "\003"
expect "NORMAL"
send -- "?"
expect "TNT 按键参考"
send -- "l" send -- "l"
expect "TNT KEY REFERENCE" expect "TNT KEY REFERENCE"
expect "Complete @mention" expect "Complete @mention"
@ -235,7 +239,7 @@ stty rows 8 columns 80
spawn ssh $SSH_OPTS anonymous@127.0.0.1 spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1 sleep 1
send -- "helppager\r" send -- "helppager\r"
expect ":help" expect "Esc NORMAL"
send -- "\033" send -- "\033"
expect "NORMAL" expect "NORMAL"
send -- "?" send -- "?"
@ -273,7 +277,7 @@ set timeout 10
spawn ssh $SSH_OPTS anonymous@127.0.0.1 spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1 sleep 1
send -- "mistype\r" send -- "mistype\r"
expect ":help" expect "Esc NORMAL"
send -- "\033" send -- "\033"
expect "NORMAL" expect "NORMAL"
send -- ":" send -- ":"
@ -305,7 +309,7 @@ set timeout 10
spawn ssh $SSH_OPTS anonymous@127.0.0.1 spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1 sleep 1
send -- "localized\r" send -- "localized\r"
expect ":help" expect "Esc NORMAL"
send -- "\033" send -- "\033"
expect "NORMAL" expect "NORMAL"
send -- ":" send -- ":"
@ -355,7 +359,7 @@ set timeout 10
spawn ssh $SSH_OPTS anonymous@127.0.0.1 spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1 sleep 1
send -- "usageuser\r" send -- "usageuser\r"
expect ":help" expect "Esc NORMAL"
send -- "\033" send -- "\033"
expect "NORMAL" expect "NORMAL"
send -- ":" send -- ":"
@ -448,7 +452,7 @@ stty rows 8 columns 80
spawn ssh $SSH_OPTS anonymous@127.0.0.1 spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1 sleep 1
send -- "pageruser\r" send -- "pageruser\r"
expect ":help" expect "Esc NORMAL"
send -- "\033" send -- "\033"
expect "NORMAL" expect "NORMAL"
send -- ":" send -- ":"
@ -492,7 +496,7 @@ stty rows 10 columns 40
spawn ssh $SSH_OPTS anonymous@127.0.0.1 spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1 sleep 1
send -- "wrapcmd\r" send -- "wrapcmd\r"
expect ":help" expect "Esc NORMAL"
send -- "\033" send -- "\033"
expect "NORMAL" expect "NORMAL"
send -- ":" send -- ":"
@ -522,7 +526,7 @@ set timeout 10
spawn ssh $SSH_OPTS anonymous@127.0.0.1 spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1 sleep 1
send -- "systemuser\r" send -- "systemuser\r"
expect ":help" expect "Esc NORMAL"
send -- "\033" send -- "\033"
expect "NORMAL" expect "NORMAL"
send -- ":" send -- ":"
@ -569,7 +573,7 @@ expect "公告"
expect "维护窗口" expect "维护窗口"
expect "按任意键继续" expect "按任意键继续"
send -- "x" send -- "x"
expect "NORMAL" expect "INSERT"
sleep 0.2 sleep 0.2
send -- "\003" send -- "\003"
sleep 0.2 sleep 0.2

View file

@ -79,7 +79,7 @@ set timeout 30
spawn ssh $SSH_OPTS bob@127.0.0.1 spawn ssh $SSH_OPTS bob@127.0.0.1
sleep 1 sleep 1
send -- "bob\r" send -- "bob\r"
expect ":help" expect "Esc NORMAL"
send -- "\033" send -- "\033"
expect "NORMAL" expect "NORMAL"
send -- ":" send -- ":"
@ -143,7 +143,7 @@ set timeout 30
spawn ssh $SSH_OPTS alice@127.0.0.1 spawn ssh $SSH_OPTS alice@127.0.0.1
sleep 1 sleep 1
send -- "alice\r" send -- "alice\r"
expect ":help" expect "Esc NORMAL"
send -- "\033" send -- "\033"
expect "NORMAL" expect "NORMAL"
send -- "?" send -- "?"
@ -160,7 +160,7 @@ expect "q:关闭"
send -- "q" send -- "q"
expect "NORMAL" expect "NORMAL"
send -- "i" send -- "i"
expect ":help" expect "Esc NORMAL"
send -- "hello lifecycle alpha\r" send -- "hello lifecycle alpha\r"
sleep 1 sleep 1
send -- "\033" send -- "\033"
@ -215,7 +215,7 @@ expect "q:关闭"
send -- "q" send -- "q"
expect "NORMAL" expect "NORMAL"
send -- "i" send -- "i"
expect ":help" expect "Esc NORMAL"
send -- "/me ships lifecycle\r" send -- "/me ships lifecycle\r"
sleep 1 sleep 1
send -- "\003" send -- "\003"

4
tnt.1
View file

@ -184,6 +184,8 @@ ESC Switch to NORMAL
Ctrl+W Delete last word Ctrl+W Delete last word
Ctrl+U Clear input line Ctrl+U Clear input line
Ctrl+C Switch to NORMAL Ctrl+C Switch to NORMAL
Up/Down Browse sent message history
Tab Complete @mention
Paste Keep multi-line paste in the input buffer Paste Keep multi-line paste in the input buffer
/me \fIaction\fR Send action message (e.g. /me waves) /me \fIaction\fR Send action message (e.g. /me waves)
@\fIusername\fR Mention user (bell notification + highlight) @\fIusername\fR Mention user (bell notification + highlight)
@ -220,7 +222,7 @@ l l.
:w \fIuser text\fR Short alias for :msg :w \fIuser text\fR Short alias for :msg
:inbox Show private messages :inbox Show private messages
:last [\fIN\fR] Show last N messages from history (1\-50, default 10) :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 :mute\-joins Toggle join/leave system notifications on/off
:lang Show current UI language :lang Show current UI language
:lang \fIen|zh\fR Switch UI language for this session :lang \fIen|zh\fR Switch UI language for this session