Skip to content

Commit 9e556a1

Browse files
committed
TUI refactor
1 parent bb03f78 commit 9e556a1

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/textui/mod.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ pub enum AppWidgets {
3131
}
3232

3333
pub struct App {
34-
/// Status messages presented in the UI
35-
messages: Vec<String>,
3634
/// Holds the active widget
3735
active_widget: AppWidgets,
38-
/// Browser for actions on a single file
39-
file_action: StatefulList<String>,
4036
/// Set to true when UI is unresponsive
4137
busy: bool,
38+
/// Browser for files CBM disk images (d81 etc)
39+
cbm_browser: StatefulList<String>,
40+
/// Selected CBM disk
41+
cbm_disk: Option<Box<dyn cbm::disk::Disk>>,
42+
/// Browser for actions on a single file
43+
file_action: StatefulList<String>,
4244
/// FileHost file browser
43-
pub filetable: StatefulTable<filehost::Record>,
45+
filetable: StatefulTable<filehost::Record>,
46+
/// Status messages presented in the UI
47+
messages: Vec<String>,
4448
/// Serial port to communicate on
45-
pub port: Box<dyn SerialPort>,
49+
port: Box<dyn SerialPort>,
4650
/// Determines how to sort the filehost table
4751
toggle_sort: bool,
48-
/// Selected CBM disk
49-
pub cbm_disk: Option<Box<dyn cbm::disk::Disk>>,
50-
/// Browser for files CBM disk images (d81 etc)
51-
pub cbm_browser: StatefulList<String>,
5252
}
5353

5454
impl App {
@@ -95,16 +95,10 @@ impl App {
9595
Ok(())
9696
}
9797

98-
// todo this should be moved to ui.rs
98+
// @todo this should be moved to ui.rs so that mod.rs is independent of crossterm
9999
pub fn keypress(&mut self, key: crossterm::event::KeyCode) -> Result<()> {
100100
match key {
101-
KeyCode::Char('h') => {
102-
if self.active_widget != AppWidgets::Help {
103-
self.set_current_widget(AppWidgets::Help);
104-
} else {
105-
self.set_current_widget(AppWidgets::FileSelector);
106-
}
107-
}
101+
KeyCode::Char('h') => self.toggle_help(),
108102

109103
// Escape jumps back to filehost selector
110104
KeyCode::Esc => {
@@ -189,15 +183,24 @@ impl App {
189183
}
190184
}
191185

186+
/// Toggles the help pop-up
187+
fn toggle_help(&mut self) {
188+
if self.active_widget != AppWidgets::Help {
189+
self.set_current_widget(AppWidgets::Help);
190+
} else {
191+
self.set_current_widget(AppWidgets::FileSelector);
192+
}
193+
}
194+
192195
/// Set OK message if previous message is something else
193-
pub fn _ok_message(&mut self) {
196+
fn _ok_message(&mut self) {
194197
let ok_text = "Ready".to_string();
195198
if *self.messages.last().unwrap() != ok_text {
196199
self.messages.push(ok_text);
197200
}
198201
}
199202

200-
pub fn add_message(&mut self, message: &str) {
203+
fn add_message(&mut self, message: &str) {
201204
self.messages.push(message.to_string());
202205
}
203206

@@ -247,4 +250,3 @@ impl App {
247250
Ok(())
248251
}
249252
}
250-

src/textui/ui.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ use tui::{
1717
layout::{Alignment, Constraint, Direction, Layout, Rect},
1818
style::{Color, Modifier, Style},
1919
text::{Span, Spans},
20-
widgets::{Block, BorderType, Borders, Cell, Clear, List, ListItem, ListState, Paragraph, Row, Table, TableState},
20+
widgets::{
21+
Block, BorderType, Borders, Cell, Clear, List, ListItem, ListState, Paragraph, Row, Table,
22+
TableState,
23+
},
2124
Frame,
2225
};
2326

0 commit comments

Comments
 (0)