Files
fdtd-coremem/crates/post/src/bin/viewer.rs
colin a2d35782a1 lift the post-processing tools (viewer, csv, decimate) into their own crate
- these tools shouldn't need access to coremem internals.
- lifting them out reduces some dependencies in coremem-the-library.
- separation allows faster iteration in the coremem library while
  temporarily breaking the post-processing tools (specifically,
  those tools could take deps on a specific coremem version and thereby
  we split the update process into two, smaller steps).
2022-07-17 15:47:39 -07:00

54 lines
1.8 KiB
Rust

use coremem_post::{Loader, Viewer};
use std::path::PathBuf;
use std::time::Duration;
use structopt::StructOpt;
use crossterm::event::{Event, KeyCode};
#[derive(Debug, StructOpt)]
struct Opt {
directory: PathBuf,
}
fn event_loop(mut viewer: Viewer) {
loop {
let mut time_steps = 0;
let mut z_steps = 0;
while crossterm::event::poll(Duration::from_millis(0)).unwrap() {
match crossterm::event::read().unwrap() {
Event::Key(e) => match e.code {
KeyCode::Left => time_steps -= 1,
KeyCode::PageUp => time_steps -= 10,
KeyCode::Right => time_steps += 1,
KeyCode::PageDown => time_steps += 10,
KeyCode::Up => z_steps += 1,
KeyCode::Down => z_steps -= 1,
KeyCode::Char('q') => return,
KeyCode::Char('w') => viewer.render_config().decrease_range(),
KeyCode::Char('s') => viewer.render_config().increase_range(),
KeyCode::Char('d') => viewer.render_config().next_mode(),
KeyCode::Char('a') => viewer.render_config().prev_mode(),
_ => {},
},
_ => {},
}
}
viewer.navigate(time_steps, z_steps);
let _ = crossterm::event::poll(Duration::from_millis(33)).unwrap();
}
}
fn main() {
let opt = Opt::from_args();
let loader = Loader::new(opt.directory);
let viewer = Viewer::new(loader);
// disable line buffering
crossterm::terminal::enable_raw_mode().unwrap();
viewer.render();
event_loop(viewer);
// return the terminal to its original state
crossterm::terminal::disable_raw_mode().unwrap();
}