mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-05 21:28:48 +00:00
perfect menu
This commit is contained in:
parent
35ddfa02c6
commit
f6f958f92c
|
@ -26,19 +26,31 @@ fn main() -> Result<()> {
|
||||||
// Draw UI components on each iteration.
|
// Draw UI components on each iteration.
|
||||||
terminal.draw(|frame| {
|
terminal.draw(|frame| {
|
||||||
let area = frame.size();
|
let area = frame.size();
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints([Constraint::Length(items.len() as u16 + 1), Constraint::Min(0)])
|
||||||
|
.split(area);
|
||||||
let list = List::new(items)
|
let list = List::new(items)
|
||||||
.block(Block::default().title("List").borders(Borders::ALL))
|
.block(Block::default().title("List").borders(Borders::ALL))
|
||||||
.highlight_style(Style::new().add_modifier(Modifier::REVERSED))
|
.highlight_style(Style::new().add_modifier(Modifier::REVERSED))
|
||||||
.highlight_symbol(">>")
|
.highlight_symbol(">>")
|
||||||
.repeat_highlight_symbol(true);
|
.repeat_highlight_symbol(true);
|
||||||
|
let command_block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.style(Style::default().bg(Color::Black).fg(Color::White))
|
||||||
|
.title("Terminal");
|
||||||
// Render the list and a paragraph widget.
|
// Render the list and a paragraph widget.
|
||||||
frame.render_stateful_widget(list, area, &mut state);
|
frame.render_stateful_widget(list, area, &mut state);
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new("The Linux Toolbox (press 'q' to quit)")
|
Paragraph::new("The Linux Toolbox (press 'q' to quit)")
|
||||||
.style(Style::default().bg(Color::Blue).fg(Color::White).add_modifier(Modifier::BOLD)),
|
.style(Style::default().bg(Color::Blue).fg(Color::White).add_modifier(Modifier::BOLD)),
|
||||||
area,
|
chunks[0],
|
||||||
);
|
);
|
||||||
|
frame.render_widget(
|
||||||
|
command_block,
|
||||||
|
chunks[1],
|
||||||
|
);
|
||||||
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Handle keyboard input.
|
// Handle keyboard input.
|
||||||
|
@ -46,21 +58,45 @@ fn main() -> Result<()> {
|
||||||
if let event::Event::Key(key) = event::read()? {
|
if let event::Event::Key(key) = event::read()? {
|
||||||
match key.kind {
|
match key.kind {
|
||||||
KeyEventKind::Press | KeyEventKind::Repeat => match key.code {
|
KeyEventKind::Press | KeyEventKind::Repeat => match key.code {
|
||||||
KeyCode::Char('j') => {
|
KeyCode::Char('j') | KeyCode::Down => {
|
||||||
// Move selection down in the list.
|
// Move selection down in the list.
|
||||||
let selected = state.selected().unwrap_or(0);
|
let selected = state.selected().unwrap_or(0);
|
||||||
state.select(Some((selected + 1).min(items.len() - 1)));
|
state.select(Some((selected + 1).min(items.len() - 1)));
|
||||||
}
|
}
|
||||||
KeyCode::Char('k') => {
|
KeyCode::Char('k') | KeyCode::Up => {
|
||||||
// Move selection up in the list.
|
// Move selection up in the list.
|
||||||
let selected = state.selected().unwrap_or(0);
|
let selected = state.selected().unwrap_or(0);
|
||||||
state.select(Some(selected.saturating_sub(1)));
|
state.select(Some(selected.saturating_sub(1)));
|
||||||
}
|
}
|
||||||
|
KeyCode::Enter => {
|
||||||
|
// Handle the enter key
|
||||||
|
if let Some(index) = state.selected() {
|
||||||
|
match items[index] {
|
||||||
|
"MyBash" => {
|
||||||
|
// Handle the "MyBash" item selected.
|
||||||
|
use std::process::Command;
|
||||||
|
println!("Launching terminal and cloning MyBash repository...");
|
||||||
|
Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg("mkdir -p ~/build/mybash && cd ~/build/mybash && git clone https://github.com/christitustech/mybash")
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to launch terminal and execute git clone command.");
|
||||||
|
}
|
||||||
|
"Neovim" => {
|
||||||
|
// Handle the "Neovim" item selected.
|
||||||
|
}
|
||||||
|
"Quit" => {
|
||||||
|
// Handle the "Quit" item selected.
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
KeyCode::Char('q') => {
|
KeyCode::Char('q') => {
|
||||||
// Exit the loop and close the application.
|
// Exit the loop and close the application.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (), // This line is a catch-all pattern that does nothing for all other unhandled key codes.
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user