Skip to content

Commit a599f4e

Browse files
committed
Output Improvements
* Add output page, all output is now cached * cleanup tabs, now they use functions keys and smaller description text
1 parent 2a0d81d commit a599f4e

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

images/screenshot.png

4.52 KB
Loading

src/main.rs

+48-23
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use env_logger::{Builder, Env};
1212
use log::debug;
1313
use ratatui::layout::{Constraint, Layout};
1414
use ratatui::prelude::*;
15-
use ratatui::style::Styled;
1615
use ratatui::widgets::block::Title;
1716
use ratatui::widgets::{Cell, Row, Table, TableState};
1817
use ratatui::{
@@ -25,13 +24,13 @@ use ratatui::{
2524
};
2625
use tui_input::backend::crossterm::EventHandler;
2726
use tui_input::Input;
28-
use Constraint::{Fill, Length, Max, Min};
27+
use Constraint::{Fill, Length, Min};
2928

3029
mod mi;
3130
use mi::{
32-
data_disassemble, data_read_memory_bytes, data_read_sp_bytes, join_registers,
33-
parse_asm_insns_values, parse_key_value_pairs, parse_register_names_values,
34-
parse_register_values, read_pc_value, Asm, MIResponse, Register,
31+
data_disassemble, data_read_sp_bytes, join_registers, parse_asm_insns_values,
32+
parse_key_value_pairs, parse_register_names_values, parse_register_values, read_pc_value, Asm,
33+
MIResponse, Register,
3534
};
3635

3736
enum InputMode {
@@ -100,6 +99,7 @@ enum Mode {
10099
OnlyRegister,
101100
OnlyStack,
102101
OnlyInstructions,
102+
OnlyOutput,
103103
}
104104

105105
struct App {
@@ -108,7 +108,7 @@ struct App {
108108
input_mode: InputMode,
109109
messages: LimitedBuffer<String>,
110110
current_pc: Arc<Mutex<u64>>, // TODO: replace with AtomicU64?
111-
output: Arc<Mutex<LimitedBuffer<String>>>,
111+
output: Arc<Mutex<Vec<String>>>,
112112
gdb_stdin: Arc<Mutex<dyn Write + Send>>,
113113
register_names: Arc<Mutex<Vec<String>>>,
114114
registers: Arc<Mutex<Vec<(String, Option<Register>)>>>,
@@ -161,7 +161,7 @@ impl App {
161161
input_mode: InputMode::Normal,
162162
messages: LimitedBuffer::new(10),
163163
current_pc: Arc::new(Mutex::new(0)),
164-
output: Arc::new(Mutex::new(LimitedBuffer::new(SAVED_OUTPUT - 3))),
164+
output: Arc::new(Mutex::new(Vec::new())),
165165
register_names: Arc::new(Mutex::new(vec![])),
166166
gdb_stdin,
167167
registers: Arc::new(Mutex::new(vec![])),
@@ -244,7 +244,7 @@ fn gdb_interact(
244244
stack_arc: Arc<Mutex<HashMap<u64, u64>>>,
245245
asm_arc: Arc<Mutex<Vec<Asm>>>,
246246
gdb_stdin_arc: Arc<Mutex<dyn Write + Send>>,
247-
output_arc: Arc<Mutex<LimitedBuffer<String>>>,
247+
output_arc: Arc<Mutex<Vec<String>>>,
248248
) {
249249
let mut next_write = vec![String::new()];
250250
for line in gdb_stdout.lines() {
@@ -382,18 +382,21 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: &mut App) -> io::Result<
382382
(InputMode::Normal, KeyCode::Char('q')) => {
383383
return Ok(());
384384
}
385-
(InputMode::Normal, KeyCode::Char('0')) => {
385+
(InputMode::Normal, KeyCode::F(1)) => {
386386
app.mode = Mode::All;
387387
}
388-
(InputMode::Normal, KeyCode::Char('1')) => {
388+
(InputMode::Normal, KeyCode::F(2)) => {
389389
app.mode = Mode::OnlyRegister;
390390
}
391-
(InputMode::Normal, KeyCode::Char('2')) => {
391+
(InputMode::Normal, KeyCode::F(3)) => {
392392
app.mode = Mode::OnlyStack;
393393
}
394-
(InputMode::Normal, KeyCode::Char('3')) => {
394+
(InputMode::Normal, KeyCode::F(4)) => {
395395
app.mode = Mode::OnlyInstructions;
396396
}
397+
(InputMode::Normal, KeyCode::F(5)) => {
398+
app.mode = Mode::OnlyOutput;
399+
}
397400
(InputMode::Editing, KeyCode::Esc) => {
398401
app.input_mode = InputMode::Normal;
399402
}
@@ -475,6 +478,20 @@ fn update_from_previous_input(app: &mut App) {
475478
fn ui(f: &mut Frame, app: &App) {
476479
// TODO: register size should depend on arch
477480
let top_size = Fill(1);
481+
482+
// If only output, then no top and fill all with output
483+
if let Mode::OnlyOutput = app.mode {
484+
let output_size = Fill(1);
485+
let vertical = Layout::vertical([Length(1), output_size, Length(3)]);
486+
let [title_area, output, input] = vertical.areas(f.area());
487+
488+
draw_title_area(app, f, title_area);
489+
draw_output(app, f, output);
490+
draw_input(title_area, app, f, input);
491+
return;
492+
}
493+
494+
// the rest will include the top
478495
let output_size = Length(SAVED_OUTPUT as u16);
479496

480497
let vertical = Layout::vertical([Length(1), top_size, output_size, Length(3)]);
@@ -511,6 +528,7 @@ fn ui(f: &mut Frame, app: &App) {
511528
let [all] = vertical.areas(top);
512529
draw_asm(app, f, all);
513530
}
531+
_ => (),
514532
}
515533
}
516534

@@ -551,15 +569,20 @@ fn draw_input(title_area: Rect, app: &App, f: &mut Frame, input: Rect) {
551569

552570
fn draw_output(app: &App, f: &mut Frame, output: Rect) {
553571
let output_lock = app.output.lock().unwrap();
554-
let messages: Vec<ListItem> = output_lock
555-
.buffer
572+
573+
let len = output_lock.len();
574+
let max = output.height;
575+
let output_buf =
576+
if len <= max as usize { &output_lock[..] } else { &output_lock[len - max as usize..] };
577+
578+
let outputs: Vec<ListItem> = output_buf
556579
.iter()
557580
.map(|m| {
558581
let content = vec![Line::from(Span::raw(format!("{}", m)))];
559582
ListItem::new(content)
560583
})
561584
.collect();
562-
let output_block = List::new(messages).block(
585+
let output_block = List::new(outputs).block(
563586
Block::default()
564587
.borders(Borders::ALL)
565588
.title("Output".fg(BLUE).add_modifier(Modifier::BOLD)),
@@ -645,14 +668,16 @@ fn draw_title_area(app: &App, f: &mut Frame, title_area: Rect) {
645668
Span::raw(" to exit, "),
646669
Span::styled("i", Style::default().add_modifier(Modifier::BOLD)),
647670
Span::raw(" to enter input | "),
648-
Span::styled("0", Style::default().add_modifier(Modifier::BOLD)),
649-
Span::raw(" to have all displays | "),
650-
Span::styled("1", Style::default().add_modifier(Modifier::BOLD)),
651-
Span::raw(" to have display registers | "),
652-
Span::styled("2", Style::default().add_modifier(Modifier::BOLD)),
653-
Span::raw(" to have display stacks | "),
654-
Span::styled("3", Style::default().add_modifier(Modifier::BOLD)),
655-
Span::raw(" to have display instructions"),
671+
Span::styled("F1", Style::default().add_modifier(Modifier::BOLD)),
672+
Span::raw(" displays | "),
673+
Span::styled("F2", Style::default().add_modifier(Modifier::BOLD)),
674+
Span::raw(" registers | "),
675+
Span::styled("F3", Style::default().add_modifier(Modifier::BOLD)),
676+
Span::raw(" stacks | "),
677+
Span::styled("F4", Style::default().add_modifier(Modifier::BOLD)),
678+
Span::raw(" instructions | "),
679+
Span::styled("F5", Style::default().add_modifier(Modifier::BOLD)),
680+
Span::raw(" output"),
656681
],
657682
Style::default().add_modifier(Modifier::RAPID_BLINK),
658683
),

0 commit comments

Comments
 (0)