summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-22 12:59:13 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-22 13:32:02 -0500
commit03594099dafb4cda04e50f087df61cf76e2034d0 (patch)
tree724d31c9b1d31d122d1862141fdc9391891821e4 /src/util
parentb3ed647b033c079a614e7a9ff5bb88da14dd99b4 (diff)
move the majority of rendering into its own widget: TuiView
- textfield is now a widget as well - reduced code duplication with TuiView - add backtab support - add a message queue for notifications
Diffstat (limited to 'src/util')
-rw-r--r--src/util/key_mapping.rs1
-rw-r--r--src/util/mod.rs1
-rw-r--r--src/util/textfield.rs114
3 files changed, 1 insertions, 115 deletions
diff --git a/src/util/key_mapping.rs b/src/util/key_mapping.rs
index c35fb50..4b0dbc3 100644
--- a/src/util/key_mapping.rs
+++ b/src/util/key_mapping.rs
@@ -7,6 +7,7 @@ pub fn str_to_key(s: &str) -> Option<Key> {
let key = match s {
"backspace" => Some(Key::Backspace),
+ "backtab" => Some(Key::BackTab),
"left" => Some(Key::Left),
"right" => Some(Key::Right),
"up" => Some(Key::Up),
diff --git a/src/util/mod.rs b/src/util/mod.rs
index 9519706..1ec901b 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -2,4 +2,3 @@ pub mod event;
pub mod format;
pub mod key_mapping;
pub mod load_child;
-pub mod textfield;
diff --git a/src/util/textfield.rs b/src/util/textfield.rs
deleted file mode 100644
index b8d9edd..0000000
--- a/src/util/textfield.rs
+++ /dev/null
@@ -1,114 +0,0 @@
-use std::io::{self, Write};
-
-use rustyline::completion::{Candidate, Completer, FilenameCompleter, Pair};
-use rustyline::line_buffer;
-
-use termion::clear;
-use termion::cursor::Goto;
-use termion::event::Key;
-use termion::input::TermRead;
-use termion::raw::IntoRawMode;
-use termion::screen::AlternateScreen;
-use tui::backend::{Backend, TermionBackend};
-use tui::layout::{Constraint, Direction, Layout, Rect};
-use tui::style::{Color, Style};
-use tui::widgets::{Block, Borders, List, Paragraph, Text, Widget};
-use tui::Terminal;
-use unicode_width::UnicodeWidthStr;
-
-use crate::ui::TuiBackend;
-use crate::util::event::{Event, Events};
-use crate::window;
-
-struct CompletionTracker {
- pub index: usize,
- pub pos: usize,
- pub original: String,
- pub candidates: Vec<Pair>,
-}
-
-impl CompletionTracker {
- pub fn new(pos: usize, candidates: Vec<Pair>, original: String) -> Self {
- CompletionTracker {
- index: 0,
- pos,
- original,
- candidates,
- }
- }
-}
-
-pub struct TextField<'a> {
- backend: &'a mut TuiBackend,
- events: &'a Events,
-}
-
-impl<'a> TextField<'a> {
- pub fn new(backend: &'a mut TuiBackend, events: &'a Events) -> Self {
- Self { backend, events }
- }
-
- pub fn readline(&mut self) -> Option<String> {
- let mut input_string = String::with_capacity(64);
- let events = self.events;
-
- // initially, clear the line for textfield and move the cursor there as well
- {
- let f_size = {
- let frame = self.backend.terminal.get_frame();
- frame.size()
- };
- let txt_y = f_size.height;
-
- let termion_terminal = self.backend.terminal.backend_mut();
-
- write!(termion_terminal, "{}{}", Goto(1, txt_y), clear::AfterCursor);
- }
-
- loop {
- let f_size = {
- let frame = self.backend.terminal.get_frame();
- frame.size()
- };
- let txt_y = f_size.height;
-
- let termion_terminal = self.backend.terminal.backend_mut();
-
- write!(termion_terminal, "{}", Goto(1, txt_y));
-
- write!(
- termion_terminal,
- "{}{}",
- input_string,
- Goto(1 + input_string.width() as u16, txt_y)
- );
-
- io::stdout().flush().ok();
-
- // Handle input
- if let Ok(event) = events.next() {
- match event {
- Event::Input(input) => match input {
- Key::Char('\n') => {
- break;
- }
- Key::Esc => {
- write!(termion_terminal, "{}{}", Goto(1, txt_y), clear::AfterCursor,);
- return None;
- }
- Key::Backspace => {
- input_string.pop();
- }
- Key::Char(c) => {
- input_string.push(c);
- }
- _ => {}
- },
- _ => {}
- }
- }
- }
- eprintln!("You typed: {}", input_string);
- Some(input_string)
- }
-}