summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-16 16:14:17 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-16 16:14:17 -0400
commitc6edd4e5d5cbcbc16063a10181aee9626822d273 (patch)
tree5524d52e5fb6f288be943c4882973dd1839a95f3 /src/ui
parent50f67156b783c3f533214ddfa8e79bd979d76278 (diff)
better error handling for threads
- code cleanup
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/widgets/tui_dirlist_detailed.rs3
-rw-r--r--src/ui/widgets/tui_menu.rs18
-rw-r--r--src/ui/widgets/tui_prompt.rs1
-rw-r--r--src/ui/widgets/tui_textfield.rs96
4 files changed, 60 insertions, 58 deletions
diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs
index e0e580c..54de784 100644
--- a/src/ui/widgets/tui_dirlist_detailed.rs
+++ b/src/ui/widgets/tui_dirlist_detailed.rs
@@ -2,7 +2,7 @@ use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Modifier, Style};
use tui::widgets::Widget;
-use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
+use unicode_width::UnicodeWidthStr;
use crate::fs::JoshutoDirList;
use crate::util::format;
@@ -32,7 +32,6 @@ impl<'a> Widget for TuiDirListDetailed<'a> {
let x = area.left();
let y = area.top();
- let dir_len = self.dirlist.contents.len();
let curr_index = match self.dirlist.index {
Some(i) => i,
None => {
diff --git a/src/ui/widgets/tui_menu.rs b/src/ui/widgets/tui_menu.rs
index 4088d6d..efa8d7d 100644
--- a/src/ui/widgets/tui_menu.rs
+++ b/src/ui/widgets/tui_menu.rs
@@ -80,17 +80,15 @@ impl TuiCommandMenu {
Event::Input(key) => {
match key {
Key::Esc => return None,
- key => {
- match map.get(&key) {
- Some(CommandKeybind::SimpleKeybind(s)) => {
- return Some(s);
- }
- Some(CommandKeybind::CompositeKeybind(m)) => {
- map = m;
- }
- None => return None,
+ key => match map.get(&key) {
+ Some(CommandKeybind::SimpleKeybind(s)) => {
+ return Some(s);
}
- }
+ Some(CommandKeybind::CompositeKeybind(m)) => {
+ map = m;
+ }
+ None => return None,
+ },
}
context.events.flush();
}
diff --git a/src/ui/widgets/tui_prompt.rs b/src/ui/widgets/tui_prompt.rs
index 1f4826f..b9848d0 100644
--- a/src/ui/widgets/tui_prompt.rs
+++ b/src/ui/widgets/tui_prompt.rs
@@ -2,7 +2,6 @@ use termion::event::Key;
use tui::layout::Rect;
use tui::style::{Color, Style};
use tui::widgets::{Paragraph, Text, Widget};
-use unicode_width::UnicodeWidthStr;
use crate::context::JoshutoContext;
use crate::ui::TuiBackend;
diff --git a/src/ui/widgets/tui_textfield.rs b/src/ui/widgets/tui_textfield.rs
index c663b95..c72bc9b 100644
--- a/src/ui/widgets/tui_textfield.rs
+++ b/src/ui/widgets/tui_textfield.rs
@@ -92,53 +92,55 @@ impl<'a> TuiTextField<'a> {
}
loop {
- terminal.draw(|mut frame| {
- let f_size = frame.size();
- if f_size.height == 0 {
- return;
- }
-
- {
- let mut view = TuiView::new(&context);
- view.show_bottom_status = false;
- view.render(&mut frame, f_size);
- }
-
- if let Some(menu) = self._menu.as_mut() {
- let menu_len = menu.len();
- let menu_y = if menu_len + 2 > f_size.height as usize {
- 0
- } else {
- (f_size.height as usize - menu_len - 2) as u16
- };
+ terminal
+ .draw(|mut frame| {
+ let f_size = frame.size();
+ if f_size.height == 0 {
+ return;
+ }
- let rect = Rect {
- x: 0,
- y: menu_y,
- width: f_size.width,
- height: menu_len as u16,
- };
- menu.render(&mut frame, rect);
- }
+ {
+ let mut view = TuiView::new(&context);
+ view.show_bottom_status = false;
+ view.render(&mut frame, f_size);
+ }
- let cmd_prompt_style = Style::default().fg(Color::LightGreen);
+ if let Some(menu) = self._menu.as_mut() {
+ let menu_len = menu.len();
+ let menu_y = if menu_len + 2 > f_size.height as usize {
+ 0
+ } else {
+ (f_size.height as usize - menu_len - 2) as u16
+ };
+
+ let rect = Rect {
+ x: 0,
+ y: menu_y,
+ width: f_size.width,
+ height: menu_len as u16,
+ };
+ menu.render(&mut frame, rect);
+ }
- let text = [
- Text::styled(self._prompt, cmd_prompt_style),
- Text::raw(line_buffer.as_str()),
- ];
+ let cmd_prompt_style = Style::default().fg(Color::LightGreen);
- let textfield_rect = Rect {
- x: 0,
- y: f_size.height - 1,
- width: f_size.width,
- height: 1,
- };
+ let text = [
+ Text::styled(self._prompt, cmd_prompt_style),
+ Text::raw(line_buffer.as_str()),
+ ];
- Paragraph::new(text.iter())
- .wrap(true)
- .render(&mut frame, textfield_rect);
- });
+ let textfield_rect = Rect {
+ x: 0,
+ y: f_size.height - 1,
+ width: f_size.width,
+ height: 1,
+ };
+
+ Paragraph::new(text.iter())
+ .wrap(true)
+ .render(&mut frame, textfield_rect);
+ })
+ .unwrap();
if let Ok(event) = context.events.next() {
match event {
@@ -180,8 +182,8 @@ impl<'a> TuiTextField<'a> {
}
Key::Char('\t') => {
if completion_tracker.is_none() {
- let res =
- completer.complete_path(line_buffer.as_str(), line_buffer.pos());
+ let res = completer
+ .complete_path(line_buffer.as_str(), line_buffer.pos());
if let Ok((pos, mut candidates)) = res {
candidates.sort_by(|x, y| {
x.display()
@@ -200,7 +202,11 @@ impl<'a> TuiTextField<'a> {
if let Some(ref mut s) = completion_tracker {
if s.index < s.candidates.len() {
let candidate = &s.candidates[s.index];
- completer.update(&mut line_buffer, s.pos, candidate.display());
+ completer.update(
+ &mut line_buffer,
+ s.pos,
+ candidate.display(),
+ );
s.index += 1;
}
}