From a1ad41247d8c06e853d54e41e72b089d0587308e Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Tue, 21 Jan 2020 15:51:43 -0800 Subject: [PATCH] resolve clippy issues and fix cursor character issue --- src/bridge/mod.rs | 9 ++- src/bridge/ui_commands.rs | 2 - src/editor/command_line.rs | 109 -------------------------------- src/editor/mod.rs | 28 +------- src/renderer/caching_shaper.rs | 12 ++-- src/renderer/cursor_renderer.rs | 5 +- src/renderer/fonts.rs | 7 +- 7 files changed, 15 insertions(+), 157 deletions(-) delete mode 100644 src/editor/command_line.rs diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index 41a2976..2922bd9 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -91,7 +91,7 @@ async fn start_process(editor: Arc>, mut receiver: UnboundedReceiv } pub struct Bridge { - runtime: Runtime, + _runtime: Runtime, sender: UnboundedSender } @@ -104,10 +104,13 @@ impl Bridge { start_process(editor, receiver, grid_dimensions).await; }); - Bridge { runtime, sender } + Bridge { _runtime: runtime, sender } } pub fn queue_command(&mut self, command: UiCommand) { - self.sender.send(command); + self.sender.send(command) + .unwrap_or_explained_panic( + "Could Not Send UI Command", + "Could not send UI command from the window system to the neovim process."); } } diff --git a/src/bridge/ui_commands.rs b/src/bridge/ui_commands.rs index 580ddfa..b665fe7 100644 --- a/src/bridge/ui_commands.rs +++ b/src/bridge/ui_commands.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use nvim_rs::Neovim; use nvim_rs::compat::tokio::Compat; use tokio::process::ChildStdin; diff --git a/src/editor/command_line.rs b/src/editor/command_line.rs deleted file mode 100644 index ebbbe64..0000000 --- a/src/editor/command_line.rs +++ /dev/null @@ -1,109 +0,0 @@ -use std::collections::HashMap; - -use crate::bridge::{RedrawEvent, StyledContent}; -use crate::editor::{DrawCommand, Style}; - -const COMMAND_SCALE: u16 = 2; - -pub struct CommandLine { - visible: bool, - prefix: String, - content: StyledContent, - cursor_position: u64, - special_char: Option<(String, bool)>, - block: Vec -} - -impl CommandLine { - pub fn new() -> CommandLine { - CommandLine { - visible: false, - prefix: String::new(), - content: Vec::new(), - cursor_position: 0, - special_char: None, - block: Vec::new() - } - } - - pub fn draw(&self, window_size: (u64, u64), defined_styles: &HashMap) -> Vec { - let mut draw_commands = Vec::new(); - if self.visible { - if self.content.len() > 0 { - let (width, height) = window_size; - let text_length: usize = self.content.iter().map(|(_, text)| text.len()).sum(); - - let text_width = text_length * COMMAND_SCALE as usize; - let text_height = COMMAND_SCALE; - - let x = (width / 2) - (text_width as u64 / 2); - let y = (height / 2) - (text_height as u64 / 2); - - let mut start_x = x; - let mut commands = self.content.iter().map(|(style_id, text)| { - let command_width = text.len() * 2; - let style = defined_styles.get(style_id).map(|style| style.clone()); - let mut command = DrawCommand::new(text.clone(), (start_x, y), style); - command.scale = COMMAND_SCALE; - start_x = start_x + command_width as u64; - command - }).collect::>(); - draw_commands.append(&mut commands); - } - } - draw_commands - } - - pub fn handle_command_events(&mut self, event: RedrawEvent) { - match event { - RedrawEvent::CommandLineShow { content, position, first_character, prompt, indent, level } => self.show(content, position, first_character, prompt, indent, level), - RedrawEvent::CommandLinePosition { position, level } => self.set_position(position, level), - RedrawEvent::CommandLineSpecialCharacter { character, shift, level } => self.set_special_character(character, shift, level), - RedrawEvent::CommandLineHide => self.hide(), - RedrawEvent::CommandLineBlockShow { lines } => self.show_block(lines), - RedrawEvent::CommandLineBlockAppend { line } => self.append_line_to_block(line), - RedrawEvent::CommandLineBlockHide => self.hide_block(), - _ => {} - } - } - - fn show(&mut self, content: StyledContent, position: u64, first_character: String, prompt: String, _indent: u64, _level: u64) { - let prefix; - if first_character.len() > 0 { - prefix = first_character; - } else { - prefix = prompt; - } - - self.visible = true; - self.prefix = prefix; - self.content = content; - self.cursor_position = position; - self.block = Vec::new(); - } - - fn set_position(&mut self, position: u64, _level: u64) { - self.cursor_position = position; - } - - fn set_special_character(&mut self, character: String, shift: bool, _level: u64) { - self.special_char = Some((character, shift)); - } - - fn hide(&mut self) { - self.visible = false; - self.special_char = None; - } - - fn show_block(&mut self, lines: Vec) { - self.block = lines; - } - - fn append_line_to_block(&mut self, line: StyledContent) { - self.block.push(line); - } - - fn hide_block(&mut self) { - self.block.clear(); - } -} diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 6d16ba9..0ec8d80 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -1,6 +1,5 @@ mod cursor; mod style; -mod command_line; use std::collections::HashMap; use std::sync::Arc; @@ -10,7 +9,6 @@ use skulpin::winit::window::Window; pub use cursor::{Cursor, CursorShape, CursorMode}; pub use style::{Colors, Style}; -use command_line::CommandLine; use crate::bridge::{GridLineCell, GuiOption, RedrawEvent}; pub type GridCell = Option<(char, Option