remove anes dependency
This commit is contained in:
parent
72fb2b67bb
commit
297ba131b9
@ -5,8 +5,5 @@ edition = "2021"
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
anes = "0.1.6"
|
|
||||||
|
|
||||||
[target.'cfg(target_family = "unix")'.dependencies]
|
[target.'cfg(target_family = "unix")'.dependencies]
|
||||||
termios = "0.3.3"
|
termios = "0.3.3"
|
||||||
|
20
src/lib.rs
20
src/lib.rs
@ -1,7 +1,6 @@
|
|||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
use termios::{cfmakeraw, tcsetattr, Termios, TCSANOW};
|
use termios::{cfmakeraw, tcsetattr, Termios, TCSANOW};
|
||||||
|
|
||||||
use anes::{esc, ResetAttributes};
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -13,6 +12,11 @@ use std::time::{Duration, Instant};
|
|||||||
|
|
||||||
type Result<T> = std::result::Result<T, io::Error>;
|
type Result<T> = std::result::Result<T, io::Error>;
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! esc {
|
||||||
|
($($arg:expr),*) => { concat!("\x1B", $($arg),*) };
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ConnType {
|
enum ConnType {
|
||||||
Local,
|
Local,
|
||||||
@ -137,7 +141,8 @@ impl NetUser {
|
|||||||
const TIME_OUT: u64 = 300;
|
const TIME_OUT: u64 = 300;
|
||||||
if self.info.timeout.elapsed().as_secs() >= TIME_OUT {
|
if self.info.timeout.elapsed().as_secs() >= TIME_OUT {
|
||||||
let e = esc!("[1;31m");
|
let e = esc!("[1;31m");
|
||||||
self.write_ln(format!("\r\n\r\n{e}Timeout!{ResetAttributes}").as_str())
|
let r = esc!("[0m");
|
||||||
|
self.write_ln(format!("\r\n\r\n{e}Timeout!{r}").as_str())
|
||||||
.expect("write");
|
.expect("write");
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
@ -148,7 +153,8 @@ impl NetUser {
|
|||||||
let time_left = self.info.timeleft;
|
let time_left = self.info.timeleft;
|
||||||
if start_time.elapsed().as_secs() >= time_left {
|
if start_time.elapsed().as_secs() >= time_left {
|
||||||
let e = esc!("[1;31m");
|
let e = esc!("[1;31m");
|
||||||
self.write_ln(format!("\r\n\r\n{e}You're out of time!{ResetAttributes}\r\n").as_str())
|
let r = esc!("[0m");
|
||||||
|
self.write_ln(format!("\r\n\r\n{e}You're out of time!{r}\r\n").as_str())
|
||||||
.expect("write");
|
.expect("write");
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
@ -221,10 +227,14 @@ impl Conn for User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn door_clear_screen(user: &mut User) -> Result<()> {
|
||||||
|
user.write_str(format!("{}{}", esc!("[2J"), esc!("[1;1H")).to_string().as_str())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn door_display_file(user: &mut User, path: &str) -> Result<()> {
|
pub fn door_display_file(user: &mut User, path: &str) -> Result<()> {
|
||||||
if let Ok(file) = std::fs::read(path) {
|
if let Ok(file) = std::fs::read(path) {
|
||||||
user.write(&file)?;
|
user.write(&file)?;
|
||||||
user.write_str(ResetAttributes.to_string().as_str())?;
|
user.write_str(esc!("[0m").to_string().as_str())?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -258,7 +268,7 @@ pub fn door_read_string(user: &mut impl Conn, len: usize) -> Result<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let s = std::str::from_utf8(&received).unwrap().to_string();
|
let s = std::str::from_utf8(&received).unwrap().to_string();
|
||||||
user.write_ln(ResetAttributes.to_string().as_str())?;
|
user.write_ln(esc!("[0m").to_string().as_str())?;
|
||||||
Ok(s)
|
Ok(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user