mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-30 00:55:00 +02:00
Quit functionality
This commit is contained in:
parent
b304db6a2f
commit
56a9856796
26
src/app.rs
26
src/app.rs
@ -203,6 +203,10 @@ impl AppState {
|
|||||||
// TODO: Redraw
|
// TODO: Redraw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn quit(&mut self) {
|
||||||
|
self.terminator.store(true, SeqCst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for AppState {
|
impl Application for AppState {
|
||||||
@ -264,9 +268,27 @@ impl Application for AppState {
|
|||||||
&mut self, event: crate::tuine::Event, _messages: &mut Vec<Self::Message>,
|
&mut self, event: crate::tuine::Event, _messages: &mut Vec<Self::Message>,
|
||||||
) {
|
) {
|
||||||
use crate::tuine::Event;
|
use crate::tuine::Event;
|
||||||
|
use crossterm::event::{KeyCode, KeyModifiers};
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::Keyboard(_) => {}
|
Event::Keyboard(event) => {
|
||||||
Event::Mouse(_) => {}
|
if event.modifiers.is_empty() {
|
||||||
|
match event.code {
|
||||||
|
KeyCode::Char('q') | KeyCode::Char('Q') => {
|
||||||
|
self.quit();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
} else if let KeyModifiers::CONTROL = event.modifiers {
|
||||||
|
match event.code {
|
||||||
|
KeyCode::Char('c') | KeyCode::Char('C') => {
|
||||||
|
self.quit();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Event::Mouse(event) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handles a [`Event`].
|
||||||
fn on_event<A>(
|
fn on_event<A>(
|
||||||
application: &mut A, user_interface: &mut Element<'_, A::Message>, app_data: &mut AppData,
|
application: &mut A, user_interface: &mut Element<'_, A::Message>, app_data: &mut AppData,
|
||||||
layout: &mut LayoutNode, event: Event,
|
layout: &mut LayoutNode, event: Event,
|
||||||
@ -98,6 +99,7 @@ fn on_event<A>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a new [`Element`] representing the root of the user interface.
|
||||||
fn new_user_interface<A>(
|
fn new_user_interface<A>(
|
||||||
application: &mut A, app_data: &mut AppData,
|
application: &mut A, app_data: &mut AppData,
|
||||||
) -> Element<'static, A::Message>
|
) -> Element<'static, A::Message>
|
||||||
@ -108,6 +110,7 @@ where
|
|||||||
application.view(&mut ctx)
|
application.view(&mut ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates the layout, and draws the given user interface.
|
||||||
fn draw<M, B>(
|
fn draw<M, B>(
|
||||||
user_interface: &mut Element<'_, M>, terminal: &mut Terminal<B>, app_data: &mut AppData,
|
user_interface: &mut Element<'_, M>, terminal: &mut Terminal<B>, app_data: &mut AppData,
|
||||||
layout: &mut LayoutNode,
|
layout: &mut LayoutNode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user