Add support for clearing and unclearing the screen
This commit is contained in:
parent
db11b57965
commit
9e1cf429e4
1 changed files with 31 additions and 1 deletions
32
src/main.rs
32
src/main.rs
|
@ -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"
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue