[+] Relay mode

This commit is contained in:
Azalea Gui
2023-03-08 23:24:31 -05:00
parent 1d64066d95
commit 79caf88957
+29 -12
View File
@@ -1,6 +1,6 @@
#![feature(let_chains)]
use std::{mem};
use std::{env, mem};
use std::io::Write;
use std::ops::DerefMut;
use std::process::exit;
@@ -154,13 +154,13 @@ impl Consts {
.*%|_,%%_| |_%%,_|#%%%*"#, "Modified from hjw from ascii.co.uk/art/house");
let asc_title = AsciiArt::new(
r#"
. *
_.__. _.| _ _. ' __
(_] /_(_]|(/,(_] _)
.
__._ _ . , . |_ _ ._ _ _
_) [ )(_) \/\/ \_| [ )(_)[ | )(/,
._| "#, "Generated by patorjk.com/software/taag");
. *
_.__. _.| _ _. ' __
(_] /_(_]|(/,(_] _)
.
__._ _ . , . _|._. _ _.._ _
_) [ )(_) \/\/ \_| (_][ (/,(_][ | )
._| "#, "Generated by patorjk.com/software/taag with font Contessa");
Self {
asc_cat,
asc_tree,
@@ -173,7 +173,20 @@ _) [ )(_) \/\/ \_| [ )(_)[ | )(/,
impl Mutes {
fn new(consts: &Consts) -> Self {
// Get the terminal size
let (width, height) = termion::terminal_size().unwrap();
let width: u16;
let height: u16;
if let Ok(size) = env::var("TN_TERM_SIZE") {
// Environment variable in format "widthxheight"
let mut split = size.split('x');
width = split.next().unwrap().parse().unwrap();
height = split.next().unwrap().parse().unwrap();
}
else {
// Get the terminal size from the terminal
let (w, h) = termion::terminal_size().unwrap();
width = w;
height = h;
}
// Initialize the buffers
let buf = vec![vec![None; width as usize]; height as usize];
@@ -352,8 +365,10 @@ async fn start_update_loop(mt: Arc<Mutex<Mutes>>, cn: &Consts) -> Result<()> {
let draw_time = (end - now).as_secs_f32();
txt.push_str(&*format!("\rDraw time: {:.2}ms", draw_time * 1000.0));
// Frame end with 3 Null bytes
txt.push_str("\x00\x00\x00");
stdout().write_all(txt.as_bytes()).await?;
// print!("{}", txt);
// Use tokio to sleep for 1/20th of a second
tokio::time::sleep(Duration::from_millis(1000 / 20)).await;
@@ -416,7 +431,10 @@ fn run() -> Result<()> {
let mt = Arc::new(Mutex::new(Mutes::new(&cn)));
// Set terminal to raw mode
let mut out = std::io::stdout().into_raw_mode().unwrap();
let mut out = std::io::stdout();
if env::var("TN_TERM_SIZE").is_err() {
std::io::stdout().into_raw_mode().unwrap();
}
// Clear the screen
out.write(CLEAR.as_ref())?;
@@ -434,7 +452,6 @@ fn run() -> Result<()> {
})?;
// Reset the terminal
out.suspend_raw_mode().unwrap();
out.write(SHOW_CURSOR.as_ref())?;
out.write(CLEAR.as_ref())?;
out.write("\r\nThanks for visiting <3\n".as_ref())?;