Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
09ddf5919e | |||
9a9fe86911 | |||
8fe698df4e |
BIN
._.DS_Store
Executable file
BIN
._.DS_Store
Executable file
Binary file not shown.
13
src/main.rs
13
src/main.rs
@ -5,6 +5,7 @@ use device_query::{DeviceQuery, DeviceState, Keycode};
|
|||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
use std::io::{stdout, Write};
|
||||||
|
|
||||||
/// Search for a pattern in a file and display the lines that contain it.
|
/// Search for a pattern in a file and display the lines that contain it.
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
@ -27,11 +28,12 @@ macro_rules! either {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let mut lock = stdout().lock(); // obtain std::out lock
|
||||||
let args = Cli::parse();
|
let args = Cli::parse();
|
||||||
if args.autoscroll {
|
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");
|
let mut input: String = read!("{}\n");
|
||||||
// check the final character, add a space if there isn't one.
|
// check the final character, add a space if there isn't one.
|
||||||
if input.chars().nth(input.len()) != Some(' ') {
|
if input.chars().nth(input.len()) != Some(' ') {
|
||||||
@ -77,7 +79,7 @@ fn main() {
|
|||||||
// 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;
|
||||||
let mut send_status = String::new();
|
let mut send_status = "N/A".to_string();
|
||||||
loop {
|
loop {
|
||||||
// Get data from the polling thread
|
// Get data from the polling thread
|
||||||
match rx.try_recv() {
|
match rx.try_recv() {
|
||||||
@ -94,7 +96,6 @@ fn main() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thread::sleep(Duration::from_millis(polling_rate));
|
|
||||||
|
|
||||||
// Autoscroll: Autoscroll automatically toggles ths scrolling direction when the scrolling reaches a nonspace.
|
// Autoscroll: Autoscroll automatically toggles ths scrolling direction when the scrolling reaches a nonspace.
|
||||||
if args.autoscroll {
|
if args.autoscroll {
|
||||||
@ -114,13 +115,14 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("i: {}, com buf status: {}, upd: {}ms, scrll: {}, {}", {i +=1; i}, send_status, polling_rate, either!(scroll_left => "L"; "R"), input);
|
write!(lock, "i: {}, com buf status: {}, upd: {}ms, scrll: {}, {}\n", {i +=1; i}, send_status, polling_rate, either!(scroll_left => "L"; "R"), input).unwrap();
|
||||||
// Scroll text
|
// Scroll text
|
||||||
if scroll_left {
|
if scroll_left {
|
||||||
input = shift_left(input);
|
input = shift_left(input);
|
||||||
} else {
|
} else {
|
||||||
input = shift_right(input);
|
input = shift_right(input);
|
||||||
}
|
}
|
||||||
|
thread::sleep(Duration::from_millis(polling_rate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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) {
|
fn detect_keys(keys: Vec<Keycode>, mut polling_rate: u64, mut scroll_left: bool) -> (bool, u64, bool) {
|
||||||
let mut user_update = false;
|
let mut user_update = false;
|
||||||
//detecting keydown events
|
//detecting keydown events
|
||||||
//println!("{} {} ", polling_rate, scroll_left);
|
|
||||||
if keys.is_empty() {
|
if keys.is_empty() {
|
||||||
return (user_update, polling_rate, scroll_left);
|
return (user_update, polling_rate, scroll_left);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user