refactor: extract cli and config into separate modules
This commit is contained in:
1 parent
03c87a8df0
commit
159b21d39a
17 files changed
+479
-2436
No files matched your search
@@ -7,11 +7,11 @@ use ratatui::{
|
||||
pub mod account;
|
||||
pub mod content;
|
||||
pub mod details;
|
||||
pub mod popups;
|
||||
pub mod profiles;
|
||||
pub mod status;
|
||||
pub mod popups;
|
||||
|
||||
pub fn styled_title(title: &str, highlight: bool) -> Line {
|
||||
pub fn styled_title(title: &str, highlight: bool) -> Line<'_> {
|
||||
if !highlight || title.is_empty() {
|
||||
Line::from(Span::raw(title))
|
||||
} else {
|
||||
@@ -26,5 +26,5 @@ pub fn styled_title(title: &str, highlight: bool) -> Line {
|
||||
}
|
||||
|
||||
pub trait WidgetKey {
|
||||
fn handle_key(&mut self, key_event: &KeyEvent);
|
||||
fn handle_key(&mut self, key_event: &KeyEvent);
|
||||
}
|
||||
@@ -2,17 +2,18 @@ use super::base::Popup;
|
||||
use crate::tui::layout::FocusedArea;
|
||||
use crate::tui::widgets::profiles;
|
||||
use crossterm::event::KeyCode;
|
||||
use ratatui::{
|
||||
Frame,
|
||||
style::{Color, Style},
|
||||
layout::{Rect, Layout, Direction, Constraint},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Paragraph, Wrap, Widget},
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Color, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Paragraph, Widget, Wrap},
|
||||
Frame,
|
||||
};
|
||||
use std::sync::Mutex;
|
||||
|
||||
static INSTANCE_POPUP_STATE: Lazy<Mutex<NewInstanceState>> = Lazy::new(|| Mutex::new(NewInstanceState::default()));
|
||||
static INSTANCE_POPUP_STATE: Lazy<Mutex<NewInstanceState>> =
|
||||
Lazy::new(|| Mutex::new(NewInstanceState::default()));
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
enum NewInstanceMode {
|
||||
@@ -32,39 +33,43 @@ pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
|
||||
|
||||
let popup = Popup {
|
||||
title: Line::from("New Instance"),
|
||||
content: Box::new(move |area, buf| {
|
||||
match state.mode {
|
||||
NewInstanceMode::Buttons => {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Percentage(40),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Percentage(40),
|
||||
])
|
||||
.split(area);
|
||||
content: Box::new(move |area, buf| match state.mode {
|
||||
NewInstanceMode::Buttons => {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Percentage(40),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Percentage(40),
|
||||
])
|
||||
.split(area);
|
||||
|
||||
let create_button = Paragraph::new(Line::from(vec![
|
||||
Span::styled("C", Style::default().fg(Color::Yellow)),
|
||||
Span::raw("reate New Instance"),
|
||||
])).alignment(ratatui::layout::Alignment::Center);
|
||||
let create_button = Paragraph::new(Line::from(vec![
|
||||
Span::styled("C", Style::default().fg(Color::Yellow)),
|
||||
Span::raw("reate New Instance"),
|
||||
]))
|
||||
.alignment(ratatui::layout::Alignment::Center);
|
||||
|
||||
let import_button = Paragraph::new(Line::from(vec![
|
||||
Span::styled("I", Style::default().fg(Color::Yellow)),
|
||||
Span::raw("mport Morinth Modpack"),
|
||||
])).alignment(ratatui::layout::Alignment::Center);
|
||||
let import_button = Paragraph::new(Line::from(vec![
|
||||
Span::styled("I", Style::default().fg(Color::Yellow)),
|
||||
Span::raw("mport Morinth Modpack"),
|
||||
]))
|
||||
.alignment(ratatui::layout::Alignment::Center);
|
||||
|
||||
create_button.render(chunks[1], buf);
|
||||
import_button.render(chunks[2], buf);
|
||||
}
|
||||
NewInstanceMode::Input => {
|
||||
let paragraph = Paragraph::new(state.input_text.clone())
|
||||
.block(Block::default().title("Enter URL or Path").borders(Borders::ALL))
|
||||
.wrap(Wrap { trim: true });
|
||||
create_button.render(chunks[1], buf);
|
||||
import_button.render(chunks[2], buf);
|
||||
}
|
||||
NewInstanceMode::Input => {
|
||||
let paragraph = Paragraph::new(state.input_text.clone())
|
||||
.block(
|
||||
Block::default()
|
||||
.title("Enter URL or Path")
|
||||
.borders(Borders::ALL),
|
||||
)
|
||||
.wrap(Wrap { trim: true });
|
||||
|
||||
paragraph.render(area, buf);
|
||||
}
|
||||
paragraph.render(area, buf);
|
||||
}
|
||||
}),
|
||||
border_style: Default::default(),
|
||||
|
||||
@@ -10,7 +10,7 @@ use ratatui::{
|
||||
Frame,
|
||||
};
|
||||
|
||||
use crate::{config::SETTINGS, tui::layout::FocusedArea};
|
||||
use crate::tui::{layout::FocusedArea, theme::THEME};
|
||||
|
||||
use super::{popups, styled_title, WidgetKey};
|
||||
|
||||
@@ -100,9 +100,9 @@ impl WidgetKey for State {
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut State) {
|
||||
let color = if focused == FocusedArea::Profiles {
|
||||
SETTINGS.colors.border_focused
|
||||
THEME.colors.border_focused
|
||||
} else {
|
||||
SETTINGS.colors.border_unfocused
|
||||
THEME.colors.border_unfocused
|
||||
};
|
||||
|
||||
let block = Block::default()
|
||||
@@ -126,9 +126,9 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
let status = if data.running { "Running" } else { "Stopped" };
|
||||
|
||||
let background_color = if i % 2 == 0 {
|
||||
SETTINGS.colors.row_background
|
||||
THEME.colors.row_background
|
||||
} else {
|
||||
SETTINGS.colors.row_alternate_bg
|
||||
THEME.colors.row_alternate_bg
|
||||
};
|
||||
|
||||
Row::new(vec![
|
||||
@@ -150,7 +150,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
.row_highlight_style(
|
||||
Style::default()
|
||||
.add_modifier(Modifier::REVERSED)
|
||||
.fg(SETTINGS.colors.row_highlight),
|
||||
.fg(THEME.colors.row_highlight),
|
||||
)
|
||||
.highlight_spacing(ratatui::widgets::HighlightSpacing::Always);
|
||||
|
||||
@@ -162,7 +162,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
.begin_symbol(Some("▲"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(SETTINGS.colors.border_focused)
|
||||
.fg(THEME.colors.border_focused)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("┃")
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
use ratatui::{
|
||||
layout::Rect,
|
||||
style::{Color, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, BorderType, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use tracing::Level;
|
||||
|
||||
use crate::tui::layout::FocusedArea;
|
||||
use crate::tui::logging::STATUS_EVENTS;
|
||||
|
||||
use super::styled_title;
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
|
||||
let color = if focused == FocusedArea::Status {
|
||||
let border_color = if focused == FocusedArea::Status {
|
||||
Color::White
|
||||
} else {
|
||||
Color::DarkGray
|
||||
@@ -20,8 +23,29 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
|
||||
.title(styled_title("Status", true))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(color));
|
||||
.border_style(Style::default().fg(border_color));
|
||||
|
||||
let widget = Paragraph::new("TEST CONTENT").block(block);
|
||||
frame.render_widget(widget, area);
|
||||
let latest = STATUS_EVENTS
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|events| events.back().cloned());
|
||||
|
||||
let content = match latest {
|
||||
Some(event) => {
|
||||
let (label, label_color) = match event.level {
|
||||
Level::ERROR => (" ERROR ", Color::Red),
|
||||
Level::WARN => (" WARN ", Color::Yellow),
|
||||
_ => (" INFO ", Color::White),
|
||||
};
|
||||
|
||||
Paragraph::new(Line::from(vec![
|
||||
Span::styled(label, Style::default().fg(Color::White).bg(label_color)),
|
||||
Span::raw(" "),
|
||||
Span::raw(event.message),
|
||||
]))
|
||||
}
|
||||
None => Paragraph::new(Span::styled("Ready", Style::default().fg(Color::DarkGray))),
|
||||
};
|
||||
|
||||
frame.render_widget(content.block(block), area);
|
||||
}
|
||||
Reference in new issue
Block a user