summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-13 08:12:05 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-13 08:16:27 -0500
commit89b08eb9905db22a3e9751f44440d22e114277a3 (patch)
treeb5b858192aabf020aea039061d607e171cc3fb7b /src
parent6042557a5e88601cb37b6067a5fdb547f6aca232 (diff)
textfield progression
Diffstat (limited to 'src')
-rw-r--r--src/commands/change_directory.rs12
-rw-r--r--src/commands/command_line.rs11
-rw-r--r--src/textfield.rs51
3 files changed, 43 insertions, 31 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index 48cf901..cd761c9 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -19,10 +19,7 @@ impl ChangeDirectory {
"cd"
}
- pub fn cd(
- path: &path::Path,
- context: &mut JoshutoContext,
- ) -> std::io::Result<()> {
+ pub fn cd(path: &path::Path, context: &mut JoshutoContext) -> std::io::Result<()> {
std::env::set_current_dir(path)?;
let curr_tab = &mut context.tabs[context.curr_tab_index];
@@ -31,14 +28,17 @@ impl ChangeDirectory {
Ok(())
}
- pub fn change_directories(path: &path::Path,
+ pub fn change_directories(
+ path: &path::Path,
context: &mut JoshutoContext,
backend: &mut TuiBackend,
) -> std::io::Result<()> {
Self::cd(path, context)?;
let curr_tab = &mut context.tabs[context.curr_tab_index];
- curr_tab.history.populate_to_root(&path, &context.config_t.sort_option)?;
+ curr_tab
+ .history
+ .populate_to_root(&path, &context.config_t.sort_option)?;
Ok(())
}
diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs
index 5f5b9db..4d3c820 100644
--- a/src/commands/command_line.rs
+++ b/src/commands/command_line.rs
@@ -2,7 +2,6 @@ use crate::commands::{self, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::textfield::TextField;
-use crate::ui;
use crate::ui::TuiBackend;
#[derive(Clone, Debug)]
@@ -24,18 +23,18 @@ impl CommandLine {
context: &mut JoshutoContext,
backend: &mut TuiBackend,
) -> JoshutoResult<()> {
- // let mut textfield =
- let mut textfield = TextField::new(backend, &context.events);
- let user_input: Option<String> = None; //textfield.readline();
+ let mut textfield = TextField::new(backend, &context.events);
+ let user_input: Option<String> = textfield.readline();
if let Some(s) = user_input {
let trimmed = s.trim_start();
match trimmed.find(' ') {
Some(ind) => {
- let (command, xs) = trimmed.split_at(ind);
+ let (cmd, xs) = trimmed.split_at(ind);
let xs = xs.trim_start();
let args: Vec<String> = vec![String::from(xs)];
- commands::from_args(String::from(command), args)?.execute(context, backend)
+ let command = commands::from_args(cmd.to_string(), args)?;
+ command.execute(context, backend)
}
None => commands::from_args(String::from(trimmed), Vec::new())?
.execute(context, backend),
diff --git a/src/textfield.rs b/src/textfield.rs
index 5ee06ec..675bdbf 100644
--- a/src/textfield.rs
+++ b/src/textfield.rs
@@ -3,6 +3,7 @@ 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;
@@ -15,8 +16,8 @@ use tui::widgets::{Block, Borders, List, Paragraph, Text, Widget};
use tui::Terminal;
use unicode_width::UnicodeWidthStr;
-use crate::util::event::{Event, Events};
use crate::ui::TuiBackend;
+use crate::util::event::{Event, Events};
use crate::window;
use crate::KEYMAP_T;
@@ -57,28 +58,39 @@ impl<'a> TextField<'a> {
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));
+ write!(termion_terminal, "{}{}", Goto(1, txt_y), clear::AfterCursor,);
+ }
+
loop {
- // Draw UI
- self.backend.terminal.draw(|mut f| {
- let f_size = f.size();
- Paragraph::new([Text::raw(&input_string)].iter())
- .style(Style::default().fg(Color::Yellow))
- .render(
- &mut f,
- Rect {
- x: 0,
- y: 0,
- height: 2,
- width: f_size.width,
- },
- );
- });
+ 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!(
- self.backend.terminal.backend_mut(),
- "{}",
- Goto(4 + input_string.width() as u16, 5)
+ termion_terminal,
+ "{}{}",
+ input_string,
+ Goto(1 + input_string.width() as u16, txt_y)
);
+
io::stdout().flush().ok();
// Handle input
@@ -89,6 +101,7 @@ impl<'a> TextField<'a> {
break;
}
Key::Esc => {
+ write!(termion_terminal, "{}{}", Goto(1, txt_y), clear::AfterCursor,);
return None;
}
Key::Backspace => {