Added command queue access to event handlers
This commit is contained in:
parent
6834194b9e
commit
ec8f43e79c
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "grex_terminal_display"
|
name = "grex_terminal_display"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -8,7 +8,7 @@ use bevy::{
|
|||||||
prelude::*, utils::tracing::level_filters::LevelFilter,
|
prelude::*, utils::tracing::level_filters::LevelFilter,
|
||||||
};
|
};
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::DisableMouseCapture,
|
event::{DisableMouseCapture, PopKeyboardEnhancementFlags},
|
||||||
terminal::{disable_raw_mode, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, LeaveAlternateScreen},
|
||||||
ExecutableCommand,
|
ExecutableCommand,
|
||||||
};
|
};
|
||||||
@ -66,6 +66,7 @@ impl Plugin for TerminalDisplayPlugin {
|
|||||||
impl Drop for TerminalDisplayPlugin {
|
impl Drop for TerminalDisplayPlugin {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let mut stdout = stdout();
|
let mut stdout = stdout();
|
||||||
|
let _ = stdout.execute(PopKeyboardEnhancementFlags);
|
||||||
let _ = stdout.execute(DisableMouseCapture);
|
let _ = stdout.execute(DisableMouseCapture);
|
||||||
let _ = stdout.execute(LeaveAlternateScreen);
|
let _ = stdout.execute(LeaveAlternateScreen);
|
||||||
let _ = disable_raw_mode();
|
let _ = disable_raw_mode();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::{sync::{Arc, Mutex}, io::{stdout, Stdout}, fs::{File, OpenOptions}};
|
use std::{sync::{Arc, Mutex}, io::{stdout, Stdout}, fs::{File, OpenOptions}};
|
||||||
|
|
||||||
use bevy::{prelude::*, utils::{HashSet, Uuid, HashMap, tracing::{subscriber, level_filters::LevelFilter}}, log::tracing_subscriber};
|
use bevy::{prelude::*, utils::{HashSet, Uuid, HashMap, tracing::{subscriber, level_filters::LevelFilter}}, log::tracing_subscriber};
|
||||||
use crossterm::{event::{Event, KeyCode, EnableMouseCapture}, terminal::{EnterAlternateScreen, enable_raw_mode}, ExecutableCommand};
|
use crossterm::{event::{Event, KeyCode, EnableMouseCapture, PushKeyboardEnhancementFlags, KeyboardEnhancementFlags}, terminal::{EnterAlternateScreen, enable_raw_mode}, ExecutableCommand};
|
||||||
use ratatui::{backend::CrosstermBackend, Frame, layout::Rect};
|
use ratatui::{backend::CrosstermBackend, Frame, layout::Rect};
|
||||||
|
|
||||||
use crate::events::TerminalInputEvent;
|
use crate::events::TerminalInputEvent;
|
||||||
@ -47,6 +47,7 @@ impl Default for Terminal {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
stdout().execute(EnterAlternateScreen).unwrap();
|
stdout().execute(EnterAlternateScreen).unwrap();
|
||||||
stdout().execute(EnableMouseCapture).unwrap();
|
stdout().execute(EnableMouseCapture).unwrap();
|
||||||
|
stdout().execute(PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::REPORT_EVENT_TYPES)).unwrap();
|
||||||
enable_raw_mode().unwrap();
|
enable_raw_mode().unwrap();
|
||||||
let mut terminal = ratatui::Terminal::new(CrosstermBackend::new(stdout())).expect("Failed to create terminal");
|
let mut terminal = ratatui::Terminal::new(CrosstermBackend::new(stdout())).expect("Failed to create terminal");
|
||||||
terminal.clear().expect("Failed to clear terminal");
|
terminal.clear().expect("Failed to clear terminal");
|
||||||
@ -85,6 +86,6 @@ pub trait TerminalWidget {
|
|||||||
fn init(&mut self) {}
|
fn init(&mut self) {}
|
||||||
fn update(&mut self) {}
|
fn update(&mut self) {}
|
||||||
fn render(&mut self, frame: &mut Frame, rect: Rect);
|
fn render(&mut self, frame: &mut Frame, rect: Rect);
|
||||||
fn handle_events(&mut self, _event: &TerminalInputEvent) {}
|
fn handle_events(&mut self, _event: &TerminalInputEvent, commands: &mut Commands) {}
|
||||||
fn depth(&self) -> u32 { 0 }
|
fn depth(&self) -> u32 { 0 }
|
||||||
}
|
}
|
||||||
|
@ -119,10 +119,11 @@ fn braille_char(mask: u8) -> char {
|
|||||||
pub fn widget_input_handling(
|
pub fn widget_input_handling(
|
||||||
mut terminal_ui: ResMut<TerminalUI>,
|
mut terminal_ui: ResMut<TerminalUI>,
|
||||||
mut event_reader: EventReader<TerminalInputEvent>,
|
mut event_reader: EventReader<TerminalInputEvent>,
|
||||||
|
mut commands: Commands,
|
||||||
) {
|
) {
|
||||||
for event in event_reader.read() {
|
for event in event_reader.read() {
|
||||||
for widget in terminal_ui.widgets().iter_mut() {
|
for widget in terminal_ui.widgets().iter_mut() {
|
||||||
widget.handle_events(event);
|
widget.handle_events(event, &mut commands);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user