diff --git a/src/io/graphics.rs b/src/io/graphics.rs index c8077a77ad1387573d7b93005b3fe8d1580b3685..be5b068bde29050756fd2966b37948cebad977bc 100644 --- a/src/io/graphics.rs +++ b/src/io/graphics.rs @@ -1,6 +1,9 @@ +#[cfg(feature = "orbital")] use edit::buffer::TextBuffer; +#[cfg(feature = "orbital")] use io::redraw::RedrawTask; use state::editor::Editor; +#[cfg(feature = "orbital")] use state::mode::{Mode, PrimitiveMode}; #[cfg(feature = "orbital")] @@ -39,7 +42,10 @@ impl Editor { let mut string = false; - for (y, row) in self.buffers.current_buffer().lines().enumerate() { + for (y, row) in self.buffers + .current_buffer() + .lines() + .enumerate() { for (x, c) in row.chars().enumerate() { // TODO: Move outta here let color = if self.options.highlight { @@ -49,36 +55,18 @@ impl Editor { (226, 225, 167) //(167, 222, 156) } _ if string => (226, 225, 167), //(167, 222, 156) - '!' | - '@' | - '#' | - '$' | - '%' | - '^' | - '&' | - '|' | - '*' | - '+' | - '-' | - '/' | - ':' | - '=' | - '<' | - '>' => (198, 83, 83), //(228, 190, 175), //(194, 106, 71), + '!' | '@' | '#' | '$' | '%' | '^' | '&' | '|' | '*' | '+' | '-' | '/' | + ':' | '=' | '<' | '>' => (198, 83, 83), //(228, 190, 175), //(194, 106, 71), '.' | ',' => (241, 213, 226), '(' | ')' | '[' | ']' | '{' | '}' => (164, 212, 125), //(195, 139, 75), - '0' ... '9' => (209, 209, 177), + '0'...'9' => (209, 209, 177), _ => (255, 255, 255), } } else { (255, 255, 255) }; - let c = if c == '\t' { - ' ' - } else { - c - }; + let c = if c == '\t' { ' ' } else { c }; if pos_x == x && pos_y == y { self.window.char(8 * (x - scroll_x) as i32, @@ -122,7 +110,10 @@ impl Editor { self.draw_status_bar(); for (n, c) in self.prompt.chars().enumerate() { - self.window.char(n as i32 * 8, h as i32 - 16 - 1, c, Color::rgb(255, 255, 255)); + self.window.char(n as i32 * 8, + h as i32 - 16 - 1, + c, + Color::rgb(255, 255, 255)); } self.window.sync(); @@ -135,41 +126,54 @@ impl Editor { let mode = self.cursor().mode; - let current_title = - self.buffers.current_buffer_info().title.as_ref().map(|s| s.as_str()).unwrap_or(""); + let current_title = self.buffers + .current_buffer_info() + .title + .as_ref() + .map(|s| s.as_str()) + .unwrap_or(""); - let items = [ - (self.status_bar.mode, 0, 4), - (current_title, 1, 4), - (&self.status_bar.cmd, 2, 4), - (&self.status_bar.msg, 3, 4) - ]; + let items = [(self.status_bar.mode, 0, 4), + (current_title, 1, 4), + (&self.status_bar.cmd, 2, 4), + (&self.status_bar.msg, 3, 4)]; for &(text, a, b) in items.iter() { for (n, c) in (if text.len() as u32 > w / (8 * b) { - text.chars().take((w / (8 * b) - 5) as usize).chain(vec!['.'; 3]).collect::<Vec<_>>() - } else { - text.chars().collect() - }) - .into_iter() - .enumerate() { + text.chars() + .take((w / (8 * b) - 5) as usize) + .chain(vec!['.'; 3]) + .collect::<Vec<_>>() + } else { + text.chars().collect() + }) + .into_iter() + .enumerate() { self.window.char(((w * a) / b) as i32 + (n as i32 * 8), - h as i32 - 16 - 1 - - { - if mode == Mode::Primitive(PrimitiveMode::Prompt) { - 16 + 1 + 1 - } else { - 0 - } - }, - c, - Color::rgb(255, 255, 255)); + h as i32 - 16 - 1 - + { + if mode == Mode::Primitive(PrimitiveMode::Prompt) { + 16 + 1 + 1 + } else { + 0 + } + }, + c, + Color::rgb(255, 255, 255)); } } } } +#[cfg(not(feature = "orbital"))] +impl Editor { + /// Redraw the window + pub fn redraw(&mut self) {} + /// Redraw the status bar + pub fn redraw_status_bar(&mut self) {} +} + /// The statubar (showing various info about the current state of the editor) pub struct StatusBar { /// The current mode diff --git a/src/io/key_state.rs b/src/io/key_state.rs index bc736fe4c339d3514ed702dd722c8e85c3e50295..e0ec99761e40525039ef6b95a4a1c43cdb8d3e7a 100644 --- a/src/io/key_state.rs +++ b/src/io/key_state.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "orbital")] use io::key::Key; #[cfg(feature = "orbital")] use orbclient::KeyEvent; @@ -30,12 +31,7 @@ impl KeyState { /// Feed the keystate with a new key input. #[cfg(feature = "orbital")] pub fn feed(&mut self, k: KeyEvent) -> Option<Key> { - use orbclient::{ - K_ALT, - K_CTRL, - K_LEFT_SHIFT, - K_RIGHT_SHIFT - }; + use orbclient::{K_ALT, K_CTRL, K_LEFT_SHIFT, K_RIGHT_SHIFT}; let c = k.character; match c { diff --git a/src/io/parse.rs b/src/io/parse.rs index 9f6af08fdaf3d7eab0e4c4627f629ed78d3e058f..76478dae3f25af1cc0455de792f8122f093b38d5 100644 --- a/src/io/parse.rs +++ b/src/io/parse.rs @@ -1,6 +1,8 @@ use io::key::{Cmd, Key}; +#[cfg(feature = "orbital")] use io::redraw::RedrawTask; use state::editor::Editor; +#[cfg(feature = "orbital")] use state::mode::Mode; #[cfg(feature = "orbital")] @@ -42,82 +44,86 @@ impl Editor { pub fn get_char(&mut self) -> char { #[cfg(feature = "orbital")] loop { - for event in self.window.events() { - match event.to_option(){ + for event in self.window.events() { + match event.to_option() { EventOption::Key(k) => { if let Some(Key::Char(c)) = self.key_state.feed(k) { self.status_bar.cmd.push(c); self.redraw_task = RedrawTask::StatusBar; return c; } - }, - _ => {}, + } + _ => {} } } } + #[cfg(not(feature = "orbital"))] + '\0' } /// Get the next instruction, i.e. the next input of a command together with a numeral /// parameter. pub fn get_inst(&mut self) -> Inst { - let mut n = 0; - let mut unset = true; + #[cfg(feature = "orbital")] + { + let mut n = 0; + let mut unset = true; - let mut key = Key::Null; - self.status_bar.cmd = String::new(); + let mut key = Key::Null; + self.status_bar.cmd = String::new(); - // self.status_bar.cmd = String::new(); - #[cfg(feature = "orbital")] - loop { - for event in self.window.events() { - match event.to_option() { - EventOption::Key(key_event) => { - if let Some(k) = self.key_state.feed(key_event) { - let c = k.to_char(); - self.status_bar.cmd.push(c); - self.redraw_status_bar(); + // self.status_bar.cmd = String::new(); + loop { + for event in self.window.events() { + match event.to_option() { + EventOption::Key(key_event) => { + if let Some(k) = self.key_state.feed(key_event) { + let c = k.to_char(); + self.status_bar.cmd.push(c); + self.redraw_status_bar(); - match self.cursor().mode { - Mode::Primitive(_) => { - key = k; - } - Mode::Command(_) => { - n = match c { - '0' ... '9' => { - unset = false; - n * 10 + ((c as u8) - b'0') as usize - } - _ => { + match self.cursor().mode { + Mode::Primitive(_) => { + key = k; + } + Mode::Command(_) => { + n = match c { + '0'...'9' => { + unset = false; + n * 10 + ((c as u8) - b'0') as usize + } + _ => { - key = k; - n - } - }; - } + key = k; + n + } + }; + } + } + } + match key { + Key::Null => {} + _ => { + return Inst(if unset { + Parameter::Null + } else { + Parameter::Int(n) + }, + Cmd { key: key }); + } } } - match key { - Key::Null => {}, - _ => { - return Inst( - if unset { - Parameter::Null - } else { - Parameter::Int(n) - }, - Cmd { key: key } - ); - }, + EventOption::Quit(_) => { + return Inst(Parameter::Null, Cmd { key: Key::Quit }); } - }, - EventOption::Quit(_) => { - return Inst(Parameter::Null, Cmd { key: Key::Quit }); - }, - _ => {}, + _ => {} + } } } } + #[cfg(not(feature = "orbital"))] + Inst(Parameter::Null, Cmd { key: Key::Null }) } }