I forgor to push something

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2024-11-13 13:27:53 -06:00
parent c101bd1440
commit b490716232

View File

@ -44,48 +44,33 @@ fn main() {
let initial_polling_rate: u64 = 50; let initial_polling_rate: u64 = 50;
let initial_scroll_left: bool = true; let initial_scroll_left: bool = true;
if args.autoscroll {
// polling thread // polling thread
thread::spawn(move || { thread::spawn(move || {
let mut polling_rate = initial_polling_rate; let mut polling_rate = initial_polling_rate;
let mut scroll_left = initial_scroll_left; let mut scroll_left = initial_scroll_left;
let device_state = DeviceState::new(); let device_state = DeviceState::new();
loop { loop {
if args.autoscroll { // Poll for input
let keys = device_state.get_keys(); // poll the keys
match rx.try_recv() { (polling_rate, scroll_left) = detect_keys(keys, polling_rate, scroll_left);
Ok((new_rate, new_scroll)) => { let _ = tx.send((polling_rate, scroll_left));
polling_rate = new_rate; thread::sleep(Duration::from_millis(100)); // poll every 50 ms
scroll_left = new_scroll;
}
Err(mpsc::TryRecvError::Empty) => {
//eprintln!("No new data. ;(");
}
Err(mpsc::TryRecvError::Disconnected) => {
eprintln!("Channel has been closed.");
break;
}
}
} }
// Poll for input
let keys = device_state.get_keys(); // poll the keys
(polling_rate, scroll_left) = detect_keys(keys, polling_rate, scroll_left);
let _ = tx.send((polling_rate, scroll_left));
thread::sleep(Duration::from_millis(100)); // poll every 50 ms
}
}); });
}
// main thread // main thread
let mut polling_rate = initial_polling_rate; let mut polling_rate = initial_polling_rate;
let mut scroll_left = initial_scroll_left; let mut scroll_left = initial_scroll_left;
loop { loop {
// Get data from the polling thread // Get data from the polling thread
match rx.try_recv() { match rx.try_recv() {
Ok((new_rate, new_scroll)) => { Ok((new_rate, new_scroll)) => {
polling_rate = new_rate; polling_rate = new_rate;
scroll_left = new_scroll; if !args.autoscroll {
scroll_left = new_scroll;
}
} }
Err(mpsc::TryRecvError::Empty) => { Err(mpsc::TryRecvError::Empty) => {
//eprintln!("No new data. ;("); //eprintln!("No new data. ;(");
@ -99,12 +84,10 @@ fn main() {
println!("i: {}, upd: {}ms, scrll: {}, {}", {i +=1; i}, polling_rate, either!(scroll_left => "L"; "R"), input); println!("i: {}, upd: {}ms, scrll: {}, {}", {i +=1; i}, polling_rate, either!(scroll_left => "L"; "R"), input);
// Autoscroll: Autoscroll automatically toggles ths scrolling direction when the scrolling reaches a space. // Autoscroll: Autoscroll automatically toggles ths scrolling direction when the scrolling reaches a nonspace.
if args.autoscroll { if args.autoscroll {
if input.chars().nth(input.len()) == Some(' ') { if !char::is_whitespace(input.chars().nth(0).unwrap()) | !char::is_whitespace(input.chars().nth(input.len() - 1).unwrap()) {
scroll_left = !scroll_left; scroll_left = !scroll_left;
// inform the other thread of the new state of scroll_left
tx_clone.send((polling_rate, scroll_left));
} }
} }
@ -118,7 +101,7 @@ fn main() {
} }
fn shift_left(mut input: String) -> String { fn shift_left(mut input: String) -> String {
let tmp: char = input.chars().nth(0).expect("char"); let tmp: char = input.chars().nth(0).unwrap();
input = input.substring(1,input.len()).to_string(); input = input.substring(1,input.len()).to_string();
input.push_str(&tmp.to_string()); input.push_str(&tmp.to_string());
return input; return input;
@ -126,7 +109,7 @@ fn shift_left(mut input: String) -> String {
fn shift_right(mut input: String) -> String { fn shift_right(mut input: String) -> String {
let tmp: String = input.substring(0, input.len() - 1).to_string(); let tmp: String = input.substring(0, input.len() - 1).to_string();
input = input.chars().nth(input.len() - 1).expect("char").to_string(); input = input.chars().nth(input.len() - 1).unwrap().to_string();
input.push_str(&tmp); input.push_str(&tmp);
return input; return input;
} }