Browse Source

Removed the Unicode character, so it works fine on Windows

master
Julio Biason 9 months ago
parent
commit
0e827b5460
  1. 15
      ratatuitest/src/main.rs

15
ratatuitest/src/main.rs

@ -14,13 +14,13 @@ use ratatui::Frame;
use ratatui::Terminal; use ratatui::Terminal;
use std::error::Error; use std::error::Error;
struct Cursor { struct Selector {
pub state: ListState, pub state: ListState,
pub values: Vec<String>, pub values: Vec<String>,
pub selected: Vec<usize>, pub selected: Vec<usize>,
} }
impl Cursor { impl Selector {
pub fn new(values: Vec<String>) -> Self { pub fn new(values: Vec<String>) -> Self {
Self { Self {
state: ListState::default().with_selected(Some(0)), state: ListState::default().with_selected(Some(0)),
@ -89,7 +89,7 @@ fn main() -> Result<(), Box<dyn Error>> {
} }
let cursor_pos = terminal.get_cursor().unwrap(); let cursor_pos = terminal.get_cursor().unwrap();
let mut options = Cursor::new(vec![ let mut options = Selector::new(vec![
"Option 1".into(), "Option 1".into(),
"Option 2".into(), "Option 2".into(),
"Option 3".into(), "Option 3".into(),
@ -112,7 +112,7 @@ fn main() -> Result<(), Box<dyn Error>> {
fn run_app<B: Backend>( fn run_app<B: Backend>(
terminal: &mut Terminal<B>, terminal: &mut Terminal<B>,
pos: &Rect, pos: &Rect,
values: &mut Cursor, values: &mut Selector,
) -> std::io::Result<()> { ) -> std::io::Result<()> {
loop { loop {
terminal.draw(|f| ui(f, pos, values))?; terminal.draw(|f| ui(f, pos, values))?;
@ -136,7 +136,7 @@ fn run_app<B: Backend>(
Ok(()) Ok(())
} }
fn ui<B: Backend>(f: &mut Frame<B>, pos: &Rect, cursor: &mut Cursor) { fn ui<B: Backend>(f: &mut Frame<B>, pos: &Rect, cursor: &mut Selector) {
let items = cursor let items = cursor
.values .values
.iter() .iter()
@ -145,16 +145,15 @@ fn ui<B: Backend>(f: &mut Frame<B>, pos: &Rect, cursor: &mut Cursor) {
ListItem::new(format!( ListItem::new(format!(
"{} {}", "{} {}",
if cursor.selected.contains(&pos) { if cursor.selected.contains(&pos) {
"" "[x]"
} else { } else {
"" "[ ]"
}, },
desc.to_string() desc.to_string()
)) ))
}) })
.collect::<Vec<ListItem>>(); .collect::<Vec<ListItem>>();
let list = List::new(items) let list = List::new(items)
// .block(Block::default().borders(Borders::ALL))
.highlight_style(Style::default().add_modifier(Modifier::BOLD)) .highlight_style(Style::default().add_modifier(Modifier::BOLD))
.highlight_symbol("> "); .highlight_symbol("> ");
f.render_stateful_widget(list, *pos, &mut cursor.state); f.render_stateful_widget(list, *pos, &mut cursor.state);

Loading…
Cancel
Save