mirror of
https://github.com/chmln/handlr.git
synced 2024-11-14 21:49:27 +01:00
Merge pull request #22 from leiserfg/terminal-from-env
Use TERMINAL from environment as default terminal emulator
This commit is contained in:
commit
06b5355acc
1 changed files with 26 additions and 3 deletions
|
@ -1,19 +1,42 @@
|
||||||
|
use std::env;
|
||||||
use crate::{Error, Result};
|
use crate::{Error, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
fn default_terminal() -> std::string::String{
|
||||||
|
match env::var("TERMINAL") {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(_) => "xterm -e".to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_selector() -> std::string::String{
|
||||||
|
"rofi -dmenu -p 'Open With: '".to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_enable_selector() -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
#[serde(default="default_enable_selector")]
|
||||||
pub enable_selector: bool,
|
pub enable_selector: bool,
|
||||||
|
|
||||||
|
#[serde(default="default_selector")]
|
||||||
pub selector: String,
|
pub selector: String,
|
||||||
|
|
||||||
|
#[serde(default="default_terminal")]
|
||||||
pub terminal_emulator: String,
|
pub terminal_emulator: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
// This seems repetitive but serde does not uses Default
|
||||||
Config {
|
Config {
|
||||||
enable_selector: false,
|
enable_selector: default_enable_selector(),
|
||||||
selector: "rofi -dmenu -p 'Open With: '".to_owned(),
|
selector: default_selector(),
|
||||||
terminal_emulator: "xterm -e".to_owned(),
|
terminal_emulator: default_terminal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue