summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlali <luteranlajos@protonmail.ch>2024-02-28 01:44:22 +0100
committerGitHub <noreply@github.com>2024-02-27 19:44:22 -0500
commit83a906a930241f2f5121d879da1b20ba4d2f62da (patch)
treeba4a9d54888e701a62e328266c9aa6fae50f965c
parent285df85cdd745a959ddcbe0c2c1f176e28370abe (diff)
feat: use a pager instead confirm_exit (#498)
* Use a pager instead confirm_exit Read the $PAGER environment variable. If it's not set, simply use 'less'. * update mimetype config Signed-off-by: LuterĂ¡n Lajos <luteranlajos@protonmail.ch>
-rw-r--r--config/mimetype.toml46
-rw-r--r--src/config/clean/mimetype/entry.rs22
-rw-r--r--src/util/process.rs14
3 files changed, 45 insertions, 37 deletions
diff --git a/config/mimetype.toml b/config/mimetype.toml
index ec2f05d..e9b143a 100644
--- a/config/mimetype.toml
+++ b/config/mimetype.toml
@@ -3,7 +3,7 @@ audio_default = [
{ command = "mpv", args = [
"--",
] },
- { command = "mediainfo", confirm_exit = true },
+ { command = "mediainfo", pager = true },
]
image_default = [
@@ -13,7 +13,7 @@ image_default = [
{ command = "krita", args = [
"--",
], fork = true, silent = true },
- { command = "exiftool", confirm_exit = true },
+ { command = "exiftool", pager = true },
{ command = "swappy", args = [
"-f",
], fork = true },
@@ -23,7 +23,7 @@ video_default = [
{ command = "mpv", args = [
"--",
], fork = true, silent = true },
- { command = "mediainfo", confirm_exit = true },
+ { command = "mediainfo", pager = true },
{ command = "mpv", args = [
"--mute",
"on",
@@ -143,50 +143,56 @@ yml.inherit = "text_default"
# archive formats
7z.app_list = [
+ { command = "file-roller", fork = true, silent = true },
{ command = "7z", args = [
"x",
- ], confirm_exit = true },
- { command = "file-roller", fork = true, silent = true },
+ ] },
]
bz2.app_list = [
+ { command = "file-roller", fork = true, silent = true },
{ command = "tar", args = [
"-xvjf",
- ], confirm_exit = true },
- { command = "file-roller", fork = true, silent = true },
+ ] },
]
gz.app_list = [
+ { command = "file-roller", fork = true, silent = true },
{ command = "tar", args = [
"-xvzf",
- ], confirm_exit = true },
- { command = "file-roller", fork = true, silent = true },
+ ] },
]
tar.app_list = [
+ { command = "file-roller", fork = true, silent = true },
{ command = "tar", args = [
"-xvf",
- ], confirm_exit = true },
- { command = "file-roller", fork = true, silent = true },
+ ] },
]
tgz.app_list = [
+ { command = "file-roller", fork = true, silent = true },
{ command = "tar", args = [
"-xvzf",
- ], confirm_exit = true },
- { command = "file-roller", fork = true, silent = true },
+ ] },
]
rar.app_list = [
+ { command = "file-roller", fork = true, silent = true },
{ command = "unrar", args = [
"x",
- ], confirm_exit = true },
- { command = "file-roller", fork = true, silent = true },
+ ] },
]
xz.app_list = [
+ { command = "file-roller", fork = true, silent = true },
{ command = "tar", args = [
"-xvJf",
- ], confirm_exit = true },
- { command = "file-roller", fork = true, silent = true },
+ ] },
]
zip.app_list = [
- { command = "unzip", confirm_exit = true },
{ command = "file-roller", fork = true, silent = true },
+ { command = "unzip" },
+]
+zst.app_list = [
+ { command = "file-roller", fork = true, silent = true },
+ { command = "zstd", args = [
+ "-d"
+ ] },
]
# misc formats
@@ -196,7 +202,7 @@ m3u.app_list = [
{ command = "micro" },
{ command = "mpv" },
{ command = "gedit", fork = true, silent = true },
- { command = "bat", confirm_exit = true },
+ { command = "bat", pager = true },
]
odt.inherit = "libreoffice_default"
@@ -219,7 +225,7 @@ kdenlive.app_list = [{ command = "kdenlive", fork = true, silent = true }]
tex.app_list = [
{ command = "micro" },
{ command = "gedit", fork = true, silent = true },
- { command = "bat", confirm_exit = true },
+ { command = "bat", pager = true },
{ command = "pdflatex" },
]
diff --git a/src/config/clean/mimetype/entry.rs b/src/config/clean/mimetype/entry.rs
index 790fe7c..ee18998 100644
--- a/src/config/clean/mimetype/entry.rs
+++ b/src/config/clean/mimetype/entry.rs
@@ -12,8 +12,8 @@ pub struct ProgramEntry {
_fork: bool,
#[serde(default, rename = "silent")]
_silent: bool,
- #[serde(default, rename = "confirm_exit")]
- _confirm_exit: bool,
+ #[serde(default, rename = "pager")]
+ _pager: bool,
}
impl ProgramEntry {
@@ -23,7 +23,7 @@ impl ProgramEntry {
_args: Vec::new(),
_fork: false,
_silent: false,
- _confirm_exit: false,
+ _pager: false,
}
}
@@ -54,12 +54,6 @@ impl ProgramEntry {
self
}
- #[allow(dead_code)]
- pub fn confirm_exit(&mut self, confirm_exit: bool) -> &mut Self {
- self._confirm_exit = confirm_exit;
- self
- }
-
pub fn get_command(&self) -> &str {
self._command.as_str()
}
@@ -76,8 +70,8 @@ impl ProgramEntry {
self._silent
}
- pub fn get_confirm_exit(&self) -> bool {
- self._confirm_exit
+ pub fn get_pager(&self) -> bool {
+ self._pager
}
// TODO: Windows support
@@ -96,7 +90,7 @@ impl std::default::Default for ProgramEntry {
_args: Vec::new(),
_fork: false,
_silent: false,
- _confirm_exit: false,
+ _pager: false,
}
}
}
@@ -115,8 +109,8 @@ impl std::fmt::Display for ProgramEntry {
if self.get_silent() {
f.write_str("[silent]").unwrap();
}
- if self.get_confirm_exit() {
- f.write_str("[confirm-exit]").unwrap();
+ if self.get_pager() {
+ f.write_str("[pager]").unwrap();
}
f.write_str("")
}
diff --git a/src/util/process.rs b/src/util/process.rs
index 679239a..b333cea 100644
--- a/src/util/process.rs
+++ b/src/util/process.rs
@@ -58,11 +58,19 @@ where
command.args(entry.get_args());
command.args(paths);
- let _ = command.status()?;
+ if entry.get_pager() {
+ println!("{}", termion::clear::All);
+ let pager_env = std::env::var("PAGER").unwrap_or_else(|_| String::from("less"));
+ let pager_args: Vec<&str> = pager_env.split_whitespace().collect();
- if entry.get_confirm_exit() {
- wait_for_enter()?;
+ if let Some(child_stdout) = command.stdout(process::Stdio::piped()).spawn()?.stdout {
+ process::Command::new(pager_args[0])
+ .args(&pager_args[1..])
+ .stdin(child_stdout)
+ .status()?;
+ }
}
+ command.status()?;
Ok(())
}