Add support for clearing and unclearing the screen

This commit is contained in:
Arthur Beck 2025-03-20 14:44:45 +00:00
parent db11b57965
commit 9e1cf429e4

View file

@ -39,6 +39,7 @@ struct User {
name: String,
status: UserStatus,
token: String,
no_show_msg: bool,
}
#[derive(Clone)]
@ -192,6 +193,7 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
name: String::from_utf8_lossy(&(buf[..i])).to_string(),
status: UserStatus::Online,
token: format!("{:x}", random::random::<u128>()),
no_show_msg: false
};
stream
@ -205,6 +207,7 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
name: "Netbot".to_owned(),
status: UserStatus::Online,
token: "".to_owned(),
no_show_msg: false
};
let mut broke = false;
@ -212,6 +215,7 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
if usr.name == user.name {
usr.status = user.status.clone();
usr.token = user.token.clone();
user.no_show_msg = usr.no_show_msg;
broke = true;
break;
}
@ -318,7 +322,9 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
/user [nick]: Get information about a user.\n \
/server [new name]: Get or set the server name.\n \
/users: List users.\n \
/me x: Say that you are doing x(for example, \"/me purrs\" as netbot would result in the output of \"netbot purrs\").\x1b[0m\n",
/me x: Say that you are doing x(for example, \"/me purrs\" as netbot would result in the output of \"netbot purrs\").\n \
/clear: Clears showing all messages(including rejoining) until /show is ran.\n \
/show: Output all messages ever.\x1b[0m\n",
)
.unwrap();
} else if contents.split(" ").collect::<Vec<&str>>()[0] == "/me" {
@ -338,6 +344,30 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
me_message: true,
});
}
} else if contents.split(" ").collect::<Vec<&str>>()[0] == "/clear" {
stream.write_all(b"\x1b[2J").unwrap();
user.no_show_msg = true;
for usr in &mut channel.lock().unwrap().online_users {
if usr.name == user.name {
usr.no_show_msg = user.no_show_msg;
}
}
} else if contents.split(" ").collect::<Vec<&str>>()[0] == "/show" {
{
let lock = channel.lock().unwrap();
for msg in &lock.messages {
if !display_msg(&mut stream, msg) {
break;
}
}
}
user.no_show_msg = false;
for usr in &mut channel.lock().unwrap().online_users {
if usr.name == user.name {
usr.no_show_msg = user.no_show_msg;
}
}
} else if contents.split(" ").collect::<Vec<&str>>()[0] == "/status"
|| contents == "/user"
{