performance improvements

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2024-11-13 22:52:25 -06:00
parent 8fe698df4e
commit 9a9fe86911

View File

@ -5,6 +5,7 @@ use device_query::{DeviceQuery, DeviceState, Keycode};
use std::sync::mpsc;
use clap::Parser;
use colored::Colorize;
use std::io::{stdout, Write};
/// Search for a pattern in a file and display the lines that contain it.
#[derive(Parser)]
@ -27,11 +28,12 @@ macro_rules! either {
}
}
fn main() {
let mut lock = stdout().lock(); // obtain std::out lock
let args = Cli::parse();
if args.autoscroll {
println!("Autoscroll is enabled!")
writeln!(lock, "Autoscroll is enabled!").unwrap();
}
print!("Use the up/down arrow keys to adjust the update speed!\nleft/right controls the scroll direction!\nPlease enter a string: ");
write!(lock, "Use the up/down arrow keys to adjust the update speed!\nleft/right controls the scroll direction!\nPlease enter a string: ").unwrap();
let mut input: String = read!("{}\n");
// check the final character, add a space if there isn't one.
if input.chars().nth(input.len()) != Some(' ') {
@ -77,7 +79,7 @@ fn main() {
// main thread
let mut polling_rate = initial_polling_rate;
let mut scroll_left = initial_scroll_left;
let mut send_status = String::new();
let mut send_status = "N/A".to_string();
loop {
// Get data from the polling thread
match rx.try_recv() {
@ -114,7 +116,7 @@ fn main() {
}
}
}
print!("i: {}, com buf status: {}, upd: {}ms, scrll: {}, {}\r\n", {i +=1; i}, send_status, polling_rate, either!(scroll_left => "L"; "R"), input);
write!(lock, "i: {}, com buf status: {}, upd: {}ms, scrll: {}, {}\r\n", {i +=1; i}, send_status, polling_rate, either!(scroll_left => "L"; "R"), input).unwrap();
// Scroll text
if scroll_left {
input = shift_left(input);
@ -141,7 +143,6 @@ fn shift_right(mut input: String) -> String {
fn detect_keys(keys: Vec<Keycode>, mut polling_rate: u64, mut scroll_left: bool) -> (bool, u64, bool) {
let mut user_update = false;
//detecting keydown events
//println!("{} {} ", polling_rate, scroll_left);
if keys.is_empty() {
return (user_update, polling_rate, scroll_left);
}