summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-16 15:45:05 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-16 15:50:25 -0500
commit98d0ce7e70f9febf804cda7473f5e9f7f180fe91 (patch)
treec8c8dd60d9e6502202b910e64f79cd75b933d05d
parentd788f8d740be85bb014ddfa005156723f0a31e99 (diff)
remove ncurses dependency
- clean up code - update theme config - fix localstate tracking file selection not selecting proper files
-rw-r--r--Cargo.toml4
-rw-r--r--config/theme.toml167
-rw-r--r--src/commands/bulk_rename.rs2
-rw-r--r--src/commands/change_directory.rs5
-rw-r--r--src/commands/command_line.rs1
-rw-r--r--src/commands/cursor_move.rs28
-rw-r--r--src/commands/file_ops/copy.rs11
-rw-r--r--src/commands/file_ops/cut.rs11
-rw-r--r--src/commands/open_file.rs2
-rw-r--r--src/commands/parent_directory.rs9
-rw-r--r--src/commands/reload_dir.rs5
-rw-r--r--src/commands/rename_file.rs3
-rw-r--r--src/commands/search.rs17
-rw-r--r--src/config/keymap.rs119
-rw-r--r--src/config/mimetype.rs4
-rw-r--r--src/config/mod.rs4
-rw-r--r--src/config/theme.rs197
-rw-r--r--src/fs/entry.rs46
-rw-r--r--src/main.rs6
-rw-r--r--src/run.rs40
-rw-r--r--src/ui/mod.rs2
-rw-r--r--src/ui/ncurses_backend.rs464
-rw-r--r--src/ui/tui_backend.rs4
-rw-r--r--src/ui/widgets/tui_dirlist.rs7
-rw-r--r--src/util/event.rs4
-rw-r--r--src/util/load_child.rs5
-rw-r--r--src/util/menu.rs3
-rw-r--r--src/util/textfield.rs2
-rw-r--r--src/window/mod.rs2
-rw-r--r--src/window/panel.rs40
30 files changed, 305 insertions, 909 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 8c4addf..8d8696e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -40,10 +40,6 @@ xdg = "^2"
# whoami = "*"
# xdg = "*"
-[dependencies.ncurses]
-version = "5.99.0"
-features = [ "extended_colors", "panel", "wide" ]
-
[dependencies.wordexp]
version = "^0"
git = "https://github.com/kamiyaa/wordexp-rs"
diff --git a/config/theme.toml b/config/theme.toml
index ebd496f..58ebbb3 100644
--- a/config/theme.toml
+++ b/config/theme.toml
@@ -1,135 +1,76 @@
-# 0 -> black
-# 1 -> red
-# 2 -> green
-# 3 -> yellow
-# 4 -> blue
-# 5 -> magenta
-# 6 -> cyan
-# 7 -> white
-# -1 -> default (transparent)
-
-[[colorpair]]
-id = 1
-fg = 1
-bg = -1
-
-[[colorpair]]
-id = 2
-fg = 2
-bg = -1
-
-[[colorpair]]
-id = 3
-fg = 3
-bg = -1
-
-[[colorpair]]
-id = 4
-fg = 4
-bg = -1
-
-[[colorpair]]
-id = 5
-fg = 5
-bg = -1
-
-[[colorpair]]
-id = 6
-fg = 6
-bg = -1
-
-
[selection]
-colorpair = 3
+fg = "light_yellow"
bold = true
-underline = false
[selection.prefix]
prefix = " "
size = 2
[executable]
-colorpair = 2
+fg = "light_green"
bold = true
-underline = false
[regular]
-colorpair = 0
-bold = false
-underline = false
+fg = "white"
[directory]
-colorpair = 4
+fg = "light_blue"
bold = true
-underline = false
[link]
-colorpair = 6
+fg = "cyan"
bold = true
-underline = false
[socket]
-colorpair = 6
+fg = "cyan"
bold = true
-underline = false
[ext]
- [ext.jpg]
- colorpair = 3
-
- [ext.jpeg]
- colorpair = 3
-
- [ext.png]
- colorpair = 3
-
- [ext.svg]
- colorpair = 6
-
- [ext.gif]
- colorpair = 6
-
- [ext.wav]
- colorpair = 5
-
- [ext.flac]
- colorpair = 5
-
- [ext.mp3]
- colorpair = 5
-
- [ext.avi]
- colorpair = 5
-
- [ext.mp4]
- colorpair = 5
-
- [ext.mkv]
- colorpair = 5
-
- [ext.m4a]
- colorpair = 5
-
- [ext.ts]
- colorpair = 5
-
- [ext.webm]
- colorpair = 5
-
- [ext.wmv]
- colorpair = 5
-
- [ext.7z]
- colorpair = 1
-
- [ext.zip]
- colorpair = 1
-
- [ext.bz2]
- colorpair = 1
- [ext.gz]
- colorpair = 1
- [ext.xz]
- colorpair = 1
- [ext.rar]
- colorpair = 1
+[ext.bmp]
+fg = "yellow"
+[ext.jpg]
+fg = "yellow"
+[ext.jpeg]
+fg = "yellow"
+[ext.png]
+fg = "yellow"
+[ext.svg]
+fg = "yellow"
+[ext.gif]
+fg = "yellow"
+
+[ext.wav]
+fg = "magenta"
+[ext.flac]
+fg = "magenta"
+[ext.mp3]
+fg = "magenta"
+[ext.avi]
+fg = "magenta"
+[ext.m3u]
+fg = "magenta"
+[ext.mp4]
+fg = "magenta"
+[ext.mkv]
+fg = "magenta"
+[ext.m4a]
+fg = "magenta"
+[ext.ts]
+fg = "magenta"
+[ext.webm]
+fg = "magenta"
+[ext.wmv]
+fg = "magenta"
+
+[ext.7z]
+fg = "red"
+[ext.zip]
+fg = "red"
+[ext.bz2]
+fg = "red"
+[ext.gz]
+fg = "red"
+[ext.xz]
+fg = "red"
+[ext.rar]
+fg = "red"
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs
index c2e127f..9f67106 100644
--- a/src/commands/bulk_rename.rs
+++ b/src/commands/bulk_rename.rs
@@ -132,7 +132,7 @@ impl std::fmt::Display for BulkRename {
}
impl JoshutoRunnable for BulkRename {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
Self::bulk_rename(context)?;
ReloadDirList::reload(context.curr_tab_index, context)?;
Ok(())
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index 5f30c36..1897b90 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -32,7 +32,6 @@ impl ChangeDirectory {
pub fn change_directories(
path: &path::Path,
context: &mut JoshutoContext,
- backend: &mut TuiBackend,
) -> std::io::Result<()> {
Self::cd(path, context)?;
@@ -55,8 +54,8 @@ impl std::fmt::Display for ChangeDirectory {
impl JoshutoRunnable for ChangeDirectory {
fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
- Self::change_directories(&self.path, context, backend)?;
- LoadChild::load_child(context, backend);
+ Self::change_directories(&self.path, context)?;
+ LoadChild::load_child(context)?;
Ok(())
}
diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs
index 1ca2c14..5795e5d 100644
--- a/src/commands/command_line.rs
+++ b/src/commands/command_line.rs
@@ -56,7 +56,6 @@ impl std::fmt::Display for CommandLine {
impl JoshutoRunnable for CommandLine {
fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
let res = self.readline(context, backend);
- ncurses::doupdate();
res
}
}
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index 5fee941..a0b7522 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -6,14 +6,14 @@ use crate::error::JoshutoResult;
use crate::history::DirectoryHistory;
use crate::ui::TuiBackend;
-pub fn cursor_move(new_index: usize, context: &mut JoshutoContext, backend: &mut TuiBackend) {
+pub fn cursor_move(new_index: usize, context: &mut JoshutoContext) {
let mut new_index = new_index;
let curr_tab = &mut context.tabs[context.curr_tab_index];
let mut path: Option<PathBuf> = None;
if let Some(curr_list) = curr_tab.curr_list_mut() {
- if let Some(index) = curr_list.index {
+ if let Some(_) = curr_list.index {
let dir_len = curr_list.contents.len();
if new_index >= dir_len {
new_index = dir_len - 1;
@@ -58,14 +58,14 @@ impl std::fmt::Display for CursorMoveDown {
}
impl JoshutoRunnable for CursorMoveDown {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
let movement = match context.curr_tab_ref().curr_list_ref() {
Some(curr_list) => curr_list.index.map(|idx| idx + self.movement),
None => None,
};
if let Some(s) = movement {
- cursor_move(s, context, backend)
+ cursor_move(s, context)
}
Ok(())
}
@@ -94,7 +94,7 @@ impl std::fmt::Display for CursorMoveUp {
}
impl JoshutoRunnable for CursorMoveUp {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
let movement = match context.curr_tab_ref().curr_list_ref() {
Some(curr_list) => curr_list.index.map(|idx| {
if idx > self.movement {
@@ -107,7 +107,7 @@ impl JoshutoRunnable for CursorMoveUp {
};
if let Some(s) = movement {
- cursor_move(s, context, backend)
+ cursor_move(s, context)
}
Ok(())
}
@@ -134,7 +134,7 @@ impl std::fmt::Display for CursorMovePageUp {
}
impl JoshutoRunnable for CursorMovePageUp {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
let movement = match context.curr_tab_ref().curr_list_ref() {
Some(curr_list) => {
let half_page = 10;
@@ -146,7 +146,7 @@ impl JoshutoRunnable for CursorMovePageUp {
};
if let Some(s) = movement {
- cursor_move(s, context, backend);
+ cursor_move(s, context);
}
Ok(())
}
@@ -173,7 +173,7 @@ impl std::fmt::Display for CursorMovePageDown {
}
impl JoshutoRunnable for CursorMovePageDown {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
let movement = match context.curr_tab_ref().curr_list_ref() {
Some(curr_list) => {
let dir_len = curr_list.contents.len();
@@ -190,7 +190,7 @@ impl JoshutoRunnable for CursorMovePageDown {
};
if let Some(s) = movement {
- cursor_move(s, context, backend);
+ cursor_move(s, context);
}
Ok(())
}
@@ -217,7 +217,7 @@ impl std::fmt::Display for CursorMoveHome {
}
impl JoshutoRunnable for CursorMoveHome {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
let movement: Option<usize> = {
let len = context.curr_tab_mut().curr_list.contents.len();
if len == 0 {
@@ -228,7 +228,7 @@ impl JoshutoRunnable for CursorMoveHome {
};
if let Some(s) = movement {
- cursor_move(s, context, backend);
+ cursor_move(s, context);
}
Ok(())
}
@@ -255,7 +255,7 @@ impl std::fmt::Display for CursorMoveEnd {
}
impl JoshutoRunnable for CursorMoveEnd {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
let movement: Option<usize> = {
let len = context.curr_tab_mut().curr_list.contents.len();
if len == 0 {
@@ -266,7 +266,7 @@ impl JoshutoRunnable for CursorMoveEnd {
};
if let Some(s) = movement {
- cursor_move(s, context, backend);
+ cursor_move(s, context);
}
Ok(())
}
diff --git a/src/commands/file_ops/copy.rs b/src/commands/file_ops/copy.rs
index 2551321..a7edbef 100644
--- a/src/commands/file_ops/copy.rs
+++ b/src/commands/file_ops/copy.rs
@@ -28,9 +28,14 @@ impl std::fmt::Display for CopyFiles {
impl JoshutoRunnable for CopyFiles {
fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
let curr_tab = context.curr_tab_ref();
- LocalState::repopulated_selected_files(&curr_tab.curr_list)?;
- LocalState::set_file_op(FileOp::Copy);
- LocalState::set_tab_src(context.curr_tab_index);
+ match curr_tab.curr_list_ref() {
+ Some(list) => {
+ LocalState::repopulated_selected_files(list)?;
+ LocalState::set_file_op(FileOp::Copy);
+ LocalState::set_tab_src(context.curr_tab_index);
+ }
+ None => {}
+ }
Ok(())
}
}
diff --git a/src/commands/file_ops/cut.rs b/src/commands/file_ops/cut.rs
index d77f157..42ec7f2 100644
--- a/src/commands/file_ops/cut.rs
+++ b/src/commands/file_ops/cut.rs
@@ -28,9 +28,14 @@ impl std::fmt::Display for CutFiles {
impl JoshutoRunnable for CutFiles {
fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
let curr_tab = context.curr_tab_ref();
- LocalState::repopulated_selected_files(&curr_tab.curr_list)?;
- LocalState::set_file_op(FileOp::Cut);
- LocalState::set_tab_src(context.curr_tab_index);
+ match curr_tab.curr_list_ref() {
+ Some(list) => {
+ LocalState::repopulated_selected_files(list)?;
+ LocalState::set_file_op(FileOp::Cut);
+ LocalState::set_tab_src(context.curr_tab_index);
+ }
+ None => {}
+ }
Ok(())
}
}
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index 501eb67..4f29432 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -51,7 +51,7 @@ impl OpenFile {
}
if let Some(path) = dirpath {
ChangeDirectory::cd(path.as_path(), context)?;
- LoadChild::load_child(context, backend);
+ LoadChild::load_child(context)?;
} else if let Some(paths) = filepaths {
let options = Self::get_options(paths[0]);
if options.len() > 0 {
diff --git a/src/commands/parent_directory.rs b/src/commands/parent_directory.rs
index d7de010..6f654e9 100644
--- a/src/commands/parent_directory.rs
+++ b/src/commands/parent_directory.rs
@@ -14,10 +14,7 @@ impl ParentDirectory {
"parent_directory"
}
- pub fn parent_directory(
- context: &mut JoshutoContext,
- backend: &mut TuiBackend,
- ) -> std::io::Result<()> {
+ pub fn parent_directory(context: &mut JoshutoContext) -> std::io::Result<()> {
let curr_tab = &mut context.tabs[context.curr_tab_index];
if !curr_tab.curr_path.pop() {
return Ok(());
@@ -36,8 +33,8 @@ impl std::fmt::Display for ParentDirectory {
}
impl JoshutoRunnable for ParentDirectory {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
- Self::parent_directory(context, backend)?;
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
+ Self::parent_directory(context)?;
Ok(())
}
}
diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs
index 20d415b..7103970 100644
--- a/src/commands/reload_dir.rs
+++ b/src/commands/reload_dir.rs
@@ -1,9 +1,6 @@
-use std::collections::hash_map::Entry;
-
use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
-use crate::fs::JoshutoDirList;
use crate::ui::TuiBackend;
#[derive(Clone, Debug)]
@@ -35,7 +32,7 @@ impl std::fmt::Display for ReloadDirList {
}
impl JoshutoRunnable for ReloadDirList {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
Self::reload(context.curr_tab_index, context)?;
Ok(())
}
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index fd43e6d..ad2441c 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -58,7 +58,6 @@ impl JoshutoRunnable for RenameFile {
if let Some(path) = path {
self.rename_file(&path, context, backend)?;
- ncurses::doupdate();
}
Ok(())
}
@@ -113,7 +112,6 @@ impl JoshutoRunnable for RenameFileAppend {
if let Some(file_name) = file_name {
self.rename_file(context, backend, file_name)?;
- ncurses::doupdate();
}
Ok(())
}
@@ -161,7 +159,6 @@ impl JoshutoRunnable for RenameFilePrepend {
if let Some(file_name) = file_name {
self.rename_file(context, backend, file_name)?;
- ncurses::doupdate();
}
Ok(())
}
diff --git a/src/commands/search.rs b/src/commands/search.rs
index d1101bc..0b7ef76 100644
--- a/src/commands/search.rs
+++ b/src/commands/search.rs
@@ -66,10 +66,10 @@ impl std::fmt::Display for Search {
}
impl JoshutoRunnable for Search {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
let index = Self::search(&context.tabs[context.curr_tab_index], &self.pattern);
if let Some(index) = index {
- cursor_move::cursor_move(index, context, backend);
+ cursor_move::cursor_move(index, context);
}
let mut data = SEARCH_PATTERN.lock().unwrap();
match data.as_ref() {
@@ -80,23 +80,20 @@ impl JoshutoRunnable for Search {
}
None => *data = Some(self.pattern.clone()),
}
- ncurses::doupdate();
Ok(())
}
}
fn search_with_func(
context: &mut JoshutoContext,
- backend: &mut TuiBackend,
search_func: fn(&JoshutoTab, &str) -> Option<usize>,
) {
let data = SEARCH_PATTERN.lock().unwrap();
if let Some(s) = (*data).as_ref() {
let index = search_func(&context.tabs[context.curr_tab_index], s);
if let Some(index) = index {
- cursor_move::cursor_move(index, context, backend);
+ cursor_move::cursor_move(index, context);
}
- ncurses::doupdate();
}
}
@@ -121,8 +118,8 @@ impl std::fmt::Display for SearchNext {
}
impl JoshutoRunnable for SearchNext {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
- search_with_func(context, backend, Search::search);
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
+ search_with_func(context, Search::search);
Ok(())
}
}
@@ -148,8 +145,8 @@ impl std::fmt::Display for SearchPrev {
}
impl JoshutoRunnable for SearchPrev {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
- search_with_func(context, backend, Search::search_rev);
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
+ search_with_func(context, Search::search_rev);
Ok(())
}
}
diff --git a/src/config/keymap.rs b/src/config/keymap.rs
index 7d3713d..9262893 100644
--- a/src/config/keymap.rs
+++ b/src/config/keymap.rs
@@ -9,54 +9,8 @@ use crate::commands::{self, CommandKeybind, JoshutoCommand};
use crate::util::key_mapping::str_to_key;
use crate::KEYMAP_FILE;
-pub const ESCAPE: i32 = 0x1B;
-
pub type JoshutoCommandMapping = HashMap<Key, CommandKeybind>;
-const fn default_up() -> i32 {
- ncurses::KEY_UP
-}
-
-const fn default_down() -> i32 {
- ncurses::KEY_DOWN
-}
-
-const fn default_left() -> i32 {
- ncurses::KEY_LEFT
-}
-
-const fn default_right() -> i32 {
- ncurses::KEY_RIGHT
-}
-
-const fn default_home() -> i32 {
- ncurses::KEY_HOME
-}
-
-const fn default_end() -> i32 {
- ncurses::KEY_END
-}
-
-const fn default_backspace() -> i32 {
- ncurses::KEY_BACKSPACE
-}
-
-const fn default_delete() -> i32 {
- ncurses::KEY_DC
-}
-
-const fn default_enter() -> i32 {
- '\n' as i32
-}
-
-const fn default_escape() -> i32 {
- ESCAPE
-}
-
-const fn default_tab() -> i32 {
- '\t' as i32
-}
-
#[derive(Debug, Deserialize)]
struct JoshutoMapCommand {
pub command: String,
@@ -66,80 +20,7 @@ struct JoshutoMapCommand {
}
#[derive(Debug, Deserialize)]
-struct JoshutoRawKeymapping {
- #[serde(default)]
- keymaps: JoshutoKeyMapping,
- #[serde(skip)]
- mapcommand: Vec<JoshutoMapCommand>,
-}
-
-#[derive(Debug, Deserialize)]
-pub struct JoshutoKeyMapping {
- #[serde(default = "default_up")]
- pub up: i32,
- #[serde(default = "default_down")]
- pub down: i32,
- #[serde(default = "default_left")]
- pub left: i32,
- #[serde(default = "default_right")]
- pub right: i32,
- #[serde(default = "default_home")]
- pub home: i32,
- #[serde(default = "default_end")]
- pub end: i32,
- /*
- #[serde(default = "default_up")]
- pub page_up: i32,
- #[serde(default = "default_up")]
- pub page_down: i32,
- */
- #[serde(default = "default_backspace")]
- pub backspace: i32,
- #[serde(default = "default_delete")]
- pub delete: i32,
- #[serde(default = "default_enter")]
- pub enter: i32,
- #[serde(default = "default_escape")]
- pub escape: i32,
- #[serde(default = "default_tab")]
- pub tab: i32,
-}
-
-impl std::default::Default for JoshutoKeyMapping {
- fn default() -> Self {
- JoshutoKeyMapping {
- up: default_up(),
- down: default_down(),
- left: default_left(),
- right: default_right(),
- home: default_home(),
- end: default_end(),
- backspace: default_backspace(),
- delete: default_delete(),
- enter: default_enter(),
- escape: default_escape(),
- tab: default_tab(),
- }
- }
-}
-
-impl Flattenable<JoshutoKeyMapping> for JoshutoRawKeymapping {
- fn flatten(self) -> JoshutoKeyMapping {
- self.keymaps
- }
-}
-
-impl ConfigStructure for JoshutoKeyMapping {
- fn get_config() -> Self {
- parse_to_config_file::<JoshutoRawKeymapping, JoshutoKeyMapping>(KEYMAP_FILE)
- .unwrap_or_else(Self::default)
- }
-}
-
-#[derive(Debug, Deserialize)]
struct JoshutoRawCommandMapping {
- #[serde(skip)]
- keymaps: JoshutoKeyMapping,
#[serde(default)]
mapcommand: Vec<JoshutoMapCommand>,
}
diff --git a/src/config/mimetype.rs b/src/config/mimetype.rs
index c69d4df..507b165 100644
--- a/src/config/mimetype.rs
+++ b/src/config/mimetype.rs
@@ -102,15 +102,11 @@ impl JoshutoMimetypeEntry {
let mut handle = command.spawn()?;
if !self.get_fork() {
- ncurses::savetty();
- ncurses::endwin();
handle.wait()?;
if self.get_confirm_exit() {
println!(" --- Press ENTER to continue --- ");
std::io::stdin().bytes().next();
}
- ncurses::resetty();
- ncurses::refresh();
}
Ok(())
}
diff --git a/src/config/mod.rs b/src/config/mod.rs
index db15753..015089c 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -5,10 +5,10 @@ pub mod preview;
pub mod theme;
pub use self::config::JoshutoConfig;
-pub use self::keymap::{JoshutoCommandMapping, JoshutoKeyMapping};
+pub use self::keymap::JoshutoCommandMapping;
pub use self::mimetype::JoshutoMimetype;
pub use self::preview::{JoshutoPreview, JoshutoPreviewEntry};
-pub use self::theme::{JoshutoColorTheme, JoshutoTheme};
+pub use self::theme::{JoshutoStyleTheme, JoshutoTheme};
use serde::de::DeserializeOwned;
use std::fs;
diff --git a/src/config/theme.rs b/src/config/theme.rs
index 2de2882..9664acb 100644
--- a/src/config/theme.rs
+++ b/src/config/theme.rs
@@ -1,27 +1,17 @@
use serde_derive::Deserialize;
use std::collections::HashMap;
+use tui::style::Color;
+
use crate::THEME_FILE;
-use super::{parse_config_file, ConfigStructure};
+use super::{parse_to_config_file, ConfigStructure, Flattenable};
-const fn default_zero() -> i16 {
- 0
-}
-const fn default_false() -> bool {
- false
-}
const fn default_prefix() -> Option<JoshutoPrefix> {
None
}
-
-#[derive(Clone, Debug, Deserialize)]
-pub struct JoshutoColorPair {
- pub id: i16,
- #[serde(default = "default_zero")]
- pub fg: i16,
- #[serde(default = "default_zero")]
- pub bg: i16,
+const fn default_color() -> Color {
+ Color::Reset
}
#[derive(Clone, Debug, Deserialize)]
@@ -41,66 +31,185 @@ impl JoshutoPrefix {
}
#[derive(Clone, Debug, Deserialize)]
-pub struct JoshutoColorTheme {
- pub colorpair: i16,
- #[serde(default = "default_false")]
+pub struct JoshutoStyleThemeRaw {
+ #[serde(default)]
+ pub fg: String,
+ #[serde(default)]
+ pub bg: String,
+ #[serde(default)]
pub bold: bool,
- #[serde(default = "default_false")]
+ #[serde(default)]
pub underline: bool,
+ #[serde(default)]
+ pub invert: bool,
#[serde(default = "default_prefix")]
pub prefix: Option<JoshutoPrefix>,
}
-impl std::default::Default for JoshutoColorTheme {
+impl JoshutoStyleThemeRaw {
+ pub fn to_style_theme(&self) -> JoshutoStyleTheme {
+ let bg = Self::str_to_color(self.bg.as_str());
+ let fg = Self::str_to_color(self.fg.as_str());
+
+ JoshutoStyleTheme {
+ bg,
+ fg,
+ bold: self.bold,
+ underline: self.underline,
+ invert: self.invert,
+ prefix: self.prefix.clone(),
+ }
+ }
+
+ pub fn str_to_color(s: &str) -> Color {
+ match s {
+ "black" => Color::Black,
+ "red" => Color::Red,
+ "blue" => Color::Blue,
+ "green" => Color::Green,
+ "yellow" => Color::Yellow,
+ "magenta" => Color::Magenta,
+ "cyan" => Color::Cyan,
+ "white" => Color::White,
+ "gray" => Color::Gray,
+ "dark_gray" => Color::DarkGray,
+ "light_red" => Color::LightRed,
+ "light_green" => Color::LightGreen,
+ "light_yellow" => Color::LightYellow,
+ "light_blue" => Color::LightBlue,
+ "light_magenta" => Color::LightMagenta,
+ "light_cyan" => Color::LightCyan,
+ _ => Color::Reset,
+ }
+ }
+}
+
+impl std::default::Default for JoshutoStyleThemeRaw {
fn default() -> Self {
- JoshutoColorTheme {
- colorpair: default_zero(),
- bold: default_false(),
- underline: default_false(),
- prefix: default_prefix(),
+ Self {
+ bg: String::new(),
+ fg: String::new(),
+ bold: false,
+ underline: false,
+ invert: false,
+ prefix: None,
}
}
}
#[derive(Clone, Debug, Deserialize)]
-pub struct JoshutoTheme {
- #[serde(default)]
- pub colorpair: Vec&