feat(tui): instance launching, tabs, profiles overhaul
This commit is contained in:
1 parent
09d548272b
commit
46087c47a8
15 files changed
+813
-71
No files matched your search
+59
-1
@@ -105,6 +105,7 @@ impl App {
|
||||
self.dismiss_expired_errors();
|
||||
|
||||
self.drain_pending_instances();
|
||||
self.drain_pending_last_played();
|
||||
self.throbber_state.calc_next();
|
||||
tui_logger::move_events();
|
||||
terminal.draw(|frame| self.render_frame(frame))?;
|
||||
@@ -139,7 +140,13 @@ impl App {
|
||||
self.focused,
|
||||
self.profiles_state.selected_instance(),
|
||||
);
|
||||
widgets::content::render(frame, main_chunks[1], self.focused, self.content_tab);
|
||||
widgets::content::render(
|
||||
frame,
|
||||
main_chunks[1],
|
||||
self.focused,
|
||||
self.content_tab,
|
||||
self.profiles_state.selected_instance(),
|
||||
);
|
||||
|
||||
let bottom_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
@@ -293,6 +300,22 @@ impl App {
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
}
|
||||
}
|
||||
KeyCode::Enter
|
||||
if self.focused == FocusedArea::Profiles
|
||||
&& !self.profiles_state.search.active =>
|
||||
{
|
||||
if let Some(instance) = self.profiles_state.selected_instance().cloned() {
|
||||
let can_launch = matches!(
|
||||
crate::running::get(&instance.name),
|
||||
None | Some(crate::running::RunState::Crashed(_))
|
||||
);
|
||||
if can_launch {
|
||||
crate::running::remove(&instance.name);
|
||||
crate::instance_logs::clear(&instance.name);
|
||||
self.spawn_launch(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -345,6 +368,30 @@ impl App {
|
||||
});
|
||||
}
|
||||
|
||||
fn spawn_launch(&self, instance: crate::instance::InstanceConfig) {
|
||||
use crate::instance::launch;
|
||||
use crate::{running, tui::error_buffer};
|
||||
|
||||
let instances_dir = self.instance_manager.instances_dir.clone();
|
||||
let meta_dir = self.instance_manager.meta_dir.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
match launch::launch(&instance, &instances_dir, &meta_dir).await {
|
||||
Ok(()) => {}
|
||||
Err(e) => {
|
||||
tracing::error!("Launch failed for '{}': {}", instance.name, e);
|
||||
running::remove(&instance.name);
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
message: format!("Failed to launch '{}': {}", instance.name, e),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn dismiss_expired_errors(&self) {
|
||||
loop {
|
||||
match error_buffer::peek_error() {
|
||||
@@ -369,6 +416,17 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
fn drain_pending_last_played(&mut self) {
|
||||
for (name, time) in crate::running::drain_last_played() {
|
||||
for inst in &mut self.profiles_state.instances {
|
||||
if inst.name == name {
|
||||
inst.last_played = Some(time);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_log_overlay(frame: &mut Frame, log_state: &mut tui_logger::TuiWidgetState) {
|
||||
use crate::tui::theme::THEME;
|
||||
use ratatui::{
|
||||
|
||||
+88
-22
@@ -1,7 +1,7 @@
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::Span,
|
||||
text::{Line, Span},
|
||||
widgets::{Block, BorderType, Borders, Paragraph, Tabs},
|
||||
Frame,
|
||||
};
|
||||
@@ -9,8 +9,6 @@ use ratatui::{
|
||||
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]
|
||||
@@ -61,7 +59,22 @@ impl ContentTab {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, tab: ContentTab) {
|
||||
fn spinner_char() -> char {
|
||||
const FRAMES: &[char] = &['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
||||
let ms = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_millis();
|
||||
FRAMES[(ms / 100) as usize % FRAMES.len()]
|
||||
}
|
||||
|
||||
pub fn render(
|
||||
frame: &mut Frame,
|
||||
area: Rect,
|
||||
focused: FocusedArea,
|
||||
tab: ContentTab,
|
||||
instance: Option<&crate::instance::InstanceConfig>,
|
||||
) {
|
||||
let border_color = if focused == FocusedArea::Content {
|
||||
THEME.colors.border_focused
|
||||
} else {
|
||||
@@ -94,19 +107,42 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, tab: ContentT
|
||||
|
||||
frame.render_widget(tabs, tabs_area);
|
||||
|
||||
let body = match tab {
|
||||
ContentTab::Mods => "No mods installed.",
|
||||
ContentTab::ResourcePacks => "No resource packs installed.",
|
||||
ContentTab::Shaders => "No shaders installed.",
|
||||
ContentTab::Screenshots => "No screenshots.",
|
||||
ContentTab::Worlds => "No worlds saved.",
|
||||
ContentTab::Logs => "No logs yet.",
|
||||
};
|
||||
match tab {
|
||||
ContentTab::Logs => {
|
||||
let lines = instance
|
||||
.map(|i| crate::instance_logs::get_all(&i.name))
|
||||
.unwrap_or_default();
|
||||
if lines.is_empty() {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No logs yet.")
|
||||
.style(Style::default().fg(THEME.colors.text_idle)),
|
||||
content_area,
|
||||
);
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new(lines.join("\n"))
|
||||
.style(Style::default().fg(THEME.colors.text_idle))
|
||||
.wrap(ratatui::widgets::Wrap { trim: false }),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let body = match tab {
|
||||
ContentTab::Mods => "No mods installed.",
|
||||
ContentTab::ResourcePacks => "No resource packs installed.",
|
||||
ContentTab::Shaders => "No shaders installed.",
|
||||
ContentTab::Screenshots => "No screenshots.",
|
||||
ContentTab::Worlds => "No worlds saved.",
|
||||
ContentTab::Logs => unreachable!(),
|
||||
};
|
||||
|
||||
frame.render_widget(
|
||||
Paragraph::new(body).style(Style::default().fg(THEME.colors.text_idle)),
|
||||
content_area,
|
||||
);
|
||||
frame.render_widget(
|
||||
Paragraph::new(body).style(Style::default().fg(THEME.colors.text_idle)),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn title(
|
||||
@@ -122,7 +158,6 @@ 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));
|
||||
@@ -142,14 +177,45 @@ pub fn title(
|
||||
let [left_area, right_area] =
|
||||
Layout::horizontal([Constraint::Min(0), Constraint::Length(32)]).areas(inner);
|
||||
|
||||
frame.render_widget(
|
||||
Paragraph::new(inst.name.as_str()).style(
|
||||
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) => (
|
||||
format!("{} ", spinner_char()),
|
||||
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),
|
||||
),
|
||||
left_area,
|
||||
);
|
||||
))
|
||||
} 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);
|
||||
|
||||
let loader_str = match &inst.loader_version {
|
||||
Some(lv) => format!("{} \u{00b7} {} {}", inst.game_version, inst.loader, lv),
|
||||
|
||||
@@ -9,6 +9,7 @@ use ratatui::{
|
||||
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
|
||||
|
||||
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};
|
||||
@@ -225,7 +226,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
Style::default()
|
||||
.fg(THEME.colors.row_highlight)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(THEME.colors.foreground),
|
||||
Style::default().fg(THEME.colors.row_highlight),
|
||||
THEME.colors.row_alternate_bg,
|
||||
)
|
||||
} else {
|
||||
@@ -238,16 +239,37 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
)
|
||||
};
|
||||
|
||||
let indicator = Span::styled(
|
||||
"\u{258c} ",
|
||||
Style::default().fg(loader_color(instance.loader)),
|
||||
);
|
||||
let run_state = get_run_state(&instance.name);
|
||||
let indicator = match &run_state {
|
||||
Some(RunState::Running) | Some(RunState::Starting) => {
|
||||
Span::styled("\u{25c9} ", 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 name_line = Line::from(vec![
|
||||
indicator,
|
||||
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_line = Line::from(vec![
|
||||
Span::raw(" "),
|
||||
meta_indicator,
|
||||
Span::styled(format_last_played(instance.last_played), meta_style),
|
||||
]);
|
||||
|
||||
|
||||
+18
-21
@@ -34,21 +34,27 @@ pub fn render(
|
||||
let state = match PROGRESS.lock() {
|
||||
Ok(s) => s.clone(),
|
||||
Err(_) => {
|
||||
let idle = Paragraph::new(Span::styled(
|
||||
"Ready",
|
||||
Style::default().fg(THEME.colors.text_idle),
|
||||
));
|
||||
frame.render_widget(idle.block(block), area);
|
||||
frame.render_widget(
|
||||
Paragraph::new(Span::styled(
|
||||
"Ready",
|
||||
Style::default().fg(THEME.colors.text_idle),
|
||||
))
|
||||
.block(block),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if state.current_action.is_none() {
|
||||
let idle = Paragraph::new(Span::styled(
|
||||
"Ready",
|
||||
Style::default().fg(THEME.colors.text_idle),
|
||||
));
|
||||
frame.render_widget(idle.block(block), area);
|
||||
frame.render_widget(
|
||||
Paragraph::new(Span::styled(
|
||||
"Ready",
|
||||
Style::default().fg(THEME.colors.text_idle),
|
||||
))
|
||||
.block(block),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,12 +73,7 @@ pub fn render(
|
||||
])
|
||||
.split(inner);
|
||||
|
||||
let ratio = if total > 0 {
|
||||
(current as f64 / total as f64).min(1.0)
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
let pct = (ratio * 100.0) as u16;
|
||||
let ratio = (current as f64 / total as f64).min(1.0);
|
||||
let gauge = Gauge::default()
|
||||
.gauge_style(
|
||||
Style::default()
|
||||
@@ -80,14 +81,12 @@ pub fn render(
|
||||
.bg(THEME.colors.progress_track)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.percent(pct);
|
||||
.percent((ratio * 100.0) as u16);
|
||||
frame.render_widget(gauge, chunks[0]);
|
||||
|
||||
frame.render_widget(
|
||||
Paragraph::new(action_text).style(Style::default().fg(THEME.colors.foreground)),
|
||||
chunks[1],
|
||||
);
|
||||
|
||||
if !sub_text.is_empty() {
|
||||
frame.render_widget(
|
||||
Paragraph::new(sub_text)
|
||||
@@ -99,7 +98,6 @@ pub fn render(
|
||||
_ => {
|
||||
let chunks =
|
||||
Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).split(inner);
|
||||
|
||||
let throbber = Throbber::default()
|
||||
.label(action_text)
|
||||
.style(Style::default().fg(THEME.colors.foreground))
|
||||
@@ -109,7 +107,6 @@ pub fn render(
|
||||
.add_modifier(Modifier::BOLD),
|
||||
);
|
||||
frame.render_stateful_widget(throbber, chunks[0], throbber_state);
|
||||
|
||||
if !sub_text.is_empty() {
|
||||
frame.render_widget(
|
||||
Paragraph::new(sub_text)
|
||||
|
||||
Reference in new issue
Block a user