1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-25 14:05:41 -05:00

Add "Quit" action to allow exit on a Cmd-W or Cmd-Q

Adds a new "Quit" action and binds it to Cmd-W and Cmd-Q on Mac OS in an
attempt to make Alacritty feel more like a "normal" citizen of the
operating system. Alternatives like Ctrl-D are okay, but I usually want
to leave my shells nested within Tmux open even if I exit my terminal.
It's also largely selfish: I've built up muscle memory over the years
that takes my fingers to Cmd-Q first (and I suspect I'm not the only
one).

The implementation for an exit is copied from `event.rs` which notably
is already tagged with a FIXME. It seems that `tty.rs` contains a
`process_should_exit` system to help handle a `SIGCHLD`, and it's
possible that these two exit implementations should be merged together.
I could probably tackle that as my next project.

As mentioned in #218, Alacritty can't really spawn other windows right
now, so I've tied in Cmd-W as simply another synonym for quitting until
that's implemented.

Fixes #218.
This commit is contained in:
Brandur 2017-02-05 18:32:43 -08:00 committed by Joe Wilm
parent 82c9235bb1
commit 12cd04fea2
4 changed files with 13 additions and 1 deletions

View file

@ -144,6 +144,8 @@ colors:
key_bindings: key_bindings:
- { key: V, mods: Command, action: Paste } - { key: V, mods: Command, action: Paste }
- { key: C, mods: Command, action: Copy } - { key: C, mods: Command, action: Copy }
- { key: Q, mods: Command, action: Quit }
- { key: W, mods: Command, action: Quit }
- { key: Home, chars: "\x1b[H", mode: ~AppCursor } - { key: Home, chars: "\x1b[H", mode: ~AppCursor }
- { key: Home, chars: "\x1b[1~", mode: AppCursor } - { key: Home, chars: "\x1b[1~", mode: AppCursor }
- { key: End, chars: "\x1b[F", mode: ~AppCursor } - { key: End, chars: "\x1b[F", mode: ~AppCursor }

View file

@ -144,6 +144,8 @@ colors:
key_bindings: key_bindings:
- { key: V, mods: Command, action: Paste } - { key: V, mods: Command, action: Paste }
- { key: C, mods: Command, action: Copy } - { key: C, mods: Command, action: Copy }
- { key: Q, mods: Command, action: Quit }
- { key: W, mods: Command, action: Quit }
- { key: Home, chars: "\x1b[H", mode: ~AppCursor } - { key: Home, chars: "\x1b[H", mode: ~AppCursor }
- { key: Home, chars: "\x1b[1~", mode: AppCursor } - { key: Home, chars: "\x1b[1~", mode: AppCursor }
- { key: End, chars: "\x1b[F", mode: ~AppCursor } - { key: End, chars: "\x1b[F", mode: ~AppCursor }

View file

@ -352,7 +352,7 @@ impl de::Deserialize for ActionWrapper {
type Value = ActionWrapper; type Value = ActionWrapper;
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Paste, Copy, or PasteSelection") f.write_str("Paste, Copy, PasteSelection, or Quit")
} }
fn visit_str<E>(self, value: &str) -> ::std::result::Result<ActionWrapper, E> fn visit_str<E>(self, value: &str) -> ::std::result::Result<ActionWrapper, E>
@ -362,6 +362,7 @@ impl de::Deserialize for ActionWrapper {
"Paste" => Action::Paste, "Paste" => Action::Paste,
"Copy" => Action::Copy, "Copy" => Action::Copy,
"PasteSelection" => Action::PasteSelection, "PasteSelection" => Action::PasteSelection,
"Quit" => Action::Quit,
_ => return Err(E::invalid_value(Unexpected::Str(value), &self)), _ => return Err(E::invalid_value(Unexpected::Str(value), &self)),
})) }))
} }

View file

@ -137,6 +137,9 @@ pub enum Action {
/// Paste contents of selection buffer /// Paste contents of selection buffer
PasteSelection, PasteSelection,
/// Quits Alacritty.
Quit,
} }
impl Action { impl Action {
@ -165,6 +168,10 @@ impl Action {
warn!("Error loading data from clipboard. {}", Red(err)); warn!("Error loading data from clipboard. {}", Red(err));
}); });
}, },
Action::Quit => {
// FIXME should do a more graceful shutdown
::std::process::exit(0);
},
} }
} }