mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
simplify ctrl+c handling, its done first so no one can block it
This commit is contained in:
parent
63630eb18d
commit
e7f0db2941
3 changed files with 9 additions and 18 deletions
10
src/app.rs
10
src/app.rs
|
|
@ -93,6 +93,10 @@ impl App {
|
||||||
pub fn event(&mut self, ev: Event) {
|
pub fn event(&mut self, ev: Event) {
|
||||||
trace!("event: {:?}", ev);
|
trace!("event: {:?}", ev);
|
||||||
|
|
||||||
|
if self.check_quit(ev) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut flags = NeedsUpdate::empty();
|
let mut flags = NeedsUpdate::empty();
|
||||||
|
|
||||||
if event_pump(ev, self.components_mut().as_mut_slice()) {
|
if event_pump(ev, self.components_mut().as_mut_slice()) {
|
||||||
|
|
@ -110,8 +114,6 @@ impl App {
|
||||||
flags.insert(new_flags);
|
flags.insert(new_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.check_quit(ev);
|
|
||||||
|
|
||||||
let new_flags = self.process_queue();
|
let new_flags = self.process_queue();
|
||||||
flags.insert(new_flags);
|
flags.insert(new_flags);
|
||||||
|
|
||||||
|
|
@ -163,12 +165,14 @@ impl App {
|
||||||
impl App {
|
impl App {
|
||||||
accessors!(self, [msg, reset, commit, help, revlog, status_tab]);
|
accessors!(self, [msg, reset, commit, help, revlog, status_tab]);
|
||||||
|
|
||||||
fn check_quit(&mut self, ev: Event) {
|
fn check_quit(&mut self, ev: Event) -> bool {
|
||||||
if let Event::Key(e) = ev {
|
if let Event::Key(e) = ev {
|
||||||
if let keys::EXIT = e {
|
if let keys::EXIT = e {
|
||||||
self.do_quit = true;
|
self.do_quit = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_tabs(&mut self) {
|
fn toggle_tabs(&mut self) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
strings, ui,
|
strings, ui,
|
||||||
};
|
};
|
||||||
use asyncgit::{sync, CWD};
|
use asyncgit::{sync, CWD};
|
||||||
use crossterm::event::{Event, KeyCode, KeyModifiers};
|
use crossterm::event::{Event, KeyCode};
|
||||||
use log::error;
|
use log::error;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use strings::commands;
|
use strings::commands;
|
||||||
|
|
@ -76,17 +76,11 @@ impl Component for CommitComponent {
|
||||||
fn event(&mut self, ev: Event) -> bool {
|
fn event(&mut self, ev: Event) -> bool {
|
||||||
if self.visible {
|
if self.visible {
|
||||||
if let Event::Key(e) = ev {
|
if let Event::Key(e) = ev {
|
||||||
let has_ctrl =
|
|
||||||
e.modifiers.contains(KeyModifiers::CONTROL);
|
|
||||||
match e.code {
|
match e.code {
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
self.hide();
|
self.hide();
|
||||||
}
|
}
|
||||||
KeyCode::Char(c) => {
|
KeyCode::Char(c) => {
|
||||||
// ignore and early out on ctrl+c
|
|
||||||
if c == 'c' && has_ctrl {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
self.msg.push(c);
|
self.msg.push(c);
|
||||||
}
|
}
|
||||||
KeyCode::Enter if self.can_commit() => {
|
KeyCode::Enter if self.can_commit() => {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
strings, ui,
|
strings, ui,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crossterm::event::{Event, KeyCode, KeyModifiers};
|
use crossterm::event::{Event, KeyCode};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use strings::commands;
|
use strings::commands;
|
||||||
use tui::{
|
use tui::{
|
||||||
|
|
@ -74,13 +74,6 @@ impl Component for ResetComponent {
|
||||||
if self.visible {
|
if self.visible {
|
||||||
if let Event::Key(e) = ev {
|
if let Event::Key(e) = ev {
|
||||||
return match e.code {
|
return match e.code {
|
||||||
KeyCode::Char(c) => {
|
|
||||||
// ignore and early out on ctrl+c
|
|
||||||
!(c == 'c'
|
|
||||||
&& e.modifiers
|
|
||||||
.contains(KeyModifiers::CONTROL))
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
self.hide();
|
self.hide();
|
||||||
true
|
true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue