simplify ctrl+c handling, its done first so no one can block it

This commit is contained in:
Stephan Dilly 2020-05-13 16:47:39 +02:00
parent 63630eb18d
commit e7f0db2941
3 changed files with 9 additions and 18 deletions

View file

@ -93,6 +93,10 @@ impl App {
pub fn event(&mut self, ev: Event) {
trace!("event: {:?}", ev);
if self.check_quit(ev) {
return;
}
let mut flags = NeedsUpdate::empty();
if event_pump(ev, self.components_mut().as_mut_slice()) {
@ -110,8 +114,6 @@ impl App {
flags.insert(new_flags);
}
self.check_quit(ev);
let new_flags = self.process_queue();
flags.insert(new_flags);
@ -163,12 +165,14 @@ impl App {
impl App {
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 keys::EXIT = e {
self.do_quit = true;
return true;
}
}
false
}
fn toggle_tabs(&mut self) {

View file

@ -7,7 +7,7 @@ use crate::{
strings, ui,
};
use asyncgit::{sync, CWD};
use crossterm::event::{Event, KeyCode, KeyModifiers};
use crossterm::event::{Event, KeyCode};
use log::error;
use std::borrow::Cow;
use strings::commands;
@ -76,17 +76,11 @@ impl Component for CommitComponent {
fn event(&mut self, ev: Event) -> bool {
if self.visible {
if let Event::Key(e) = ev {
let has_ctrl =
e.modifiers.contains(KeyModifiers::CONTROL);
match e.code {
KeyCode::Esc => {
self.hide();
}
KeyCode::Char(c) => {
// ignore and early out on ctrl+c
if c == 'c' && has_ctrl {
return false;
}
self.msg.push(c);
}
KeyCode::Enter if self.can_commit() => {

View file

@ -7,7 +7,7 @@ use crate::{
strings, ui,
};
use crossterm::event::{Event, KeyCode, KeyModifiers};
use crossterm::event::{Event, KeyCode};
use std::borrow::Cow;
use strings::commands;
use tui::{
@ -74,13 +74,6 @@ impl Component for ResetComponent {
if self.visible {
if let Event::Key(e) = ev {
return match e.code {
KeyCode::Char(c) => {
// ignore and early out on ctrl+c
!(c == 'c'
&& e.modifiers
.contains(KeyModifiers::CONTROL))
}
KeyCode::Esc => {
self.hide();
true