summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-06-28 21:57:13 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-06-28 21:57:13 -0400
commitdbde58c681625819992c7ed31b7391076043c414 (patch)
tree069a6ce8b9f9d1c376244b22066259d1b5680ff9 /src
parent57564e71c806ff2089bf47c041c127bd43b015b1 (diff)
change mimetype.toml config
Diffstat (limited to 'src')
-rw-r--r--src/config/mimetype.rs46
-rw-r--r--src/unix.rs11
2 files changed, 40 insertions, 17 deletions
diff --git a/src/config/mimetype.rs b/src/config/mimetype.rs
index eff0540..567dc2d 100644
--- a/src/config/mimetype.rs
+++ b/src/config/mimetype.rs
@@ -11,26 +11,48 @@ const fn default_false() -> bool {
#[derive(Debug, Deserialize)]
pub struct JoshutoMimetypeEntry {
- pub id: usize,
- pub program: String,
- pub args: Option<Vec<String>>,
+ id: usize,
+ command: String,
+ #[serde(default)]
+ args: Vec<String>,
#[serde(default = "default_false")]
- pub fork: bool,
+ fork: bool,
#[serde(default = "default_false")]
- pub silent: bool,
+ silent: bool,
+}
+
+impl JoshutoMimetypeEntry {
+ pub fn get_id(&self) -> usize {
+ self.id
+ }
+
+ pub fn get_command(&self) -> &str {
+ &self.command
+ }
+
+ pub fn get_args(&self) -> &[String] {
+ &self.args
+ }
+
+ pub fn get_fork(&self) -> bool {
+ self.fork
+ }
+
+ pub fn get_silent(&self) -> bool {
+ self.silent
+ }
}
impl std::fmt::Display for JoshutoMimetypeEntry {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.write_str(self.program.as_str()).unwrap();
- if let Some(s) = self.args.as_ref() {
- s.iter().for_each(|arg| write!(f, " {}", arg).unwrap());
- }
+ f.write_str(self.get_command()).unwrap();
+ self.get_args().iter().for_each(|arg| write!(f, " {}", arg).unwrap());
+
f.write_str("\t[").unwrap();
- if self.fork {
+ if self.get_fork() {
f.write_str("fork,").unwrap();
}
- if self.silent {
+ if self.get_silent() {
f.write_str("silent").unwrap();
}
f.write_str("]")
@@ -51,7 +73,7 @@ impl Flattenable<JoshutoMimetype> for JoshutoRawMimetype {
fn flatten(self) -> JoshutoMimetype {
let mut entries = HashMap::with_capacity(self.entry.len());
for entry in self.entry {
- entries.insert(entry.id, entry);
+ entries.insert(entry.get_id(), entry);
}
JoshutoMimetype {
entries,
diff --git a/src/unix.rs b/src/unix.rs
index e8f52aa..39fe886e 100644
--- a/src/unix.rs
+++ b/src/unix.rs
@@ -68,22 +68,23 @@ pub fn set_mode(path: &Path, mode: u32) {
}
pub fn open_with_entry(paths: &[&PathBuf], entry: &mimetype::JoshutoMimetypeEntry) {
- let program = entry.program.clone();
+ let program = String::from(entry.get_command());
let mut command = process::Command::new(program);
- if entry.silent {
+ if entry.get_silent() {
command.stdout(process::Stdio::null());
command.stderr(process::Stdio::null());
}
- if let Some(args) = entry.args.as_ref() {
- command.args(args.clone());
+ let args = entry.get_args();
+ if args.len() > 0 {
+ command.args(args);
}
command.args(paths.iter().map(|path| path.as_os_str()));
match command.spawn() {
Ok(mut handle) => {
- if !entry.fork {
+ if !entry.get_fork() {
match handle.wait() {
Ok(_) => {}
Err(e) => eprintln!("{}", e),