Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: rust fixes and optimizations #933

Merged
merged 24 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1ff69c7
fix: getting locked out when running script
jeevithakannan2 Nov 6, 2024
4a9d726
Merge remote-tracking branch 'upstream/main' into min-tui
jeevithakannan2 Nov 6, 2024
1aa1dfe
Use success and fail colors and reorder imports
jeevithakannan2 Nov 10, 2024
3b7e859
Remove redundant code in themes
jeevithakannan2 Nov 10, 2024
190c26c
Fix scroll beyond list, color bleeding and refact in confirmation.rs
jeevithakannan2 Nov 10, 2024
0b4f33c
Implement case insensitive, fix word disappearing bug
jeevithakannan2 Nov 10, 2024
7e96651
Revert "Remove redundant code in themes"
jeevithakannan2 Nov 11, 2024
35159b8
Reference instead of passing the vector
jeevithakannan2 Nov 11, 2024
2d1f5db
Revert regex and String implementation
jeevithakannan2 Nov 11, 2024
10352c6
Replace ansi and text wrapping code with ratatui
jeevithakannan2 Nov 11, 2024
0be3a44
Merge branch 'main' into optimization
jeevithakannan2 Nov 11, 2024
2f1f5fd
Fix conflicts
jeevithakannan2 Nov 11, 2024
02b0612
Reference instead of borrowing commands, refact mut variables
jeevithakannan2 Nov 11, 2024
df81642
Update tui/src/filter.rs
jeevithakannan2 Nov 12, 2024
79aae9e
Rendering optimizations and function refactors
jeevithakannan2 Nov 12, 2024
06f13dc
Cleanup
jeevithakannan2 Nov 12, 2024
8571925
Update deps, remove unused temp-dir
jeevithakannan2 Nov 12, 2024
f8c6ba1
Add accidentally deleted preview.tape
jeevithakannan2 Nov 13, 2024
1044517
Merge remote-tracking branch 'origin/min-tui' into optimization
jeevithakannan2 Nov 14, 2024
ed01e13
Add fields to config files
jeevithakannan2 Nov 15, 2024
42a7836
Merge branch 'main' into optimization
jeevithakannan2 Nov 15, 2024
78b7c3f
Merge branch 'config-updates' into optimization
jeevithakannan2 Nov 15, 2024
a0752ae
Remove accidentally commited config file
jeevithakannan2 Nov 15, 2024
3e888c3
Merge branch 'main' into optimization
jeevithakannan2 Nov 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 24 additions & 85 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include = ["src/*.rs", "Cargo.toml", "tabs/**"]
[dependencies]
include_dir = "0.7.4"
temp-dir = "0.1.14"
serde = { version = "1.0.205", features = ["derive"], default-features = false }
serde = { version = "1.0.215", features = ["derive"], default-features = false }
toml = { version = "0.8.19", features = ["parse"], default-features = false }
which = "6.0.3"
which = "7.0.0"
ego-tree = "0.9.0"
43 changes: 37 additions & 6 deletions core/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,59 @@
use crate::{ListNode, TabList};
use serde::Deserialize;
use std::path::Path;
use std::process;
use std::{fs, path::Path, process, rc::Rc};

// Struct that defines what values can be used in the toml file
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
pub auto_execute: Vec<String>,
#[serde(default)]
auto_execute: Option<Vec<String>>,
#[serde(default)]
skip_confirmation: Option<bool>,
#[serde(default)]
size_bypass: Option<bool>,
}

// Struct that holds the parsed values from the toml so that it can be applied in the AppState
pub struct ConfigValues {
pub auto_execute_commands: Vec<Rc<ListNode>>,
pub skip_confirmation: bool,
pub size_bypass: bool,
}

impl Config {
pub fn from_file(path: &Path) -> Self {
let content = match std::fs::read_to_string(path) {
pub fn read_config(path: &Path, tabs: &TabList) -> ConfigValues {
let content = match fs::read_to_string(path) {
Ok(content) => content,
Err(e) => {
eprintln!("Failed to read config file {}: {}", path.display(), e);
process::exit(1);
}
};

match toml::from_str(&content) {
let config: Config = match toml::from_str(&content) {
Ok(config) => config,
Err(e) => {
eprintln!("Failed to parse config file: {}", e);
process::exit(1);
}
};

ConfigValues {
auto_execute_commands: config.auto_execute_commands(tabs),
skip_confirmation: config.skip_confirmation.unwrap_or(false),
size_bypass: config.size_bypass.unwrap_or(false),
}
}

fn auto_execute_commands(&self, tabs: &TabList) -> Vec<Rc<ListNode>> {
self.auto_execute
.as_ref()
.map_or_else(Vec::new, |commands| {
commands
.iter()
.filter_map(|name| tabs.iter().find_map(|tab| tab.find_command_by_name(name)))
.collect()
})
}
}
9 changes: 4 additions & 5 deletions core/src/inner.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use crate::{Command, ListNode, Tab};
use ego_tree::{NodeMut, Tree};
use include_dir::{include_dir, Dir};
use serde::Deserialize;
use std::{
fs::File,
io::{BufRead, BufReader, Read},
Expand All @@ -6,11 +10,6 @@ use std::{
path::{Path, PathBuf},
rc::Rc,
};

use crate::{Command, ListNode, Tab};
use ego_tree::{NodeMut, Tree};
use include_dir::{include_dir, Dir};
use serde::Deserialize;
use temp_dir::TempDir;

const TAB_DATA: Dir = include_dir!("$CARGO_MANIFEST_DIR/tabs");
Expand Down
12 changes: 4 additions & 8 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use ego_tree;
use ego_tree::Tree;
use std::path::PathBuf;

pub use config::Config;
pub use config::{Config, ConfigValues};
pub use inner::{get_tabs, TabList};

#[derive(Clone, Hash, Eq, PartialEq)]
Expand Down Expand Up @@ -38,14 +38,10 @@ pub struct ListNode {
}

impl Tab {
pub fn find_command(&self, name: &str) -> Option<Rc<ListNode>> {
fn find_command_by_name(&self, name: &str) -> Option<Rc<ListNode>> {
self.tree.root().descendants().find_map(|node| {
let value = node.value();
if value.name == name && !node.has_children() {
Some(value.clone())
} else {
None
}
let node_value = node.value();
(node_value.name == name && !node.has_children()).then_some(node_value.clone())
})
}
}
13 changes: 4 additions & 9 deletions tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@ oneshot = { version = "0.1.8", features = ["std"], default-features = false }
portable-pty = "0.8.1"
ratatui = { version = "0.29.0", features = ["crossterm"], default-features = false }
tui-term = { version = "0.2.0", default-features = false }
temp-dir = "0.1.14"
time = { version = "0.3.36", features = ["formatting", "local-offset", "macros"], default-features = false }
unicode-width = { version = "0.2.0", default-features = false }
rand = { version = "0.8.5", optional = true }
linutil_core = { version = "24.10.31" }
tree-sitter-highlight = "0.24.3"
tree-sitter-bash = "0.23.1"
textwrap = { version = "0.16.1", default-features = false }
anstyle = { version = "1.0.8", default-features = false }
ansi-to-tui = { version = "7.0.0", default-features = false }
zips = "0.1.7"
linutil_core = { version = "24.10.31", path = "../core" }
tree-sitter-highlight = "0.24.4"
tree-sitter-bash = "0.23.3"
nix = { version = "0.29.0", features = [ "user" ] }
vt100-ctt = { git = "https://github.com/ChrisTitusTech/vt100-rust" }
vt100-ctt = "0.16.0"

[[bin]]
name = "linutil"
Expand Down
Loading