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,
|
name: String,
|
||||||
status: UserStatus,
|
status: UserStatus,
|
||||||
token: String,
|
token: String,
|
||||||
|
no_show_msg: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -192,6 +193,7 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
|
||||||
name: String::from_utf8_lossy(&(buf[..i])).to_string(),
|
name: String::from_utf8_lossy(&(buf[..i])).to_string(),
|
||||||
status: UserStatus::Online,
|
status: UserStatus::Online,
|
||||||
token: format!("{:x}", random::random::<u128>()),
|
token: format!("{:x}", random::random::<u128>()),
|
||||||
|
no_show_msg: false
|
||||||
};
|
};
|
||||||
|
|
||||||
stream
|
stream
|
||||||
|
@ -205,6 +207,7 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
|
||||||
name: "Netbot".to_owned(),
|
name: "Netbot".to_owned(),
|
||||||
status: UserStatus::Online,
|
status: UserStatus::Online,
|
||||||
token: "".to_owned(),
|
token: "".to_owned(),
|
||||||
|
no_show_msg: false
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut broke = false;
|
let mut broke = false;
|
||||||
|
@ -212,6 +215,7 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
|
||||||
if usr.name == user.name {
|
if usr.name == user.name {
|
||||||
usr.status = user.status.clone();
|
usr.status = user.status.clone();
|
||||||
usr.token = user.token.clone();
|
usr.token = user.token.clone();
|
||||||
|
user.no_show_msg = usr.no_show_msg;
|
||||||
broke = true;
|
broke = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -318,7 +322,9 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
|
||||||
/user [nick]: Get information about a user.\n \
|
/user [nick]: Get information about a user.\n \
|
||||||
/server [new name]: Get or set the server name.\n \
|
/server [new name]: Get or set the server name.\n \
|
||||||
/users: List users.\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();
|
.unwrap();
|
||||||
} else if contents.split(" ").collect::<Vec<&str>>()[0] == "/me" {
|
} else if contents.split(" ").collect::<Vec<&str>>()[0] == "/me" {
|
||||||
|
@ -338,6 +344,30 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
|
||||||
me_message: true,
|
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"
|
} else if contents.split(" ").collect::<Vec<&str>>()[0] == "/status"
|
||||||
|| contents == "/user"
|
|| contents == "/user"
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue