Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiyaa committed Sep 11, 2022
1 parent 693a36b commit a264033
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 32 deletions.
1 change: 0 additions & 1 deletion lib/dizi_lib/src/request/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::path::PathBuf;
use std::time;

use serde_derive::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/client/event/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pub fn process_noninteractive(event: AppEvent, context: &mut AppContext) {

pub fn process_dir_preview(
context: &mut AppContext,
path: path::PathBuf,
_path: path::PathBuf,
res: io::Result<JoshutoDirList>,
) {
match res {
Expand Down
78 changes: 53 additions & 25 deletions src/client/key_command/constants.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,64 @@
pub const CMD_HELP: &str = "help";
use rustyline::completion::Pair;

pub const CMD_CLOSE: &str = "close";

pub const CMD_CHANGE_DIRECTORY: &str = "cd";
pub const CMD_COMMAND_LINE: &str = ":";

pub const CMD_CURSOR_MOVE_UP: &str = "cursor_move_up";
pub const CMD_CURSOR_MOVE_DOWN: &str = "cursor_move_down";
pub const CMD_CURSOR_MOVE_HOME: &str = "cursor_move_home";
pub const CMD_CURSOR_MOVE_END: &str = "cursor_move_end";
pub const CMD_CURSOR_MOVE_PAGEUP: &str = "cursor_move_page_up";
pub const CMD_CURSOR_MOVE_PAGEDOWN: &str = "cursor_move_page_down";
macro_rules! cmd_constants {
($( ($cmd_name:ident, $cmd_value:literal), )*) => {
$(
pub const $cmd_name: &str = $cmd_value;
)*

pub fn commands() -> Vec<&'static str> {
vec![$($cmd_value,)*]
}
};
}

cmd_constants![
(CMD_CLOSE, "close"),

(CMD_CHANGE_DIRECTORY, "cd"),

(CMD_CURSOR_MOVE_UP, "cursor_move_up"),
(CMD_CURSOR_MOVE_DOWN, "cursor_move_down"),
(CMD_CURSOR_MOVE_HOME, "cursor_move_home"),
(CMD_CURSOR_MOVE_END, "cursor_move_end"),
(CMD_CURSOR_MOVE_PAGEUP, "cursor_move_page_up"),
(CMD_CURSOR_MOVE_PAGEDOWN, "cursor_move_page_down"),

(CMD_GO_TO_PLAYING, "go_to_playing"),

(CMD_OPEN_FILE, "open"),

(CMD_PARENT_DIRECTORY, "cd .."),
(CMD_RELOAD_DIRECTORY_LIST, "reload_dirlist"),

pub const CMD_GO_TO_PLAYING: &str = "go_to_playing";
(CMD_SEARCH_STRING, "search"),
(CMD_SEARCH_GLOB, "search_glob"),
(CMD_SEARCH_SKIM, "search_skim"),
(CMD_SEARCH_NEXT, "search_next"),
(CMD_SEARCH_PREV, "search_prev"),

pub const CMD_OPEN_FILE: &str = "open";
(CMD_SELECT_FILES, "select"),

pub const CMD_PARENT_DIRECTORY: &str = "cd ..";
pub const CMD_RELOAD_DIRECTORY_LIST: &str = "reload_dirlist";
(CMD_SERVER_REQUEST, "server_request"),

pub const CMD_SEARCH_STRING: &str = "search";
pub const CMD_SEARCH_GLOB: &str = "search_glob";
pub const CMD_SEARCH_SKIM: &str = "search_skim";
pub const CMD_SEARCH_NEXT: &str = "search_next";
pub const CMD_SEARCH_PREV: &str = "search_prev";
(CMD_SORT, "sort"),
(CMD_SORT_REVERSE, "sort reverse"),

pub const CMD_SELECT_FILES: &str = "select";
(CMD_TOGGLE_HIDDEN, "toggle_hidden"),
(CMD_TOGGLE_VIEW, "toggle_view"),
];

pub const CMD_SERVER_REQUEST: &str = "server_request";

pub const CMD_SORT: &str = "sort";
pub const CMD_SORT_REVERSE: &str = "sort reverse";

pub const CMD_TOGGLE_HIDDEN: &str = "toggle_hidden";
pub const CMD_TOGGLE_VIEW: &str = "toggle_view";
pub fn complete_command(partial_command: &str) -> Vec<Pair> {
commands()
.into_iter()
.filter(|command| command.starts_with(partial_command))
.map(|command| Pair {
display: command.to_string(),
replacement: command.to_string(),
})
.collect()
}
19 changes: 16 additions & 3 deletions src/client/ui/views/tui_textfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use unicode_width::UnicodeWidthStr;
use crate::context::AppContext;
use crate::event::process_event;
use crate::event::AppEvent;
use crate::key_command::Command;
use crate::key_command::{complete_command};
use crate::ui::views::TuiView;
use crate::ui::widgets::{TuiMenu, TuiMultilineText};
use crate::ui::AppBackend;
Expand Down Expand Up @@ -260,7 +260,9 @@ impl<'a> TuiTextField<'a> {
Key::Char('\n') => {
break;
}
Key::Char(c) => line_buffer.insert(c, 1).is_some(),
Key::Char(c) => {
line_buffer.insert(c, 1).is_some()
}
_ => false,
};
if dirty {
Expand Down Expand Up @@ -370,6 +372,17 @@ fn get_candidates(
line_buffer: &mut LineBuffer,
) -> Option<(usize, Vec<Pair>)> {
let line = line_buffer.as_str().split_once(' ');
let res = completer.complete_path(line_buffer.as_str(), line_buffer.pos());
let res = match line {
None => Ok((0, complete_command(line_buffer.as_str()))),

Some((command, _files)) => {
// We want to autocomplete a command if we are inside it.
if line_buffer.pos() <= command.len() {
Ok((0, complete_command(command)))
} else {
completer.complete_path(line_buffer.as_str(), line_buffer.pos())
}
}
};
res.ok()
}
4 changes: 2 additions & 2 deletions src/server/audio/symphonia/stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;
use std::sync::mpsc;
use std::thread::{self, JoinHandle};
use std::time::{Duration, SystemTime};
use std::thread;
use std::time::Duration;

use log::{debug, log_enabled, Level};
use symphonia::core::codecs::{DecoderOptions, CODEC_TYPE_NULL};
Expand Down

0 comments on commit a264033

Please sign in to comment.