Skip to content

Commit

Permalink
rework io workers
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiyaa committed Jul 7, 2024
1 parent 6797743 commit 073a61e
Show file tree
Hide file tree
Showing 66 changed files with 994 additions and 1,108 deletions.
2 changes: 1 addition & 1 deletion src/commands/cursor_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn to_path(app_state: &mut AppState, path: &path::Path) -> AppResult {
{
if let path::Component::Normal(name) = path.components().next().ok_or_else(err)? {
let index = curr_list.get_index_from_name(name.to_str().ok_or_else(err)?);
curr_list.set_index(index, &ui_state, &display_options);
curr_list.set_index(index, &ui_state, display_options);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/delete_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::sync::mpsc;
use termion::event::Key;

use crate::error::{AppError, AppErrorKind, AppResult};
use crate::io::{FileOperation, FileOperationOptions, IoWorkerThread};
use crate::types::state::AppState;
use crate::ui::widgets::TuiPrompt;
use crate::ui::AppBackend;
use crate::workers::io::{FileOperation, FileOperationOptions, IoWorkerThread};

use super::tab_ops;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/file_ops.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::process::{Command, Stdio};

use crate::error::{AppError, AppErrorKind, AppResult};
use crate::io::{FileOperation, FileOperationOptions, IoWorkerThread};
use crate::types::state::{AppState, LocalStateState};
use crate::workers::io::{FileOperation, FileOperationOptions, IoWorkerThread};

fn new_local_state(app_state: &mut AppState, file_op: FileOperation) -> Option<()> {
let list = app_state
Expand Down
8 changes: 2 additions & 6 deletions src/commands/open_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ where
{
if option.get_fork() {
let (child_id, handle) = fork_execute(option, files, app_state.clone_event_tx())?;
app_state
.state
.worker_state_mut()
.push_child(child_id, handle);
app_state.state.thread_pool.push_child(child_id, handle);
} else {
backend.terminal_drop();
let res = execute_and_wait(option, files);
Expand Down Expand Up @@ -246,10 +243,9 @@ pub fn open_with_interactive(app_state: &mut AppState, backend: &mut AppBackend)
.curr_tab_ref()
.curr_list_ref()
.and_then(|s| s.curr_entry_ref())
.map(|s| s.clone())
{
Some(entry) => {
paths.push(entry);
paths.push(entry.clone());
}
None => {
let err = AppError::new(AppErrorKind::Io, "No files selected".to_string());
Expand Down
3 changes: 1 addition & 2 deletions src/commands/tab_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use crate::error::{AppError, AppErrorKind, AppResult};
use crate::history::{
create_dirlist_with_history, generate_entries_to_root, DirectoryHistory, JoshutoHistory,
};
use crate::tab::{JoshutoTab, TabHomePage};
use crate::types::option::tab::NewTabMode;
use crate::tab::{JoshutoTab, NewTabMode, TabHomePage};
use crate::types::state::AppState;
use crate::utils::{cwd, unix};

Expand Down
2 changes: 1 addition & 1 deletion src/config/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl From<AppConfigRaw> for AppConfig {
zoxide_update: raw.zoxide_update,
display_options: DisplayOption::from(raw.display_options),
preview_options: PreviewOption::from(raw.preview_options),
search_options: SearchOption::from(raw.search_options),
search_options: raw.search_options,
tab_options: TabOption::from(raw.tab_options),
custom_commands: raw.custom_commands,
}
Expand Down
39 changes: 37 additions & 2 deletions src/config/preview/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
pub mod preview;
pub mod preview_option_raw;
pub mod preview_raw;

use std::collections::HashMap;

use crate::{
error::{AppError, AppErrorKind, AppResult},
preview::preview_entry::FileEntryPreviewEntry,
traits::config::search_config_directories,
types::config_type::ConfigType,
};

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct FileEntryPreview {
#[serde(default)]
pub extension: HashMap<String, FileEntryPreviewEntry>,
#[serde(default)]
pub mimetype: HashMap<String, FileEntryPreviewEntry>,
}

impl FileEntryPreview {
pub fn from_toml_str(s: &str) -> AppResult<Self> {
let res = toml::from_str(s)?;
Ok(res)
}

pub fn get_config() -> AppResult<Self> {
let file_path = search_config_directories(ConfigType::Preview.as_filename())
.ok_or_else(|| AppError::new(AppErrorKind::Config, "Cannot find config".to_string()))?;
let file_contents = std::fs::read_to_string(file_path)?;
Self::from_toml_str(&file_contents)
}

pub fn get_config_or_default() -> Self {
Self::get_config().unwrap_or_default()
}
}
39 changes: 0 additions & 39 deletions src/config/preview/preview.rs

This file was deleted.

8 changes: 1 addition & 7 deletions src/config/preview/preview_option_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ use toml::Value;

use crate::types::option::preview::{PreviewProtocol, XDGThumbSizes};

pub const fn default_max_preview_size() -> u64 {
2 * 1024 * 1024 // 2 MB
}

pub const fn default_true() -> bool {
true
}
use crate::utils::serde::{default_max_preview_size, default_true};

#[derive(Clone, Debug, Deserialize)]
pub struct PreviewOptionRaw {
Expand Down
11 changes: 0 additions & 11 deletions src/config/preview/preview_raw.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/config/sort_option_raw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::Deserialize;

use super::preview::preview_option_raw::default_true;
use crate::utils::serde::default_true;

#[derive(Clone, Debug, Deserialize)]
pub struct SortOptionRaw {
Expand Down
95 changes: 94 additions & 1 deletion src/config/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,98 @@ pub mod style;
pub mod style_raw;
pub mod tab;
pub mod tab_raw;
pub mod theme;
pub mod theme_raw;

use std::collections::HashMap;

use lscolors::LsColors;

use crate::constants::config::THEME_CONFIG;
use crate::error::AppResult;
use crate::traits::config::TomlConfigFile;
use crate::types::config_type::ConfigType;

use style::AppStyle;
use tab::TabTheme;
use theme_raw::AppThemeRaw;

#[derive(Clone, Debug)]
pub struct AppTheme {
pub tabs: TabTheme,
pub regular: AppStyle,
pub selection: AppStyle,
pub visual_mode_selection: AppStyle,
pub directory: AppStyle,
pub executable: AppStyle,
pub link: AppStyle,
pub link_invalid: AppStyle,
pub socket: AppStyle,
pub ext: HashMap<String, AppStyle>,
pub lscolors: Option<LsColors>,
}

impl AppTheme {
pub fn default_res() -> AppResult<Self> {
let raw: AppThemeRaw = toml::from_str(THEME_CONFIG)?;
Ok(Self::from(raw))
}
}

impl TomlConfigFile for AppTheme {
type Raw = AppThemeRaw;

fn get_type() -> ConfigType {
ConfigType::Theme
}
}

impl std::default::Default for AppTheme {
fn default() -> Self {
// This should not fail.
// If it fails then there is a (syntax) error in the default config file
Self::default_res().unwrap()
}
}

impl From<AppThemeRaw> for AppTheme {
fn from(raw: AppThemeRaw) -> Self {
let tabs = raw.tabs;
let selection = raw.selection.to_style_theme();
let visual_mode_selection = raw.visual_mode_selection.to_style_theme();
let executable = raw.executable.to_style_theme();
let regular = raw.regular.to_style_theme();
let directory = raw.directory.to_style_theme();
let link = raw.link.to_style_theme();
let link_invalid = raw.link_invalid.to_style_theme();
let socket = raw.socket.to_style_theme();
let ext: HashMap<String, AppStyle> = raw
.ext
.iter()
.map(|(k, v)| {
let style = v.to_style_theme();
(k.clone(), style)
})
.collect();
let lscolors = if raw.lscolors_enabled {
let lscolors = LsColors::from_env();
let default = Some(LsColors::default());
lscolors.or(default)
} else {
None
};

Self {
selection,
visual_mode_selection,
executable,
regular,
directory,
link,
link_invalid,
socket,
ext,
tabs: TabTheme::from(tabs),
lscolors,
}
}
}
93 changes: 0 additions & 93 deletions src/config/theme/theme.rs

This file was deleted.

Loading

0 comments on commit 073a61e

Please sign in to comment.