mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-22 21:09:48 -04:00
wip: Informative help text
This commit is contained in:
parent
4ac9c4361f
commit
a361b7a87b
@ -5,7 +5,6 @@ use std::{
|
||||
io::Read,
|
||||
path::PathBuf,
|
||||
process::ExitCode,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use super::sheet::{Address, Tbl};
|
||||
@ -17,13 +16,11 @@ use ratatui::{
|
||||
layout::{Constraint, Flex, Layout},
|
||||
style::{Color, Modifier, Style, Stylize},
|
||||
text::{Line, Text},
|
||||
widgets::{Block, Cell, Row, Table, Widget},
|
||||
widgets::{Block, Cell, Paragraph, Row, Table, Widget},
|
||||
Frame,
|
||||
};
|
||||
use tui_textarea::{CursorMove, TextArea};
|
||||
|
||||
const DEFAULT_KEY_TIMEOUT: Duration = Duration::from_millis(30);
|
||||
|
||||
#[derive(Default, Debug, PartialEq)]
|
||||
pub enum Modality {
|
||||
#[default]
|
||||
@ -131,6 +128,14 @@ impl<'ws> Workspace<'ws> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn render_help_text(&self) -> impl Widget {
|
||||
let info_block = Block::bordered().title("Help");
|
||||
Paragraph::new(match self.state.modality {
|
||||
Modality::Navigate => "Navigate Mode:\n* e: Enter edit mode for current cell\n* h,j,k,l: vim style navigation\n* q exit\n* Ctrl-S Save sheet",
|
||||
Modality::CellEdit => "Edit Mode:\n ESC: Exit edit mode\nOtherwise edit as normal",
|
||||
}).block(info_block)
|
||||
}
|
||||
|
||||
fn handle_edit_input(&mut self, key: event::KeyEvent) -> Result<Option<ExitCode>> {
|
||||
if key.kind == KeyEventKind::Press {
|
||||
if let KeyCode::Esc = key.code {
|
||||
@ -242,8 +247,8 @@ impl<'widget, 'ws: 'widget> Widget for &'widget Workspace<'ws> {
|
||||
))
|
||||
.right_aligned(),
|
||||
);
|
||||
let [edit_rect, table_rect] =
|
||||
Layout::vertical(&[Constraint::Fill(1), Constraint::Fill(20)])
|
||||
let [edit_rect, table_rect, info_rect] =
|
||||
Layout::vertical(&[Constraint::Fill(1), Constraint::Fill(20), Constraint::Fill(3)])
|
||||
.vertical_margin(2)
|
||||
.horizontal_margin(2)
|
||||
.flex(Flex::Legacy)
|
||||
@ -253,6 +258,9 @@ impl<'widget, 'ws: 'widget> Widget for &'widget Workspace<'ws> {
|
||||
let table_block = Block::bordered();
|
||||
let table = Table::from(&self.tbl).block(table_block);
|
||||
table.render(table_rect, buf);
|
||||
// TODO(jwall): render help text?
|
||||
let info_para = self.render_help_text();
|
||||
info_para.render(info_rect, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user