mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 22:01:47 +03:00
add --daemonize flag
This commit is contained in:
parent
33f17eaf3f
commit
4c877d493f
@ -55,6 +55,7 @@ zstd = "0.4"
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
mio = "0.6"
|
||||
mio-extras = "2.0"
|
||||
daemonize = "0.4"
|
||||
|
||||
[dependencies.fontconfig]
|
||||
optional = true
|
||||
|
@ -118,6 +118,9 @@ pub struct Config {
|
||||
|
||||
#[serde(default)]
|
||||
pub keys: Vec<Key>,
|
||||
|
||||
#[serde(default)]
|
||||
pub daemon_options: DaemonOptions,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
@ -362,6 +365,36 @@ fn default_dpi() -> f64 {
|
||||
96.0
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Deserialize)]
|
||||
pub struct DaemonOptions {
|
||||
pub pid_file: Option<PathBuf>,
|
||||
pub stdout: Option<PathBuf>,
|
||||
pub stderr: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl DaemonOptions {
|
||||
pub fn pid_file(&self) -> PathBuf {
|
||||
self.pid_file
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| RUNTIME_DIR.join("pid"))
|
||||
}
|
||||
|
||||
pub fn stdout(&self) -> PathBuf {
|
||||
self.stdout
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| RUNTIME_DIR.join("log"))
|
||||
}
|
||||
|
||||
pub fn stderr(&self) -> PathBuf {
|
||||
self.stderr
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| RUNTIME_DIR.join("log"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Configures an instance of a multiplexer that can be communicated
|
||||
/// with via a unix domain socket
|
||||
#[derive(Default, Debug, Clone, Deserialize)]
|
||||
@ -483,6 +516,7 @@ impl Default for Config {
|
||||
keys: vec![],
|
||||
tls_servers: vec![],
|
||||
tls_clients: vec![],
|
||||
daemon_options: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
src/main.rs
22
src/main.rs
@ -98,6 +98,10 @@ struct StartCommand {
|
||||
#[structopt(long = "no-auto-connect")]
|
||||
no_auto_connect: bool,
|
||||
|
||||
/// Detach from the foreground and become a background process
|
||||
#[structopt(long = "daemonize")]
|
||||
daemonize: bool,
|
||||
|
||||
/// Instead of executing your shell, run PROG.
|
||||
/// For example: `wezterm start -- bash -l` will spawn bash
|
||||
/// as if it were a login shell.
|
||||
@ -129,7 +133,23 @@ enum CliSubCommand {
|
||||
List,
|
||||
}
|
||||
|
||||
fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Result<(), Error> {
|
||||
fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Fallible<()> {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
if opts.daemonize {
|
||||
use std::fs::OpenOptions;
|
||||
let mut options = OpenOptions::new();
|
||||
options.write(true).create(true).append(true);
|
||||
let stdout = options.open(config.daemon_options.stdout())?;
|
||||
let stderr = options.open(config.daemon_options.stderr())?;
|
||||
daemonize::Daemonize::new()
|
||||
.stdout(stdout)
|
||||
.stderr(stderr)
|
||||
.pid_file(config.daemon_options.pid_file())
|
||||
.start()?;
|
||||
}
|
||||
}
|
||||
|
||||
let font_system = opts.font_system.unwrap_or(config.font_system);
|
||||
font_system.set_default();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user