1use crate::input::{KeyPress, OscHandler};
2
3pub trait TerminalApp {
5 type Command: From<KeyPress>;
7
8 fn render(&self, frame: &mut ratatui::Frame);
10
11 fn handle_input(&mut self, cmd: Self::Command) -> bool;
13
14 fn tick(&mut self, delta_ms: u64) -> bool;
16
17 fn should_quit(&self) -> bool;
19
20 fn input_extensions(&self) -> Vec<OscHandler<Self::Command>> {
22 vec![]
23 }
24}
25
26pub struct TerminalConfig {
28 pub cols: u16,
29 pub rows: u16,
30 pub fps: u16,
31 pub heartbeat: bool,
32 pub buf_capacity: usize,
33}
34
35impl Default for TerminalConfig {
36 fn default() -> Self {
37 Self::new()
38 }
39}
40
41impl TerminalConfig {
42 pub fn new() -> Self {
43 TerminalConfig {
44 cols: 80,
45 rows: 24,
46 fps: 30,
47 heartbeat: cfg!(target_os = "wasi"),
48 buf_capacity: if cfg!(target_os = "wasi") { 1024 } else { 8192 },
49 }
50 }
51
52 pub fn cols(mut self, cols: u16) -> Self {
53 self.cols = cols;
54 self
55 }
56
57 pub fn rows(mut self, rows: u16) -> Self {
58 self.rows = rows;
59 self
60 }
61
62 pub fn fps(mut self, fps: u16) -> Self {
63 self.fps = fps;
64 self
65 }
66
67 pub fn heartbeat(mut self, heartbeat: bool) -> Self {
68 self.heartbeat = heartbeat;
69 self
70 }
71
72 pub fn buf_capacity(mut self, capacity: usize) -> Self {
73 self.buf_capacity = capacity;
74 self
75 }
76}