summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2021-08-18 15:44:26 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2021-08-18 15:44:26 -0400
commitf8851c7f9ac22289e473a2911611958e361befdc (patch)
tree5f1ea05eb677aede45eb12a877882a7c2ff23a3d /src/main.rs
parent45e7a9f8cc3937ed21006fb4a5d5145426f70558 (diff)
add quit_to_cwd command
- this command lets users exit to the current directory more easily and more ergonomically
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index 446e00e..209b364 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -22,7 +22,7 @@ use structopt::StructOpt;
use crate::config::{
AppConfig, AppKeyMapping, AppMimetypeRegistry, AppTheme, ConfigStructure, JoshutoPreview,
};
-use crate::context::AppContext;
+use crate::context::{AppContext, QuitType};
use crate::error::JoshutoError;
use crate::run::run;
@@ -98,24 +98,32 @@ fn run_joshuto(args: Args) -> Result<(), JoshutoError> {
let config = AppConfig::get_config(CONFIG_FILE);
let keymap = AppKeyMapping::get_config(KEYMAP_FILE);
+ let mut context = AppContext::new(config);
{
- let mut context = AppContext::new(config);
let mut backend: ui::TuiBackend = ui::TuiBackend::new()?;
run(&mut backend, &mut context, keymap)?;
}
- if let Some(p) = args.last_dir {
- let curr_path = std::env::current_dir()?;
- let mut file = File::create(p)?;
- file.write_all(
- curr_path
- .into_os_string()
- .as_os_str()
- .to_string_lossy()
- .as_bytes(),
- )?;
- file.write_all("\n".as_bytes())?;
+ match context.quit {
+ QuitType::ToCurrentDirectory => {
+ if let Some(p) = args.last_dir {
+ let curr_path = std::env::current_dir()?;
+ let mut file = File::create(p)?;
+ file.write_all(
+ curr_path
+ .into_os_string()
+ .as_os_str()
+ .to_string_lossy()
+ .as_bytes(),
+ )?;
+ file.write_all("\n".as_bytes())?;
+ }
+ },
+ QuitType::Force => {},
+ _ => {},
+
}
+
Ok(())
}