Skip to content

Commit d74b250

Browse files
committed
功能:更新聊天命令帮助信息,增加命令描述,优化消息输出格式
1 parent 0ffdee6 commit d74b250

3 files changed

Lines changed: 56 additions & 9 deletions

File tree

client/src/commands/handlers/chat.rs

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crossterm::{
88
use std::borrow::Cow;
99

1010
use crate::commands::{Command, CommandContext, CommandResult};
11-
use crate::ui::CrosstermInputHandler;
11+
use crate::ui::{CrosstermInputHandler, CommandItem};
1212
use fishpi_rust::ChatDataContent;
1313

1414
pub struct ChatCommand {
@@ -46,7 +46,7 @@ impl Command for ChatCommand {
4646
r#"
4747
私聊命令:
4848
:h [页码] - 历史消息
49-
:r - 刷新消息
49+
:refresh - 刷新消息
5050
:read - 标记已读
5151
:rm <ID> - 撤回消息
5252
:cls - 清屏
@@ -58,6 +58,36 @@ impl Command for ChatCommand {
5858
impl ChatCommand {
5959
async fn chat_loop(&self, username: &str) -> Result<()> {
6060
let mut input_handler = CrosstermInputHandler::new();
61+
input_handler.set_commands(vec![
62+
CommandItem {
63+
name: ":q",
64+
desc: "退出",
65+
},
66+
CommandItem {
67+
name: ":help",
68+
desc: "帮助",
69+
},
70+
CommandItem {
71+
name: ":cls",
72+
desc: "清屏",
73+
},
74+
CommandItem {
75+
name: ":history",
76+
desc: "查看历史消息",
77+
},
78+
CommandItem {
79+
name: ":read",
80+
desc: "标记已读",
81+
},
82+
CommandItem {
83+
name: ":refresh",
84+
desc: "刷新消息",
85+
},
86+
CommandItem {
87+
name: ":rm",
88+
desc: "撤回消息",
89+
},
90+
]);
6191

6292
println!(
6393
"{}",
@@ -100,12 +130,12 @@ impl ChatCommand {
100130
)?;
101131
continue;
102132
}
103-
":help" | ":h" => {
133+
":help" => {
104134
println!("{}", self.help().green());
105135
self.context.show_switch_help();
106136

107137
}
108-
cmd if cmd.starts_with(":history") => {
138+
cmd if cmd.starts_with(":history") | cmd.starts_with(":h") => {
109139
let parts: Vec<&str> = cmd.split_whitespace().collect();
110140
let page = if parts.len() > 1 {
111141
parts[1].parse().unwrap_or(1)
@@ -114,7 +144,7 @@ impl ChatCommand {
114144
};
115145
self.show_history(username, page).await;
116146
}
117-
":refresh" | ":r" => {
147+
":refresh" => {
118148
self.refresh_messages(username).await;
119149
}
120150
":read" => {
@@ -178,9 +208,10 @@ impl ChatCommand {
178208
println!("与 {} 的最近聊天记录:", username.green());
179209
for msg in messages.iter().rev() {
180210
println!(
181-
" {} {}: {}",
211+
" {} {} [{}]: {}",
182212
msg.time.blue(),
183213
msg.sender_user_name.green().bold(),
214+
msg.oid.bright_black(),
184215
msg.content.cyan()
185216
);
186217
}
@@ -272,6 +303,18 @@ impl ChatCommand {
272303
println!("{}", "请输入用户名或编号:".cyan());
273304
let mut input_handler = CrosstermInputHandler::new();
274305
if let Some(input) = input_handler.start_input_loop("选择> ").await? {
306+
if input.starts_with(':') {
307+
match input.as_str() {
308+
":q" | ":exit" | ":quit" => {
309+
println!("{}", "已退出联系人选择".yellow());
310+
return Ok(());
311+
}
312+
_ => {
313+
println!("{}", "未知命令".red());
314+
return Ok(());
315+
}
316+
}
317+
}
275318
let username = if let Ok(index) = input.trim().parse::<usize>() {
276319
if index > 0 && index <= contacts.len() {
277320
&contacts[index - 1].receiver_user_name
@@ -332,9 +375,10 @@ impl ChatCommand {
332375
println!("与 {} 的聊天记录:", username.green());
333376
for msg in messages.iter().rev() {
334377
println!(
335-
"{} {}: {}",
378+
"{} {} [{}]: {}",
336379
msg.time.blue(),
337380
msg.sender_user_name.green().bold(),
381+
msg.oid.bright_black(),
338382
msg.content.cyan()
339383
);
340384
}

client/src/commands/handlers/chatroom.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl ChatroomCommand {
299299
let cfg = filter_handler.config.lock().unwrap();
300300
cfg.should_block(&msg.user_name, &msg.md_text())
301301
};
302-
if should_block {
302+
if should_block && !msg.is_redpacket() {
303303
filter_handler.push_blocked_msg((*msg).clone());
304304
return;
305305
}
@@ -530,7 +530,7 @@ impl ChatroomCommand {
530530
);
531531
} else {
532532
println!(
533-
"{} {}[{}]: {}",
533+
"{} {} [{}]:{}",
534534
msg.time.blue().bold(),
535535
msg.all_name().green().bold(),
536536
msg.oid.bright_black(),

client/src/commands/handlers/filter.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ impl FilterCommand {
177177
msg.1.oid.bright_black(),
178178
filter_tail_content(&formatted_content)
179179
);
180+
println!("{}","=".repeat(80).bright_black());
180181
} else {
181182
let filtered_content = filter_tail_content(&content);
182183
println!(
@@ -187,6 +188,8 @@ impl FilterCommand {
187188
msg.1.oid.bright_black(),
188189
strip_html_tags_chatroom(&filtered_content)
189190
);
191+
println!("{}","=".repeat(80).bright_black());
192+
190193
}
191194
}
192195

0 commit comments

Comments
 (0)