From 1ecb4401baa5fd30539a9768d04a45ad3b89fc70 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Tue, 16 Jul 2019 15:25:36 +1200 Subject: [PATCH] WIP --- src/lib.rs | 2 +- src/plugins/binaryview.rs | 37 ++++++++++++++++++------------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4528be06b..05b39f57a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,4 +32,4 @@ pub use cli::cli; pub use errors::ShellError; pub use object::base::{Primitive, Value}; pub use parser::parse::text::Text; -pub use parser::registry::{Args, CommandConfig, NamedType, PositionalType}; +pub use parser::registry::{Args, CommandConfig, NamedType, NamedValue, PositionalType}; diff --git a/src/plugins/binaryview.rs b/src/plugins/binaryview.rs index 4ed47d8bc..ea600d62c 100644 --- a/src/plugins/binaryview.rs +++ b/src/plugins/binaryview.rs @@ -14,7 +14,7 @@ impl BinaryView { impl Plugin for BinaryView { fn config(&mut self) -> Result { let mut named = IndexMap::new(); - named.insert("hires".to_string(), NamedType::Switch); + named.insert("--lores".to_string(), NamedType::Switch); Ok(CommandConfig { name: "binaryview".to_string(), positional: vec![], @@ -32,7 +32,7 @@ impl Plugin for BinaryView { item: Value::Binary(b), .. } => { - let _ = view_binary(&b, args.has("hires")); + let _ = view_binary(&b, args.has("lores")); } _ => {} } @@ -40,17 +40,17 @@ impl Plugin for BinaryView { } } -fn view_binary(b: &[u8], hires_mode: bool) -> Result<(), Box> { +fn view_binary(b: &[u8], lores_mode: bool) -> Result<(), Box> { if b.len() > 3 { match (b[0], b[1], b[2]) { (0x4e, 0x45, 0x53) => { - view_contents_interactive(b, hires_mode)?; + view_contents_interactive(b, lores_mode)?; return Ok(()); } _ => {} } } - view_contents(b, hires_mode)?; + view_contents(b, lores_mode)?; Ok(()) } @@ -59,17 +59,17 @@ pub struct RenderContext { pub height: usize, pub frame_buffer: Vec<(u8, u8, u8)>, pub since_last_button: Vec, - pub hires_mode: bool, + pub lores_mode: bool, } impl RenderContext { - pub fn blank(hires_mode: bool) -> RenderContext { + pub fn blank(lores_mode: bool) -> RenderContext { RenderContext { width: 0, height: 0, frame_buffer: vec![], since_last_button: vec![0; 8], - hires_mode, + lores_mode, } } pub fn clear(&mut self) { @@ -174,10 +174,10 @@ impl RenderContext { Ok(()) } pub fn flush(&mut self) -> Result<(), Box> { - if self.hires_mode { - self.render_to_screen_hires() - } else { + if self.lores_mode { self.render_to_screen_lores() + } else { + self.render_to_screen_hires() } } pub fn update(&mut self) -> Result<(), Box> { @@ -189,10 +189,10 @@ impl RenderContext { cursor.hide()?; self.width = terminal_size.0 as usize + 1; - self.height = if self.hires_mode { - terminal_size.1 as usize * 2 - } else { + self.height = if self.lores_mode { terminal_size.1 as usize + } else { + terminal_size.1 as usize * 2 }; } @@ -247,7 +247,7 @@ fn load_from_jpg_buffer(buffer: &[u8]) -> Option<(RawImageBuffer)> { }) } -pub fn view_contents(buffer: &[u8], hires_mode: bool) -> Result<(), Box> { +pub fn view_contents(buffer: &[u8], lores_mode: bool) -> Result<(), Box> { let mut raw_image_buffer = load_from_png_buffer(buffer); if raw_image_buffer.is_none() { @@ -261,7 +261,7 @@ pub fn view_contents(buffer: &[u8], hires_mode: bool) -> Result<(), Box Result<(), Box Result<(), Box Result<(), Box> { use rawkey::{KeyCode, RawKey}; @@ -344,7 +343,7 @@ pub fn view_contents_interactive( nes.reset(); if let Ok(_raw) = RawScreen::into_raw_mode() { - let mut render_context: RenderContext = RenderContext::blank(hires_mode); + let mut render_context: RenderContext = RenderContext::blank(lores_mode); let input = crossterm::input(); let _ = input.read_async(); let cursor = cursor();