Add --hold CLI flag

This implements --hold flag which keeps Alacritty open after
its child process exits.

Fixes #1165.
This commit is contained in:
Valentin Ignatev 2019-10-10 00:37:48 +03:00 committed by Christian Duerr
parent 24651a6144
commit 4cb5566a9c
9 changed files with 130 additions and 104 deletions

View File

@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bindings for ScrollToTop and ScrollToBottom actions - Bindings for ScrollToTop and ScrollToBottom actions
- `ReceiveChar` key binding action to insert the key's text character - `ReceiveChar` key binding action to insert the key's text character
- Live reload font size from config - Live reload font size from config
- New CLI flag `--hold` for keeping Alacritty opened after its child process exits
### Changed ### Changed

View File

@ -35,6 +35,7 @@ pub struct Options {
pub embed: Option<String>, pub embed: Option<String>,
pub log_level: LevelFilter, pub log_level: LevelFilter,
pub command: Option<Shell<'static>>, pub command: Option<Shell<'static>>,
pub hold: bool,
pub working_dir: Option<PathBuf>, pub working_dir: Option<PathBuf>,
pub config: Option<PathBuf>, pub config: Option<PathBuf>,
pub persistent_logging: bool, pub persistent_logging: bool,
@ -53,6 +54,7 @@ impl Default for Options {
embed: None, embed: None,
log_level: LevelFilter::Warn, log_level: LevelFilter::Warn,
command: None, command: None,
hold: false,
working_dir: None, working_dir: None,
config: None, config: None,
persistent_logging: false, persistent_logging: false,
@ -71,104 +73,106 @@ impl Options {
let mut options = Options::default(); let mut options = Options::default();
let matches = let matches = App::new(crate_name!())
App::new(crate_name!()) .version(version.as_str())
.version(version.as_str()) .author(crate_authors!("\n"))
.author(crate_authors!("\n")) .about(crate_description!())
.about(crate_description!()) .arg(Arg::with_name("ref-test").long("ref-test").help("Generates ref test"))
.arg(Arg::with_name("ref-test").long("ref-test").help("Generates ref test")) .arg(
.arg( Arg::with_name("live-config-reload")
Arg::with_name("live-config-reload") .long("live-config-reload")
.long("live-config-reload") .help("Enable automatic config reloading"),
.help("Enable automatic config reloading"), )
) .arg(
.arg( Arg::with_name("no-live-config-reload")
Arg::with_name("no-live-config-reload") .long("no-live-config-reload")
.long("no-live-config-reload") .help("Disable automatic config reloading")
.help("Disable automatic config reloading") .conflicts_with("live-config-reload"),
.conflicts_with("live-config-reload"), )
) .arg(
.arg( Arg::with_name("print-events")
Arg::with_name("print-events") .long("print-events")
.long("print-events") .help("Print all events to stdout"),
.help("Print all events to stdout"), )
) .arg(
.arg( Arg::with_name("persistent-logging")
Arg::with_name("persistent-logging") .long("persistent-logging")
.long("persistent-logging") .help("Keep the log file after quitting Alacritty"),
.help("Keep the log file after quitting Alacritty"), )
) .arg(
.arg( Arg::with_name("dimensions")
Arg::with_name("dimensions") .long("dimensions")
.long("dimensions") .short("d")
.short("d") .value_names(&["columns", "lines"])
.value_names(&["columns", "lines"]) .help(
.help( "Defines the window dimensions. Falls back to size specified by window \
"Defines the window dimensions. Falls back to size specified by \ manager if set to 0x0 [default: 0x0]",
window manager if set to 0x0 [default: 0x0]", ),
), )
) .arg(
.arg( Arg::with_name("position")
Arg::with_name("position") .long("position")
.long("position") .allow_hyphen_values(true)
.allow_hyphen_values(true) .value_names(&["x-pos", "y-pos"])
.value_names(&["x-pos", "y-pos"]) .help(
.help( "Defines the window position. Falls back to position specified by window \
"Defines the window position. Falls back to position specified by \ manager if unset [default: unset]",
window manager if unset [default: unset]", ),
), )
) .arg(
.arg( Arg::with_name("title")
Arg::with_name("title") .long("title")
.long("title") .short("t")
.short("t") .takes_value(true)
.takes_value(true) .help(&format!("Defines the window title [default: {}]", DEFAULT_NAME)),
.help(&format!("Defines the window title [default: {}]", DEFAULT_NAME)), )
) .arg(
.arg( Arg::with_name("class")
Arg::with_name("class").long("class").takes_value(true).help(&format!( .long("class")
"Defines window class on Linux [default: {}]", .takes_value(true)
DEFAULT_NAME .help(&format!("Defines window class on Linux [default: {}]", DEFAULT_NAME)),
)), )
) .arg(
.arg(Arg::with_name("embed").long("embed").takes_value(true).help( Arg::with_name("embed").long("embed").takes_value(true).help(
"Defines the X11 window ID (as a decimal integer) to embed Alacritty within", "Defines the X11 window ID (as a decimal integer) to embed Alacritty within",
)) ),
.arg( )
Arg::with_name("q") .arg(
.short("q") Arg::with_name("q")
.multiple(true) .short("q")
.conflicts_with("v") .multiple(true)
.help("Reduces the level of verbosity (the min level is -qq)"), .conflicts_with("v")
) .help("Reduces the level of verbosity (the min level is -qq)"),
.arg( )
Arg::with_name("v") .arg(
.short("v") Arg::with_name("v")
.multiple(true) .short("v")
.conflicts_with("q") .multiple(true)
.help("Increases the level of verbosity (the max level is -vvv)"), .conflicts_with("q")
) .help("Increases the level of verbosity (the max level is -vvv)"),
.arg( )
Arg::with_name("working-directory") .arg(
.long("working-directory") Arg::with_name("working-directory")
.takes_value(true) .long("working-directory")
.help("Start the shell in the specified working directory"), .takes_value(true)
) .help("Start the shell in the specified working directory"),
.arg(Arg::with_name("config-file").long("config-file").takes_value(true).help( )
"Specify alternative configuration file [default: \ .arg(Arg::with_name("config-file").long("config-file").takes_value(true).help(
$XDG_CONFIG_HOME/alacritty/alacritty.yml]", "Specify alternative configuration file [default: \
)) $XDG_CONFIG_HOME/alacritty/alacritty.yml]",
.arg( ))
Arg::with_name("command") .arg(
.long("command") Arg::with_name("command")
.short("e") .long("command")
.multiple(true) .short("e")
.takes_value(true) .multiple(true)
.min_values(1) .takes_value(true)
.allow_hyphen_values(true) .min_values(1)
.help("Command and args to execute (must be last argument)"), .allow_hyphen_values(true)
) .help("Command and args to execute (must be last argument)"),
.get_matches(); )
.arg(Arg::with_name("hold").long("hold").help("Remain open after child process exits"))
.get_matches();
if matches.is_present("ref-test") { if matches.is_present("ref-test") {
options.ref_test = true; options.ref_test = true;
@ -238,6 +242,10 @@ impl Options {
options.command = Some(Shell::new_with_args(command, args)); options.command = Some(Shell::new_with_args(command, args));
} }
if matches.is_present("hold") {
options.hold = true;
}
options options
} }
@ -254,6 +262,8 @@ impl Options {
); );
config.shell = self.command.or(config.shell); config.shell = self.command.or(config.shell);
config.hold = self.hold;
config.window.dimensions = self.dimensions.unwrap_or(config.window.dimensions); config.window.dimensions = self.dimensions.unwrap_or(config.window.dimensions);
config.window.position = self.position.or(config.window.position); config.window.position = self.position.or(config.window.position);
config.window.title = self.title.or(config.window.title); config.window.title = self.title.or(config.window.title);

