1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

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,8 +73,7 @@ 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!())
@ -104,8 +105,8 @@ impl Options {
.short("d") .short("d")
.value_names(&["columns", "lines"]) .value_names(&["columns", "lines"])
.help( .help(
"Defines the window dimensions. Falls back to size specified by \ "Defines the window dimensions. Falls back to size specified by window \
window manager if set to 0x0 [default: 0x0]", manager if set to 0x0 [default: 0x0]",
), ),
) )
.arg( .arg(
@ -114,8 +115,8 @@ impl Options {
.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 \ "Defines the window position. Falls back to position specified by window \
window manager if unset [default: unset]", manager if unset [default: unset]",
), ),
) )
.arg( .arg(
@ -126,14 +127,16 @@ impl Options {
.help(&format!("Defines the window title [default: {}]", DEFAULT_NAME)), .help(&format!("Defines the window title [default: {}]", DEFAULT_NAME)),
) )
.arg( .arg(
Arg::with_name("class").long("class").takes_value(true).help(&format!( Arg::with_name("class")
"Defines window class on Linux [default: {}]", .long("class")
DEFAULT_NAME .takes_value(true)
)), .help(&format!("Defines window class on Linux [default: {}]", DEFAULT_NAME)),
) )
.arg(Arg::with_name("embed").long("embed").takes_value(true).help( .arg(
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(
Arg::with_name("q") Arg::with_name("q")
.short("q") .short("q")
@ -168,6 +171,7 @@ impl Options {
.allow_hyphen_values(true) .allow_hyphen_values(true)
.help("Command and args to execute (must be last argument)"), .help("Command and args to execute (must be last argument)"),
) )
.arg(Arg::with_name("hold").long("hold").help("Remain open after child process exits"))
.get_matches(); .get_matches();
if matches.is_present("ref-test") { if matches.is_present("ref-test") {
@ -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() {
if !self.hold {
self.terminal.lock().exit(); 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 \