[+] Relay mode
This commit is contained in:
+29
-12
@@ -1,6 +1,6 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
|
|
||||||
use std::{mem};
|
use std::{env, mem};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
@@ -154,13 +154,13 @@ impl Consts {
|
|||||||
.*%|_,%%_| |_%%,_|#%%%*"#, "Modified from hjw from ascii.co.uk/art/house");
|
.*%|_,%%_| |_%%,_|#%%%*"#, "Modified from hjw from ascii.co.uk/art/house");
|
||||||
let asc_title = AsciiArt::new(
|
let asc_title = AsciiArt::new(
|
||||||
r#"
|
r#"
|
||||||
. *
|
. *
|
||||||
_.__. _.| _ _. ' __
|
_.__. _.| _ _. ' __
|
||||||
(_] /_(_]|(/,(_] _)
|
(_] /_(_]|(/,(_] _)
|
||||||
.
|
.
|
||||||
__._ _ . , . |_ _ ._ _ _
|
__._ _ . , . _|._. _ _.._ _
|
||||||
_) [ )(_) \/\/ \_| [ )(_)[ | )(/,
|
_) [ )(_) \/\/ \_| (_][ (/,(_][ | )
|
||||||
._| "#, "Generated by patorjk.com/software/taag");
|
._| "#, "Generated by patorjk.com/software/taag with font Contessa");
|
||||||
Self {
|
Self {
|
||||||
asc_cat,
|
asc_cat,
|
||||||
asc_tree,
|
asc_tree,
|
||||||
@@ -173,7 +173,20 @@ _) [ )(_) \/\/ \_| [ )(_)[ | )(/,
|
|||||||
impl Mutes {
|
impl Mutes {
|
||||||
fn new(consts: &Consts) -> Self {
|
fn new(consts: &Consts) -> Self {
|
||||||
// Get the terminal size
|
// 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
|
// Initialize the buffers
|
||||||
let buf = vec![vec![None; width as usize]; height as usize];
|
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();
|
let draw_time = (end - now).as_secs_f32();
|
||||||
txt.push_str(&*format!("\rDraw time: {:.2}ms", draw_time * 1000.0));
|
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?;
|
stdout().write_all(txt.as_bytes()).await?;
|
||||||
// print!("{}", txt);
|
|
||||||
|
|
||||||
// Use tokio to sleep for 1/20th of a second
|
// Use tokio to sleep for 1/20th of a second
|
||||||
tokio::time::sleep(Duration::from_millis(1000 / 20)).await;
|
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)));
|
let mt = Arc::new(Mutex::new(Mutes::new(&cn)));
|
||||||
|
|
||||||
// Set terminal to raw mode
|
// 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
|
// Clear the screen
|
||||||
out.write(CLEAR.as_ref())?;
|
out.write(CLEAR.as_ref())?;
|
||||||
@@ -434,7 +452,6 @@ fn run() -> Result<()> {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Reset the terminal
|
// Reset the terminal
|
||||||
out.suspend_raw_mode().unwrap();
|
|
||||||
out.write(SHOW_CURSOR.as_ref())?;
|
out.write(SHOW_CURSOR.as_ref())?;
|
||||||
out.write(CLEAR.as_ref())?;
|
out.write(CLEAR.as_ref())?;
|
||||||
out.write("\r\nThanks for visiting <3\n".as_ref())?;
|
out.write("\r\nThanks for visiting <3\n".as_ref())?;
|
||||||
|
|||||||
Reference in New Issue
Block a user