feat(tui): auto-wrap keybind lines, show profiles keybinds
This commit is contained in:
1 parent
b0738761c9
commit
9e65fb43d8
6 files changed
+100
-52
No files matched your search
@@ -226,10 +226,13 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut A
|
||||
.border_style(Style::default().fg(color));
|
||||
|
||||
if focused == FocusedArea::Account {
|
||||
block = block.title_bottom(
|
||||
super::popups::keybind_line(&[("⏎", " select"), ("a", " add"), ("d", " del")])
|
||||
.alignment(ratatui::layout::Alignment::Right),
|
||||
let lines = super::popups::keybind_lines_wrapped(
|
||||
&[("⏎", " select"), ("a", " add"), ("d", " del")],
|
||||
area.width.saturating_sub(2),
|
||||
);
|
||||
for line in lines {
|
||||
block = block.title_bottom(line);
|
||||
}
|
||||
}
|
||||
|
||||
let inner = block.inner(area);
|
||||
|
||||
+31
-15
@@ -138,49 +138,65 @@ pub fn render(
|
||||
block = block.title_top(sl);
|
||||
}
|
||||
|
||||
if is_focused {
|
||||
let kb: &[(&str, &str)] = match tab {
|
||||
let kb: Option<&[(&str, &str)]> = if is_focused {
|
||||
Some(match tab {
|
||||
ContentTab::Mods | ContentTab::ResourcePacks | ContentTab::Shaders => &[
|
||||
("j/k", " nav"),
|
||||
("j/k", " navigate"),
|
||||
("⏎", " toggle"),
|
||||
("S+⏎", " dir"),
|
||||
("Shift+⏎", " open dir"),
|
||||
("h/l", " tabs"),
|
||||
("/", " search"),
|
||||
],
|
||||
ContentTab::Worlds => &[
|
||||
("j/k", " nav"),
|
||||
("S+⏎", " dir"),
|
||||
("j/k", " navigate"),
|
||||
("Shift+⏎", " open dir"),
|
||||
("h/l", " tabs"),
|
||||
("/", " search"),
|
||||
],
|
||||
ContentTab::Screenshots => &[
|
||||
("S+HJKL", " grid"),
|
||||
("Shift+HJKL", " grid"),
|
||||
("⏎", " open"),
|
||||
("S+⏎", " dir"),
|
||||
("Shift+⏎", " open dir"),
|
||||
("h/l", " tabs"),
|
||||
("/", " search"),
|
||||
],
|
||||
ContentTab::Logs => {
|
||||
if logs_state.viewer_focused {
|
||||
&[
|
||||
("S+JK", " scroll"),
|
||||
("g/G", " top/bot"),
|
||||
("j/k", " scroll"),
|
||||
("g/G", " top/bottom"),
|
||||
("Esc", " back"),
|
||||
("/", " search"),
|
||||
]
|
||||
} else {
|
||||
&[
|
||||
("S+JK", " nav"),
|
||||
("j/k", " navigate"),
|
||||
("⏎", " view"),
|
||||
("h/l", " tabs"),
|
||||
("/", " search"),
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
block = block.title_bottom(
|
||||
super::popups::keybind_line(kb).alignment(ratatui::layout::Alignment::Right),
|
||||
);
|
||||
})
|
||||
} else if focused == FocusedArea::Profiles {
|
||||
Some(&[
|
||||
("l", " launch"),
|
||||
("⏎", " content"),
|
||||
("Shift+⏎", " open dir"),
|
||||
("Esc", " kill"),
|
||||
("a", " add"),
|
||||
("d", " delete"),
|
||||
("/", " search"),
|
||||
])
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(kb) = kb {
|
||||
let lines = super::popups::keybind_lines_wrapped(kb, area.width.saturating_sub(2));
|
||||
for line in lines {
|
||||
block = block.title_bottom(line);
|
||||
}
|
||||
}
|
||||
|
||||
let content_area = block.inner(area);
|
||||
|
||||
+16
-12
@@ -1,5 +1,5 @@
|
||||
use ratatui::{
|
||||
layout::{Alignment, Rect},
|
||||
layout::Rect,
|
||||
style::Style,
|
||||
widgets::{Block, BorderType, Borders},
|
||||
Frame,
|
||||
@@ -17,21 +17,25 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
|
||||
THEME.colors.border_unfocused
|
||||
};
|
||||
|
||||
let block = Block::default()
|
||||
let mut block = Block::default()
|
||||
.title(styled_title("Details", true))
|
||||
.title_bottom(
|
||||
super::popups::keybind_line(&[
|
||||
("P", " profiles"),
|
||||
("C", " content"),
|
||||
("A", " account"),
|
||||
("S", " logs"),
|
||||
("q", " quit"),
|
||||
])
|
||||
.alignment(Alignment::Right),
|
||||
)
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(color));
|
||||
|
||||
let lines = super::popups::keybind_lines_wrapped(
|
||||
&[
|
||||
("P", " profiles"),
|
||||
("C", " content"),
|
||||
("A", " account"),
|
||||
("S", " logs"),
|
||||
("q", " quit"),
|
||||
],
|
||||
area.width.saturating_sub(2),
|
||||
);
|
||||
for line in lines {
|
||||
block = block.title_bottom(line);
|
||||
}
|
||||
|
||||
frame.render_widget(block, area);
|
||||
}
|
||||
@@ -70,3 +70,49 @@ pub fn keybind_line(binds: &[(&str, &str)]) -> ratatui::text::Line<'static> {
|
||||
}
|
||||
Line::from(spans)
|
||||
}
|
||||
|
||||
pub fn keybind_lines_wrapped(
|
||||
binds: &[(&str, &str)],
|
||||
max_width: u16,
|
||||
) -> Vec<ratatui::text::Line<'static>> {
|
||||
use ratatui::{style::{Modifier, Style}, text::{Line, Span}};
|
||||
use crate::tui::theme::THEME;
|
||||
|
||||
let key_style = Style::default()
|
||||
.fg(THEME.colors.border_focused)
|
||||
.add_modifier(Modifier::BOLD);
|
||||
let dim_style = Style::default().fg(THEME.colors.border_unfocused);
|
||||
|
||||
let mut rows: Vec<Line<'static>> = Vec::new();
|
||||
let mut current_spans: Vec<Span<'static>> = Vec::new();
|
||||
let mut current_width: usize = 0;
|
||||
|
||||
for (i, (key, label)) in binds.iter().enumerate() {
|
||||
let sep_w = if i > 0 && !current_spans.is_empty() { 2 } else { 0 };
|
||||
let item_w = key.len() + 2 + label.len();
|
||||
let needed = sep_w + item_w;
|
||||
|
||||
if !current_spans.is_empty() && current_width + needed > max_width as usize {
|
||||
rows.push(Line::from(current_spans).right_aligned());
|
||||
current_spans = Vec::new();
|
||||
current_width = 0;
|
||||
}
|
||||
|
||||
if !current_spans.is_empty() {
|
||||
current_spans.push(Span::styled(" ", dim_style));
|
||||
current_width += 2;
|
||||
}
|
||||
|
||||
current_spans.push(Span::styled(format!("[{}]", key), key_style));
|
||||
if !label.is_empty() {
|
||||
current_spans.push(Span::styled(label.to_string(), dim_style));
|
||||
}
|
||||
current_width += item_w;
|
||||
}
|
||||
|
||||
if !current_spans.is_empty() {
|
||||
rows.push(Line::from(current_spans).right_aligned());
|
||||
}
|
||||
|
||||
rows
|
||||
}
|
||||
@@ -207,20 +207,6 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
block = block.title_top(search_line);
|
||||
}
|
||||
|
||||
if focused == FocusedArea::Profiles {
|
||||
block = block.title_bottom(
|
||||
super::popups::keybind_line(&[
|
||||
("l", " launch"),
|
||||
("⏎", " content"),
|
||||
("a", " add"),
|
||||
("d", " del"),
|
||||
("/", " search"),
|
||||
("Esc", " kill"),
|
||||
])
|
||||
.alignment(ratatui::layout::Alignment::Right),
|
||||
);
|
||||
}
|
||||
|
||||
let scrollbar_area = Rect {
|
||||
x: area.x + area.width.saturating_sub(1),
|
||||
y: area.y + 1,
|
||||
|
||||
@@ -25,19 +25,12 @@ pub fn render(
|
||||
THEME.colors.border_unfocused
|
||||
};
|
||||
|
||||
let mut block = Block::default()
|
||||
let block = Block::default()
|
||||
.title(styled_title("Status", true))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(border_color));
|
||||
|
||||
if focused == FocusedArea::Status {
|
||||
block = block.title_bottom(
|
||||
super::popups::keybind_line(&[("S", " expand")])
|
||||
.alignment(ratatui::layout::Alignment::Right),
|
||||
);
|
||||
}
|
||||
|
||||
let state = match PROGRESS.lock() {
|
||||
Ok(s) => s.clone(),
|
||||
Err(_) => {
|
||||
|
||||
Reference in new issue
Block a user