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
+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),
|
||||
|
||||
Reference in new issue
Block a user