diff --git a/.todo.md b/.todo.md index 0a069e1..6ae6d03 100644 --- a/.todo.md +++ b/.todo.md @@ -1,8 +1,7 @@ - [ ] 0.3.2 - [ ] Better CLI - - [ ] Allow providing config file - [ ] Allow providing syntax highlighting option - - [ ] Read only mode + - [X] Allow providing config file - [ ] 0.3.3 - [ ] Help page inside editor - [ ] UPDATE AUR PACKAGE @@ -28,3 +27,5 @@ - [ ] More plugins - 0.4.2 - [ ] Bracket and Quote Pairs - [ ] Auto indentation +- [ ] Tweaks - 0.4.3 + - [ ] Read only mode diff --git a/Cargo.lock b/Cargo.lock index 6470498..6d42ac9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -284,7 +284,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] name = "ox" -version = "0.3.1" +version = "0.3.2" dependencies = [ "alinio", "crossterm", diff --git a/Cargo.toml b/Cargo.toml index 1b8613e..bcd5211 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ox" -version = "0.3.1" +version = "0.3.2" edition = "2021" authors = ["Curlpipe <11898833+curlpipe@users.noreply.github.com>"] description = "A Rust powered text editor." diff --git a/src/cli.rs b/src/cli.rs index d485b0c..a462045 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,22 +1,23 @@ -use jargon_args::Jargon; +use jargon_args::{Key, Jargon}; /// Holds the version number of the crate pub const VERSION: &str = env!("CARGO_PKG_VERSION"); /// Holds the help dialog pub const HELP: &str = "\ -Cactus: A compact and complete kaolinite implementation +Ox: A lightweight and flexible text editor -USAGE: cactus [options] [files] +USAGE: ox [options] [files] OPTIONS: - --help, -h : Show this help message - --version, -v : Show the version number + --help, -h : Show this help message + --version, -v : Show the version number + --config [path], -c [path] : Specify the configuration file EXAMPLES: - cactus test.txt - cactus test.txt test2.txt - cactus /home/user/docs/test.txt + ox test.txt + ox test.txt test2.txt + ox /home/user/docs/test.txt "; /// Struct to help with starting ox @@ -48,4 +49,13 @@ impl CommandLineInterface { pub fn get_files(&mut self) { self.to_open = self.jargon.clone().finish(); } + + /// Configuration file path + pub fn get_config_path(&mut self) -> String { + let config_key: Key = ["-c", "--config"].into(); + match self.jargon.option_arg::(config_key.clone()) { + Some(config) => config, + None => "~/.oxrc".to_string(), + } + } } diff --git a/src/config.rs b/src/config.rs index 7ea69c0..0c2f51c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,7 +27,7 @@ pub struct Config { } impl Config { - pub fn read() -> Result { + pub fn read(path: String) -> Result { // Load defaults let lua = Lua::new(); @@ -49,7 +49,7 @@ impl Config { lua.load(DEFAULT_CONFIG).exec()?; // Attempt to read config file from home directory - if let Ok(path) = shellexpand::full("~/.oxrc") { + if let Ok(path) = shellexpand::full(&path) { if let Ok(config) = std::fs::read_to_string(path.to_string()) { // Update configuration with user-defined values lua.load(config).exec()?; diff --git a/src/editor.rs b/src/editor.rs index 3611d9b..4e69221 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -34,12 +34,12 @@ pub struct Editor { impl Editor { /// Create a new instance of the editor - pub fn new() -> Result { + pub fn new(config: String) -> Result { Ok(Self { doc: vec![], ptr: 0, terminal: Terminal::new(), - config: Config::read()?, + config: Config::read(config)?, active: true, greet: false, highlighter: vec![], diff --git a/src/main.rs b/src/main.rs index 9486ca1..3753216 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,14 +21,14 @@ fn main() { return } - cli.get_files(); - let _ = run(cli); } -fn run(cli: CommandLineInterface) -> Result<()> { +fn run(mut cli: CommandLineInterface) -> Result<()> { + let config_path = cli.get_config_path(); + cli.get_files(); // Create editor and open requested files - let mut editor = Editor::new()?; + let mut editor = Editor::new(config_path)?; for file in cli.to_open { editor.open_or_new(file)?; }