I forgor to push something
This commit is contained in:
parent
c101bd1440
commit
b490716232
47
src/main.rs
47
src/main.rs
@ -44,48 +44,33 @@ fn main() {
|
||||
|
||||
let initial_polling_rate: u64 = 50;
|
||||
let initial_scroll_left: bool = true;
|
||||
|
||||
if args.autoscroll {
|
||||
// polling thread
|
||||
thread::spawn(move || {
|
||||
let mut polling_rate = initial_polling_rate;
|
||||
let mut scroll_left = initial_scroll_left;
|
||||
let device_state = DeviceState::new();
|
||||
|
||||
loop {
|
||||
if args.autoscroll {
|
||||
|
||||
match rx.try_recv() {
|
||||
Ok((new_rate, new_scroll)) => {
|
||||
polling_rate = new_rate;
|
||||
scroll_left = new_scroll;
|
||||
}
|
||||
Err(mpsc::TryRecvError::Empty) => {
|
||||
//eprintln!("No new data. ;(");
|
||||
}
|
||||
Err(mpsc::TryRecvError::Disconnected) => {
|
||||
eprintln!("Channel has been closed.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
loop {
|
||||
// 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
|
||||
}
|
||||
// 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
|
||||
let mut polling_rate = initial_polling_rate;
|
||||
let mut scroll_left = initial_scroll_left;
|
||||
loop {
|
||||
// Get data from the polling thread
|
||||
|
||||
match rx.try_recv() {
|
||||
Ok((new_rate, new_scroll)) => {
|
||||
polling_rate = new_rate;
|
||||
scroll_left = new_scroll;
|
||||
if !args.autoscroll {
|
||||
scroll_left = new_scroll;
|
||||
}
|
||||
}
|
||||
Err(mpsc::TryRecvError::Empty) => {
|
||||
//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);
|
||||
|
||||
// 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 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;
|
||||
// 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 {
|
||||
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.push_str(&tmp.to_string());
|
||||
return input;
|
||||
@ -126,7 +109,7 @@ fn shift_left(mut input: String) -> String {
|
||||
|
||||
fn shift_right(mut input: String) -> 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);
|
||||
return input;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user