1
0
Fork 0
mirror of https://github.com/alemidev/scope-tui.git synced 2024-11-23 14:14:48 +01:00

feat: better ux, variable window size

improved keybinds: arrows move view, pageUp/pageDwn move trigger
threshold. Current sample window displayed on UI.
This commit is contained in:
əlemi 2023-01-13 02:52:16 +01:00
parent 73cb8bc167
commit b48989d4e9
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 43 additions and 38 deletions

View file

@ -26,8 +26,8 @@ pub struct App {
impl App { impl App {
pub fn update_values(&mut self) { pub fn update_values(&mut self) {
if self.cfg.scale > 32768 { if self.cfg.scale > 32770 { // sample max value is 32768 (32 bits), but we leave 2 pixels for
self.cfg.scale = 32768; self.cfg.scale = 32770; // padding (and to not "disaling" range when reaching limit)
} }
if self.cfg.scale < 0 { if self.cfg.scale < 0 {
self.cfg.scale = 0; self.cfg.scale = 0;
@ -123,7 +123,7 @@ pub fn run_app<T : Backend>(args: Args, terminal: &mut Terminal<T>) -> Result<()
let s = match Simple::new( let s = match Simple::new(
None, // Use the default server None, // Use the default server
"ScopeTUI", // Our applications name "scope-tui", // Our applications name
Direction::Record, // We want a record stream Direction::Record, // We want a record stream
dev, // Use requested device, or default dev, // Use requested device, or default
"data", // Description of our stream "data", // Description of our stream
@ -243,7 +243,7 @@ pub fn run_app<T : Backend>(args: Args, terminal: &mut Terminal<T>) -> Result<()
terminal.draw(|f| { terminal.draw(|f| {
let mut size = f.size(); let mut size = f.size();
if app.cfg.show_ui { if app.cfg.show_ui {
let heading = header(&args, &app, samples as u32, framerate); let heading = header(&app, samples as u32, framerate);
f.render_widget(heading, Rect { x: size.x, y: size.y, width: size.width, height:1 }); f.render_widget(heading, Rect { x: size.x, y: size.y, width: size.width, height:1 });
size.height -= 1; size.height -= 1;
size.y += 1; size.y += 1;
@ -258,29 +258,34 @@ pub fn run_app<T : Backend>(args: Args, terminal: &mut Terminal<T>) -> Result<()
match key.modifiers { match key.modifiers {
KeyModifiers::SHIFT => { KeyModifiers::SHIFT => {
match key.code { match key.code {
KeyCode::Up => app.cfg.threshold += 1000.0, KeyCode::Up => app.cfg.scale -= 1000, // inverted to act as zoom
KeyCode::Down => app.cfg.threshold -= 1000.0, KeyCode::Down => app.cfg.scale += 1000, // inverted to act as zoom
KeyCode::Right => app.cfg.scale += 1000, KeyCode::Right => app.cfg.width += 100,
KeyCode::Left => app.cfg.scale -= 1000, KeyCode::Left => app.cfg.width -= 100,
KeyCode::PageUp => app.cfg.threshold += 1000.0,
KeyCode::PageDown => app.cfg.threshold -= 1000.0,
_ => {}, _ => {},
} }
}, },
KeyModifiers::CONTROL => { KeyModifiers::CONTROL => {
match key.code { // mimic other programs shortcuts to quit, for user friendlyness match key.code { // mimic other programs shortcuts to quit, for user friendlyness
KeyCode::Char('c') | KeyCode::Char('q') | KeyCode::Char('w') => break, KeyCode::Char('c') | KeyCode::Char('q') | KeyCode::Char('w') => break,
KeyCode::Up => app.cfg.threshold += 10.0, KeyCode::Up => app.cfg.scale -= 10, // inverted to act as zoom
KeyCode::Down => app.cfg.threshold -= 10.0, KeyCode::Down => app.cfg.scale += 10, // inverted to act as zoom
KeyCode::Right => app.cfg.scale += 10, KeyCode::Right => app.cfg.width += 1,
KeyCode::Left => app.cfg.scale -= 10, KeyCode::Left => app.cfg.width -= 1,
_ => {}, KeyCode::PageUp => app.cfg.threshold += 10.0,
} KeyCode::PageDown => app.cfg.threshold -= 10.0,
KeyCode::Char('r') => { // reset settings
app.cfg.references = !args.no_reference;
app.cfg.show_ui = !args.no_ui;
app.cfg.braille = !args.no_braille;
app.cfg.threshold = args.threshold;
app.cfg.width = args.buffer / (args.channels as u32 * 2); // TODO ...
app.cfg.scale = args.range;
app.cfg.vectorscope = args.vectorscope;
app.cfg.triggering = args.triggering;
}, },
KeyModifiers::ALT => {
match key.code {
KeyCode::Up => app.cfg.threshold += 1.0,
KeyCode::Down => app.cfg.threshold -= 1.0,
KeyCode::Right => app.cfg.scale += 1,
KeyCode::Left => app.cfg.scale -= 1,
_ => {}, _ => {},
} }
}, },
@ -294,18 +299,20 @@ pub fn run_app<T : Backend>(args: Args, terminal: &mut Terminal<T>) -> Result<()
KeyCode::Char('h') => app.cfg.show_ui = !app.cfg.show_ui, KeyCode::Char('h') => app.cfg.show_ui = !app.cfg.show_ui,
KeyCode::Char('r') => app.cfg.references = !app.cfg.references, KeyCode::Char('r') => app.cfg.references = !app.cfg.references,
KeyCode::Char('t') => app.cfg.triggering = !app.cfg.triggering, KeyCode::Char('t') => app.cfg.triggering = !app.cfg.triggering,
KeyCode::Up => app.cfg.threshold += 100.0, KeyCode::Up => app.cfg.scale -= 250, // inverted to act as zoom
KeyCode::Down => app.cfg.threshold -= 100.0, KeyCode::Down => app.cfg.scale += 250, // inverted to act as zoom
KeyCode::Right => app.cfg.scale += 100, KeyCode::Right => app.cfg.width += 25,
KeyCode::Left => app.cfg.scale -= 100, KeyCode::Left => app.cfg.width -= 25,
KeyCode::Esc => { // reset settings KeyCode::PageUp => app.cfg.threshold += 250.0,
app.cfg.references = !args.no_reference; KeyCode::PageDown => app.cfg.threshold -= 250.0,
app.cfg.braille = !args.no_braille; KeyCode::Tab => { // only reset "zoom"
app.cfg.threshold = args.threshold;
app.cfg.width = args.buffer / (args.channels as u32 * 2); // TODO ... app.cfg.width = args.buffer / (args.channels as u32 * 2); // TODO ...
app.cfg.scale = args.range; app.cfg.scale = args.range;
},
KeyCode::Esc => { // back to oscilloscope
app.cfg.references = !args.no_reference;
app.cfg.show_ui = !args.no_ui;
app.cfg.vectorscope = args.vectorscope; app.cfg.vectorscope = args.vectorscope;
app.cfg.triggering = args.triggering;
}, },
_ => {}, _ => {},
} }
@ -320,7 +327,7 @@ pub fn run_app<T : Backend>(args: Args, terminal: &mut Terminal<T>) -> Result<()
// TODO these functions probably shouldn't be here // TODO these functions probably shouldn't be here
fn header(args: &Args, app: &App, samples: u32, framerate: u32) -> Table<'static> { fn header(app: &App, samples: u32, framerate: u32) -> Table<'static> {
Table::new( Table::new(
vec![ vec![
Row::new( Row::new(
@ -328,10 +335,9 @@ fn header(args: &Args, app: &App, samples: u32, framerate: u32) -> Table<'static
Cell::from(format!("TUI {}", if app.cfg.vectorscope { "Vectorscope" } else { "Oscilloscope" })).style(Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)), Cell::from(format!("TUI {}", if app.cfg.vectorscope { "Vectorscope" } else { "Oscilloscope" })).style(Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)),
Cell::from(format!("{} plot", if app.cfg.scatter { "scatter" } else { "line" })), Cell::from(format!("{} plot", if app.cfg.scatter { "scatter" } else { "line" })),
Cell::from(format!("{}", if app.cfg.triggering { "triggered" } else { "live" } )), Cell::from(format!("{}", if app.cfg.triggering { "triggered" } else { "live" } )),
Cell::from(format!("threshold {:.0}", app.cfg.threshold)), Cell::from(format!("threshold {:.0} ^", app.cfg.threshold)),
Cell::from(format!("range +-{}", app.cfg.scale)), Cell::from(format!("range +{}-", app.cfg.scale)),
Cell::from(format!("{}smpl", samples as u32)), Cell::from(format!("{}/{} samples", samples as u32, app.cfg.width)),
Cell::from(format!("{:.1}kHz", args.sample_rate as f32 / 1000.0)),
Cell::from(format!("{}fps", framerate)), Cell::from(format!("{}fps", framerate)),
] ]
) )
@ -344,8 +350,7 @@ fn header(args: &Args, app: &App, samples: u32, framerate: u32) -> Table<'static
Constraint::Percentage(12), Constraint::Percentage(12),
Constraint::Percentage(12), Constraint::Percentage(12),
Constraint::Percentage(12), Constraint::Percentage(12),
Constraint::Percentage(6), Constraint::Percentage(12),
Constraint::Percentage(6),
Constraint::Percentage(6) Constraint::Percentage(6)
]) ])
} }

View file

@ -70,7 +70,7 @@ pub struct Args {
triggering: bool, triggering: bool,
/// Threshold value for triggering /// Threshold value for triggering
#[arg(long, default_value_t = 0.0)] #[arg(long, value_name = "VAL", default_value_t = 0.0)]
threshold: f64, threshold: f64,
/// Don't draw reference line /// Don't draw reference line