View File

@ -178,8 +178,7 @@ fn run(window_event_loop: GlutinEventLoop<Event>, config: Config) -> Result<(),
// renderer and input processing. Note that access to the terminal state is // renderer and input processing. Note that access to the terminal state is
// synchronized since the I/O loop updates the state, and the display // synchronized since the I/O loop updates the state, and the display
// consumes it periodically. // consumes it periodically.
let event_loop = let event_loop = EventLoop::new(Arc::clone(&terminal), event_proxy.clone(), pty, &config);
EventLoop::new(Arc::clone(&terminal), event_proxy.clone(), pty, config.debug.ref_test);
// The event loop channel allows write requests from the event processor // The event loop channel allows write requests from the event processor
// to be sent to the pty loop and ultimately written to the pty. // to be sent to the pty loop and ultimately written to the pty.

View File

@ -130,6 +130,10 @@ pub struct Config<T> {
#[serde(flatten)] #[serde(flatten)]
pub ui_config: T, pub ui_config: T,
/// Remain open after child process exits
#[serde(skip)]
pub hold: bool,
// TODO: DEPRECATED // TODO: DEPRECATED
#[serde(default, deserialize_with = "failure_default")] #[serde(default, deserialize_with = "failure_default")]
pub render_timer: Option<bool>, pub render_timer: Option<bool>,

View File

@ -13,6 +13,7 @@ use mio::{self, Events, PollOpt, Ready};
use mio_extras::channel::{self, Receiver, Sender}; use mio_extras::channel::{self, Receiver, Sender};
use crate::ansi; use crate::ansi;
use crate::config::Config;
use crate::event::{self, Event, EventListener}; use crate::event::{self, Event, EventListener};
use crate::sync::FairMutex; use crate::sync::FairMutex;
use crate::term::Term; use crate::term::Term;
@ -43,6 +44,7 @@ pub struct EventLoop<T: tty::EventedPty, U: EventListener> {
tx: Sender<Msg>, tx: Sender<Msg>,
terminal: Arc<FairMutex<Term<U>>>, terminal: Arc<FairMutex<Term<U>>>,
event_proxy: U, event_proxy: U,
hold: bool,
ref_test: bool, ref_test: bool,
} }
@ -143,11 +145,11 @@ where
U: EventListener + Send + 'static, U: EventListener + Send + 'static,
{ {
/// Create a new event loop /// Create a new event loop
pub fn new( pub fn new<V>(
terminal: Arc<FairMutex<Term<U>>>, terminal: Arc<FairMutex<Term<U>>>,
event_proxy: U, event_proxy: U,
pty: T, pty: T,
ref_test: bool, config: &Config<V>,
) -> EventLoop<T, U> { ) -> EventLoop<T, U> {
let (tx, rx) = channel::channel(); let (tx, rx) = channel::channel();
EventLoop { EventLoop {
@ -157,7 +159,8 @@ where
rx, rx,
terminal, terminal,
event_proxy, event_proxy,
ref_test, hold: config.hold,
ref_test: config.debug.ref_test,
} }
} }
@ -327,7 +330,9 @@ where
#[cfg(unix)] #[cfg(unix)]
token if token == self.pty.child_event_token() => { token if token == self.pty.child_event_token() => {
if let Some(tty::ChildEvent::Exited) = self.pty.next_child_event() { if let Some(tty::ChildEvent::Exited) = self.pty.next_child_event() {
self.terminal.lock().exit(); if !self.hold {
self.terminal.lock().exit();
}
self.event_proxy.send_event(Event::Wakeup); self.event_proxy.send_event(Event::Wakeup);
break 'event_loop; break 'event_loop;
} }

View File

@ -14,6 +14,9 @@ However, it does allow configuration of many aspects of the terminal.
\fB\-h\fR, \fB\-\-help\fR \fB\-h\fR, \fB\-\-help\fR
Prints help information Prints help information
.TP .TP
\fB\-\-hold\fR
Remain open after child process exits
.TP
\fB\-\-live\-config\-reload\fR \fB\-\-live\-config\-reload\fR
Enable automatic config reloading Enable automatic config reloading
.TP .TP

View File

@ -11,6 +11,7 @@ _arguments \
"--print-events[print all events to stdout]" \ "--print-events[print all events to stdout]" \
'(-v)'{-q,-qq}"[reduce the level of verbosity (min is -qq)]" \ '(-v)'{-q,-qq}"[reduce the level of verbosity (min is -qq)]" \
"--ref-test[generate ref test]" \ "--ref-test[generate ref test]" \
"--hold[remain open after child process exits]" \
'(-q)'{-v,-vv,-vvv}"[increase the level of verbosity (max is -vvv)]" \ '(-q)'{-v,-vv,-vvv}"[increase the level of verbosity (max is -vvv)]" \
"$ign(-)"{-V,--version}"[print version information]" \ "$ign(-)"{-V,--version}"[print version information]" \
"--class=[define the window class]:class" \ "--class=[define the window class]:class" \

View File

@ -11,7 +11,7 @@ _alacritty()
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
prevprev="${COMP_WORDS[COMP_CWORD-2]}" prevprev="${COMP_WORDS[COMP_CWORD-2]}"
opts="-h --help -V --version --live-config-reload --no-live-config-reload --persistent-logging --print-events -q -qq -v -vv -vvv --ref-test -e --command --config-file -d --dimensions --position -t --title --embed --class --working-directory" opts="-h --help -V --version --live-config-reload --no-live-config-reload --persistent-logging --print-events -q -qq -v -vv -vvv --ref-test --hold -e --command --config-file -d --dimensions --position -t --title --embed --class --working-directory"
# If `--command` or `-e` is used, stop completing # If `--command` or `-e` is used, stop completing
for i in "${!COMP_WORDS[@]}"; do for i in "${!COMP_WORDS[@]}"; do

View File

@ -37,6 +37,9 @@ complete -c alacritty \
-a '(__fish_complete_directories (commandline -ct))' \ -a '(__fish_complete_directories (commandline -ct))' \
-l "working-directory" \ -l "working-directory" \
-d "Start shell in specified directory" -d "Start shell in specified directory"
complete -c alacritty \
-l "hold" \
-d "Remain open after child process exits"
# Output # Output
complete \ complete \