mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-23 13:29:48 -04:00
wip: Informative help text
This commit is contained in:
parent
4ac9c4361f
commit
a361b7a87b
@ -5,7 +5,6 @@ use std::{
|
|||||||
io::Read,
|
io::Read,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::ExitCode,
|
process::ExitCode,
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::sheet::{Address, Tbl};
|
use super::sheet::{Address, Tbl};
|
||||||
@ -17,13 +16,11 @@ use ratatui::{
|
|||||||
layout::{Constraint, Flex, Layout},
|
layout::{Constraint, Flex, Layout},
|
||||||
style::{Color, Modifier, Style, Stylize},
|
style::{Color, Modifier, Style, Stylize},
|
||||||
text::{Line, Text},
|
text::{Line, Text},
|
||||||
widgets::{Block, Cell, Row, Table, Widget},
|
widgets::{Block, Cell, Paragraph, Row, Table, Widget},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use tui_textarea::{CursorMove, TextArea};
|
use tui_textarea::{CursorMove, TextArea};
|
||||||
|
|
||||||
const DEFAULT_KEY_TIMEOUT: Duration = Duration::from_millis(30);
|
|
||||||
|
|
||||||
#[derive(Default, Debug, PartialEq)]
|
#[derive(Default, Debug, PartialEq)]
|
||||||
pub enum Modality {
|
pub enum Modality {
|
||||||
#[default]
|
#[default]
|
||||||
@ -131,6 +128,14 @@ impl<'ws> Workspace<'ws> {
|
|||||||
Ok(None)
|
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>> {
|
fn handle_edit_input(&mut self, key: event::KeyEvent) -> Result<Option<ExitCode>> {
|
||||||
if key.kind == KeyEventKind::Press {
|
if key.kind == KeyEventKind::Press {
|
||||||
if let KeyCode::Esc = key.code {
|
if let KeyCode::Esc = key.code {
|
||||||
@ -242,8 +247,8 @@ impl<'widget, 'ws: 'widget> Widget for &'widget Workspace<'ws> {
|
|||||||
))
|
))
|
||||||
.right_aligned(),
|
.right_aligned(),
|
||||||
);
|
);
|
||||||
let [edit_rect, table_rect] =
|
let [edit_rect, table_rect, info_rect] =
|
||||||
Layout::vertical(&[Constraint::Fill(1), Constraint::Fill(20)])
|
Layout::vertical(&[Constraint::Fill(1), Constraint::Fill(20), Constraint::Fill(3)])
|
||||||
.vertical_margin(2)
|
.vertical_margin(2)
|
||||||
.horizontal_margin(2)
|
.horizontal_margin(2)
|
||||||
.flex(Flex::Legacy)
|
.flex(Flex::Legacy)
|
||||||
@ -253,6 +258,9 @@ impl<'widget, 'ws: 'widget> Widget for &'widget Workspace<'ws> {
|
|||||||
let table_block = Block::bordered();
|
let table_block = Block::bordered();
|
||||||
let table = Table::from(&self.tbl).block(table_block);
|
let table = Table::from(&self.tbl).block(table_block);
|
||||||
table.render(table_rect, buf);
|
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