summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-02 11:54:56 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-02 11:54:56 -0500
commit0f4d1c5f1ad0b8b1ae5309f2f005601c78df8487 (patch)
treee4644250331db5efceea059a34f547fbb77adde6
parentabec069c233b5bf6f582882851430b3a5949b22b (diff)
parent6b84901e50bfc0052fd93daed4b5b742db96447d (diff)
Merge branch 'dev' of github.com:kamiyaa/joshuto into dev
-rw-r--r--src/commands/delete_files.rs8
-rw-r--r--src/commands/open_file.rs78
-rw-r--r--src/config/theme.rs46
-rw-r--r--src/context.rs2
-rw-r--r--src/run.rs7
-rw-r--r--src/ui/widgets/tui_textfield.rs4
6 files changed, 99 insertions, 46 deletions
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index 78344d1..d89a17d 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -52,19 +52,19 @@ impl DeleteFiles {
}
let ch = {
- let prompt_str = format!("Delete {} files? (y/N)", paths_len);
+ let prompt_str = format!("Delete {} files? (Y/n)", paths_len);
let mut prompt = TuiPrompt::new(&prompt_str);
prompt.get_key(backend, &context)
};
- if ch == Key::Char('y') {
+ if ch == Key::Char('y') || ch == Key::Char('\n') {
if paths_len > 1 {
let ch = {
- let prompt_str = "Are you sure? (Y/n)";
+ let prompt_str = "Are you sure? (y/N)";
let mut prompt = TuiPrompt::new(prompt_str);
prompt.get_key(backend, &context)
};
- if ch == Key::Char('y') || ch == Key::Char('\n') {
+ if ch == Key::Char('y') {
Self::remove_files(&paths)?;
ReloadDirList::reload(context.curr_tab_index, context)?;
let msg = format!("Deleted {} files", paths_len);
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index 2a900e0..405a286 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -5,7 +5,7 @@ use crate::config::mimetype::JoshutoMimetypeEntry;
use crate::context::JoshutoContext;
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::history::DirectoryHistory;
-use crate::ui::widgets::TuiTextField;
+use crate::ui::widgets::{TuiMenu, TuiTextField};
use crate::ui::TuiBackend;
use crate::util::load_child::LoadChild;
@@ -92,42 +92,68 @@ impl OpenFileWith {
}
pub fn open_with(context: &JoshutoContext, backend: &mut TuiBackend, paths: &[&PathBuf]) -> std::io::Result<()> {
+ const PROMPT: &'static str = "open_with ";
+
let mimetype_options: Vec<&JoshutoMimetypeEntry> = OpenFile::get_options(&paths[0]);
- let mut textfield = TuiTextField::default()
- .prompt(":")
- .prefix("open_with ");
- let user_input: Option<String> = textfield.get_input(backend, &context);
+ let user_input: Option<String> = {
+ let menu_options: Vec<String> = mimetype_options
+ .iter()
+ .enumerate()
+ .map(|(i, e)| format!(" {} | {}", i, e))
+ .collect();
+ let menu_options_str: Vec<&str> = menu_options
+ .iter()
+ .map(|e| e.as_str())
+ .collect();
+ let mut menu_widget = TuiMenu::new(&menu_options_str);
+
+ let mut textfield = TuiTextField::default()
+ .prompt(":")
+ .prefix(PROMPT)
+ .menu(&mut menu_widget);
+ textfield.get_input(backend, &context)
+ };
match user_input.as_ref() {
- None => Ok(()),
- Some(user_input) => match user_input.parse::<usize>() {
- Ok(n) if n >= mimetype_options.len() => Err(std::io::Error::new(
- std::io::ErrorKind::InvalidData,
- "option does not exist".to_owned(),
- )),
- Ok(n) => {
- backend.terminal_drop();
- let res = mimetype_options[n].execute_with(paths);
- backend.terminal_restore()?;
- res
- }
- Err(_) => {
- let mut args_iter = user_input.split_whitespace();
- args_iter.next();
- match args_iter.next() {
- Some(cmd) => {
+ Some(user_input) if user_input.starts_with(PROMPT) => {
+ let user_input = &user_input[PROMPT.len()..];
+
+ match user_input.parse::<usize>() {
+ Ok(n) if n >= mimetype_options.len() => Err(std::io::Error::new(
+ std::io::ErrorKind::InvalidData,
+ "option does not exist".to_owned(),
+ )),
+ Ok(n) => {
+
+ let mimetype_entry = &mimetype_options[n];
+ if mimetype_entry.get_fork() {
+ mimetype_entry.execute_with(paths)
+ } else {
backend.terminal_drop();
- let res = JoshutoMimetypeEntry::new(String::from(cmd))
- .args(args_iter)
- .execute_with(paths);
+ let res = mimetype_entry.execute_with(paths);
backend.terminal_restore()?;
res
}
- None => Ok(()),
+ }
+ Err(_) => {
+ let mut args_iter = user_input.split_whitespace();
+ args_iter.next();
+ match args_iter.next() {
+ Some(cmd) => {
+ backend.terminal_drop();
+ let res = JoshutoMimetypeEntry::new(String::from(cmd))
+ .args(args_iter)
+ .execute_with(paths);
+ backend.terminal_restore()?;
+ res
+ }
+ None => Ok(()),
+ }
}
}
}
+ _ => Ok(()),
}
}
}
diff --git a/src/config/theme.rs b/src/config/theme.rs
index 9664acb..ddbd882 100644
--- a/src/config/theme.rs
+++ b/src/config/theme.rs
@@ -168,6 +168,29 @@ pub struct JoshutoStyleTheme {
pub prefix: Option<JoshutoPrefix>,
}
+impl JoshutoStyleTheme {
+ pub fn set_bg(mut self, bg: Color) -> Self {
+ self.bg = bg;
+ self
+ }
+ pub fn set_fg(mut self, fg: Color) -> Self {
+ self.fg = fg;
+ self
+ }
+ pub fn set_bold(mut self, bold: bool) -> Self {
+ self.bold = bold;
+ self
+ }
+ pub fn set_underline(mut self, bold: bool) -> Self {
+ self.bold = bold;
+ self
+ }
+ pub fn set_invert(mut self, bold: bool) -> Self {
+ self.bold = bold;
+ self
+ }
+}
+
impl std::default::Default for JoshutoStyleTheme {
fn default() -> Self {
JoshutoStyleTheme {
@@ -201,12 +224,23 @@ impl ConfigStructure for JoshutoTheme {
impl std::default::Default for JoshutoTheme {
fn default() -> Self {
- let selection = JoshutoStyleTheme::default();
- let executable = JoshutoStyleTheme::default();
- let regular = JoshutoStyleTheme::default();
- let directory = JoshutoStyleTheme::default();
- let link = JoshutoStyleTheme::default();
- let socket = JoshutoStyleTheme::default();
+ let selection = JoshutoStyleTheme::default()
+ .set_fg(Color::LightYellow)
+ .set_bold(true);
+ let executable = JoshutoStyleTheme::default()
+ .set_fg(Color::LightGreen)
+ .set_bold(true);
+ let regular = JoshutoStyleTheme::default()
+ .set_fg(Color::White);
+ let directory = JoshutoStyleTheme::default()
+ .set_fg(Color::LightBlue)
+ .set_bold(true);
+ let link = JoshutoStyleTheme::default()
+ .set_fg(Color::LightCyan)
+ .set_bold(true);
+ let socket = JoshutoStyleTheme::default()
+ .set_fg(Color::LightMagenta)
+ .set_bold(true);
let ext = HashMap::new();
JoshutoTheme {
diff --git a/src/context.rs b/src/context.rs
index 149a868..56dcc89 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -16,7 +16,6 @@ pub struct JoshutoContext {
pub worker_msg: Option<String>,
pub message_queue: VecDeque<String>,
- pub message_elapse: usize,
pub events: Events,
pub config_t: config::JoshutoConfig,
@@ -31,7 +30,6 @@ impl JoshutoContext {
worker_queue: VecDeque::with_capacity(10),
worker_msg: None,
message_queue: VecDeque::with_capacity(4),
- message_elapse: 0,
events: Events::new(),
config_t,
diff --git a/src/run.rs b/src/run.rs
index bb33c65..0b9913c 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -71,12 +71,7 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io:
Event::Input(key) => {
/* Message handling */
if !context.message_queue.is_empty() {
- if context.message_elapse < MESSAGE_VISIBLE_DURATION {
- context.message_elapse += 1;
- } else {
- let _ = context.message_queue.pop_front();
- context.message_elapse = 0;
- }
+ let _ = context.message_queue.pop_front();
}
match keymap_t.get(&key) {
None => {
diff --git a/src/ui/widgets/tui_textfield.rs b/src/ui/widgets/tui_textfield.rs
index 6d89b14..f1e9cc7 100644
--- a/src/ui/widgets/tui_textfield.rs
+++ b/src/ui/widgets/tui_textfield.rs
@@ -109,10 +109,10 @@ impl<'a> TuiTextField<'a> {
if let Some(menu) = self._menu.as_mut() {
let menu_len = menu.len();
- let menu_y = if menu_len + 1 > f_size.height as usize {
+ let menu_y = if menu_len + 2 > f_size.height as usize {
0
} else {
- (f_size.height as usize - menu_len - 1) as u16
+ (f_size.height as usize - menu_len - 2) as u16
};
let rect = Rect {