use std::io;
use tuika::prelude::*;
fn hints() -> KeyHints {
KeyHints::new([("↑/↓", "move"), ("enter", "select"), ("esc", "cancel")])
}
fn before(rows: &[Line<'static>], state: &SelectState) -> impl View {
let header = Text::new(vec![Line::from("Select an action")]);
let body = SelectList::new(rows.to_vec(), state);
AppShell::new(body)
.top_rule()
.header(header)
.top_rule()
.bottom_rule()
.footer(hints())
}
fn after<'rows>(rows: &'rows [Line<'static>], state: &SelectState) -> SelectionScreen<'rows> {
SelectionScreen::borrowed("Select an action", rows, state)
.leading_rule()
.trailing_rule()
.footer(hints())
}
fn main() -> io::Result<()> {
let rows = [
Line::from("Run command"),
Line::from("Delegate to agent"),
Line::from("Request permission"),
Line::from("Resume session"),
];
let mut state = SelectState::new();
state.select(Some(2));
let _before_still_compiles = before(&rows, &state);
write_once(
&mut io::stdout(),
&after(&rows, &state),
&Theme::default(),
OneShotOptions {
width: 54,
max_height: 9,
..OneShotOptions::default()
},
)
}