fix(tui): running indicator, throbber, popup styling, buffer OOB
This commit is contained in:
1 parent
3e7a05b6e5
commit
2adac8306b
5 files changed
+107
-84
No files matched your search
+12
-1
@@ -34,6 +34,7 @@ pub struct App {
|
||||
instance_manager: InstanceManager,
|
||||
log_list_state: tui_logger::TuiWidgetState,
|
||||
throbber_state: throbber_widgets_tui::ThrobberState,
|
||||
throbber_tick: u8,
|
||||
error_effects: HashMap<u64, ErrorEffectState>,
|
||||
}
|
||||
|
||||
@@ -90,6 +91,7 @@ impl Default for App {
|
||||
log_list_state: tui_logger::TuiWidgetState::new()
|
||||
.set_default_display_level(log::LevelFilter::Debug),
|
||||
throbber_state: throbber_widgets_tui::ThrobberState::default(),
|
||||
throbber_tick: 0,
|
||||
error_effects: HashMap::new(),
|
||||
}
|
||||
}
|
||||
@@ -106,7 +108,10 @@ impl App {
|
||||
|
||||
self.drain_pending_instances();
|
||||
self.drain_pending_last_played();
|
||||
self.throbber_state.calc_next();
|
||||
self.throbber_tick = self.throbber_tick.wrapping_add(1);
|
||||
if self.throbber_tick % 8 == 0 {
|
||||
self.throbber_state.calc_next();
|
||||
}
|
||||
tui_logger::move_events();
|
||||
terminal.draw(|frame| self.render_frame(frame))?;
|
||||
self.handle_events().wrap_err("handle events failed")?;
|
||||
@@ -139,6 +144,7 @@ impl App {
|
||||
main_chunks[0],
|
||||
self.focused,
|
||||
self.profiles_state.selected_instance(),
|
||||
&mut self.throbber_state,
|
||||
);
|
||||
widgets::content::render(
|
||||
frame,
|
||||
@@ -180,6 +186,11 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
if self.profiles_state.show_popup {
|
||||
let area = new_instance::popup_rect(frame.area());
|
||||
new_instance::render(frame, area, self.focused);
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::ConfirmDelete {
|
||||
let name = confirm_popup::pending_delete_name();
|
||||
if !name.is_empty() {
|
||||
|
||||
+54
-36
@@ -5,10 +5,13 @@ use ratatui::{
|
||||
widgets::{Block, BorderType, Borders, Paragraph, Tabs},
|
||||
Frame,
|
||||
};
|
||||
use throbber_widgets_tui::{Throbber, ThrobberState};
|
||||
|
||||
use crate::tui::layout::FocusedArea;
|
||||
use crate::tui::theme::THEME;
|
||||
|
||||
use super::styled_title;
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ContentTab {
|
||||
#[default]
|
||||
@@ -141,6 +144,7 @@ pub fn title(
|
||||
area: Rect,
|
||||
focused: FocusedArea,
|
||||
instance: Option<&crate::instance::InstanceConfig>,
|
||||
throbber_state: &mut ThrobberState,
|
||||
) {
|
||||
let color = if focused == FocusedArea::Content {
|
||||
THEME.colors.border_focused
|
||||
@@ -149,6 +153,7 @@ pub fn title(
|
||||
};
|
||||
|
||||
let block = Block::default()
|
||||
.title(styled_title("Content", true))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(color));
|
||||
@@ -169,44 +174,57 @@ pub fn title(
|
||||
Layout::horizontal([Constraint::Min(0), Constraint::Length(32)]).areas(inner);
|
||||
|
||||
use crate::running::RunState;
|
||||
|
||||
let run_state = crate::running::get(&inst.name);
|
||||
let (prefix, prefix_style) = match run_state {
|
||||
Some(RunState::Running) | Some(RunState::Starting) => (
|
||||
String::from("\u{25b6} "),
|
||||
Style::default()
|
||||
.fg(THEME.colors.success)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
Some(RunState::Crashed(_)) => (
|
||||
String::from("\u{2717} "),
|
||||
Style::default()
|
||||
.fg(THEME.colors.error)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
None => (String::new(), Style::default()),
|
||||
};
|
||||
|
||||
let name_line = if prefix.is_empty() {
|
||||
Line::from(Span::styled(
|
||||
inst.name.as_str(),
|
||||
Style::default()
|
||||
.fg(THEME.colors.foreground)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
))
|
||||
} else {
|
||||
Line::from(vec![
|
||||
Span::styled(prefix, prefix_style),
|
||||
Span::styled(
|
||||
inst.name.as_str(),
|
||||
Style::default()
|
||||
.fg(THEME.colors.foreground)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])
|
||||
};
|
||||
|
||||
frame.render_widget(Paragraph::new(name_line), left_area);
|
||||
match run_state {
|
||||
Some(RunState::Running) | Some(RunState::Starting) => {
|
||||
let throbber = Throbber::default()
|
||||
.label(inst.name.as_str())
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(THEME.colors.foreground)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.throbber_style(
|
||||
Style::default()
|
||||
.fg(THEME.colors.success)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.throbber_set(throbber_widgets_tui::PARENTHESIS)
|
||||
.use_type(throbber_widgets_tui::WhichUse::Spin);
|
||||
frame.render_stateful_widget(throbber, left_area, throbber_state);
|
||||
}
|
||||
Some(RunState::Crashed(_)) => {
|
||||
frame.render_widget(
|
||||
Paragraph::new(Line::from(vec![
|
||||
Span::styled(
|
||||
"\u{2717} ",
|
||||
Style::default()
|
||||
.fg(THEME.colors.error)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
Span::styled(
|
||||
inst.name.as_str(),
|
||||
Style::default()
|
||||
.fg(THEME.colors.foreground)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])),
|
||||
left_area,
|
||||
);
|
||||
}
|
||||
None => {
|
||||
frame.render_widget(
|
||||
Paragraph::new(Span::styled(
|
||||
inst.name.as_str(),
|
||||
Style::default()
|
||||
.fg(THEME.colors.foreground)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)),
|
||||
left_area,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let loader_str = match &inst.loader_version {
|
||||
Some(lv) => format!("{} \u{00b7} {} {}", inst.game_version, inst.loader, lv),
|
||||
|
||||
@@ -72,7 +72,11 @@ pub fn popup_area(frame_area: Rect, message: &str, base_y: u16, elapsed_ms: u128
|
||||
let popup_w = (inner_w + 2) as u16;
|
||||
let popup_h = (h + 2) as u16;
|
||||
let popup_w = popup_w.min(frame_area.width.saturating_sub(4));
|
||||
let popup_h = popup_h.min(frame_area.height.saturating_sub(2));
|
||||
let max_h = frame_area.height.saturating_sub(base_y).saturating_sub(1);
|
||||
if max_h < 3 {
|
||||
return None;
|
||||
}
|
||||
let popup_h = popup_h.min(max_h);
|
||||
let base_x = frame_area.width.saturating_sub(popup_w + 2);
|
||||
Some(Rect {
|
||||
x: base_x,
|
||||
|
||||
@@ -449,7 +449,7 @@ fn close_popup(state: &mut WizardState, profiles_state: &mut profiles::State) {
|
||||
|
||||
fn wizard_title(_state: &WizardState) -> Line<'static> {
|
||||
use crate::tui::widgets::styled_title;
|
||||
styled_title("New Instance", true)
|
||||
styled_title("New Instance", false)
|
||||
}
|
||||
|
||||
fn step_keybinds(state: &WizardState) -> ratatui::text::Line<'static> {
|
||||
@@ -519,15 +519,17 @@ fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
|
||||
} else {
|
||||
" (snapshot)".to_string()
|
||||
};
|
||||
ListItem::new(format!("{}{}", version.id, suffix))
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
format!("{}{}", version.id, suffix),
|
||||
Style::default().fg(THEME.colors.foreground),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.style(Style::default().fg(THEME.colors.foreground))
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(THEME.colors.row_highlight)
|
||||
.fg(THEME.colors.accent)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
@@ -549,14 +551,18 @@ fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer
|
||||
|
||||
let items: Vec<ListItem> = loaders
|
||||
.into_iter()
|
||||
.map(|loader| ListItem::new(loader.to_string()))
|
||||
.map(|loader| {
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
loader.to_string(),
|
||||
Style::default().fg(THEME.colors.foreground),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.style(Style::default().fg(THEME.colors.foreground))
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(THEME.colors.row_highlight)
|
||||
.fg(THEME.colors.accent)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
@@ -592,14 +598,18 @@ fn render_loader_version_step(
|
||||
LoadState::Loaded(versions) => {
|
||||
let items: Vec<ListItem> = versions
|
||||
.iter()
|
||||
.map(|version| ListItem::new(version.clone()))
|
||||
.map(|version| {
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
version.clone(),
|
||||
Style::default().fg(THEME.colors.foreground),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.style(Style::default().fg(THEME.colors.foreground))
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(THEME.colors.row_highlight)
|
||||
.fg(THEME.colors.accent)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
|
||||
+16
-36
@@ -12,7 +12,7 @@ use crate::instance::models::InstanceConfig;
|
||||
use crate::running::{get as get_run_state, RunState};
|
||||
use crate::tui::{layout::FocusedArea, theme::THEME};
|
||||
|
||||
use super::{popups, search::SearchState, styled_title, WidgetKey};
|
||||
use super::{search::SearchState, styled_title, WidgetKey};
|
||||
|
||||
fn format_last_played(last_played: Option<chrono::DateTime<chrono::Utc>>) -> String {
|
||||
let Some(dt) = last_played else {
|
||||
@@ -227,7 +227,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
.fg(THEME.colors.row_highlight)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(THEME.colors.row_highlight),
|
||||
THEME.colors.row_alternate_bg,
|
||||
THEME.colors.row_background,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
@@ -235,43 +235,28 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
.fg(THEME.colors.border_focused)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(THEME.colors.border_unfocused),
|
||||
THEME.colors.row_background,
|
||||
THEME.colors.row_alternate_bg,
|
||||
)
|
||||
};
|
||||
|
||||
let run_state = get_run_state(&instance.name);
|
||||
let indicator = match &run_state {
|
||||
Some(RunState::Running) | Some(RunState::Starting) => {
|
||||
Span::styled("\u{25b6} ", Style::default().fg(THEME.colors.success))
|
||||
}
|
||||
Some(RunState::Crashed(_)) => {
|
||||
Span::styled("\u{2717} ", Style::default().fg(THEME.colors.error))
|
||||
}
|
||||
None => Span::styled(
|
||||
"\u{258c} ",
|
||||
Style::default().fg(loader_color(instance.loader)),
|
||||
),
|
||||
};
|
||||
let stripe = Span::styled(
|
||||
"\u{258c} ",
|
||||
Style::default().fg(loader_color(instance.loader)),
|
||||
);
|
||||
let name_line = Line::from(vec![
|
||||
indicator,
|
||||
stripe.clone(),
|
||||
Span::styled(instance.name.as_str(), name_style),
|
||||
]);
|
||||
let meta_indicator = match &run_state {
|
||||
Some(RunState::Running) | Some(RunState::Starting) => {
|
||||
Span::styled("\u{258c} ", Style::default().fg(THEME.colors.success))
|
||||
}
|
||||
Some(RunState::Crashed(_)) => {
|
||||
Span::styled("\u{258c} ", Style::default().fg(THEME.colors.error))
|
||||
}
|
||||
None => Span::styled(
|
||||
"\u{258c} ",
|
||||
Style::default().fg(loader_color(instance.loader)),
|
||||
|
||||
let (meta_text, meta_text_style) = match get_run_state(&instance.name) {
|
||||
Some(RunState::Running) | Some(RunState::Starting) => (
|
||||
"Playing".to_string(),
|
||||
Style::default().fg(THEME.colors.success),
|
||||
),
|
||||
_ => (format_last_played(instance.last_played), meta_style),
|
||||
};
|
||||
let meta_line = Line::from(vec![
|
||||
meta_indicator,
|
||||
Span::styled(format_last_played(instance.last_played), meta_style),
|
||||
]);
|
||||
|
||||
let meta_line = Line::from(vec![stripe, Span::styled(meta_text, meta_text_style)]);
|
||||
|
||||
let item = Text::from(vec![name_line, meta_line]).style(Style::default().bg(bg));
|
||||
(item, 2)
|
||||
@@ -296,9 +281,4 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
scrollbar_area,
|
||||
&mut state.scrollbar_state,
|
||||
);
|
||||
|
||||
if state.show_popup {
|
||||
let popup_area = popups::new_instance::popup_rect(frame.area());
|
||||
popups::new_instance::render(frame, popup_area, focused);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user