feat(theme): add palette system and per-element theming

This commit is contained in:
objz committed 2026-01-24 19:18:09 +01:00
1 parent ecc2b2bb23
commit 80210364d5
40 files changed
+2900 -1120

No files matched your search

Generated
+583 -378
View File
File diff suppressed because it is too large. Load diff
+5 -1
View File
@@ -14,11 +14,12 @@ crossterm = { version = "0.29", features = [] }
dirs-next = "2.0.0"
log = "0.4"
once_cell = "1.20.3"
ratatui = "0.30.0"
ratatui = { version = "0.30.0", features = ["serde"] }
ratatui-textarea = { version = "0.8", features = ["crossterm"] }
reqwest = { version = "0.12", features = ["json", "stream"] }
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0"
toml = "0.8"
tachyonfx = "0.25"
throbber-widgets-tui = "0.11"
thiserror = "2"
@@ -43,3 +44,6 @@ codegen-units = 1
lto = true
opt-level = "s"
strip = true
[dev-dependencies]
tempfile = "3"
+17
View File
@@ -0,0 +1,17 @@
[general]
debug = false
[paths]
instances_dir = "~/.local/share/mcl/instances"
meta_dir = "~/.local/share/mcl/meta"
java_path = ""
[defaults]
memory_min = "512M"
memory_max = "2G"
[ui]
error_auto_dismiss_ms = 5000
error_slide_start_ms = 3500
error_fly_out_ms = 300
max_error_events = 50
-30
View File
@@ -1,30 +0,0 @@
[general]
debug = false
[paths]
instances_dir = "~/.local/share/mcl/instances"
meta_dir = "~/.local/share/mcl/meta"
# java_path is optional, leave commented out by default
[defaults]
memory_min = "512M"
memory_max = "2G"
[colors]
background = "#1e1e1e"
foreground = "white"
border_focused = "white"
border_unfocused = "darkgray"
row_highlight = "yellow"
row_background = "#1a1a1a"
row_alternate_bg = "#242424"
popup_bg = "#1e1e1e"
error = "red"
warn = "yellow"
success = "green"
accent = "yellow"
text_idle = "darkgray"
progress_fill = "green"
progress_track = "darkgray"
badge_text = "black"
fade_to = "darkgray"
+148
View File
@@ -0,0 +1,148 @@
[palette]
bg = "#1e1e1e"
surface = "#242424"
overlay = "#1a1a1a"
fg = "white"
muted = "darkgray"
accent = "yellow"
error = "red"
warn = "yellow"
success = "green"
[general]
border_type = "rounded"
fg = "fg"
bg = "bg"
accent = "accent"
text_secondary = "muted"
error = "error"
warn = "warn"
success = "success"
[profiles]
border_focused_fg = "fg"
border_unfocused_fg = "muted"
selected_fg = "accent"
selected_bg = "overlay"
selected_bold = true
row_alt_bg = "surface"
text_fg = "fg"
running_fg = "success"
loader_vanilla = "green"
loader_fabric = "#71a5de"
loader_forge = "#e07b39"
loader_neoforge = "#e0541b"
loader_quilt = "#a65ccb"
[content]
border_focused_fg = "fg"
border_unfocused_fg = "muted"
tab_active_fg = "accent"
tab_active_bold = true
tab_inactive_fg = "muted"
selected_bg = "overlay"
text_fg = "fg"
[content_list]
border_focused_fg = "fg"
selected_fg = "accent"
selected_bg = "overlay"
selected_bold = true
row_alt_bg = "surface"
text_fg = "fg"
text_secondary_fg = "muted"
disabled_crossed_out = true
[details]
border_focused_fg = "fg"
border_unfocused_fg = "muted"
label_fg = "muted"
value_fg = "fg"
[logs]
border_focused_fg = "fg"
border_unfocused_fg = "muted"
error_fg = "error"
warn_fg = "warn"
info_fg = "fg"
debug_fg = "muted"
trace_fg = "muted"
selected_fg = "accent"
selected_bg = "overlay"
selected_bold = true
row_alt_bg = "surface"
running_fg = "success"
text_fg = "fg"
[log_overlay]
bg = "bg"
border_fg = "fg"
error_fg = "error"
warn_fg = "warn"
info_fg = "fg"
debug_fg = "muted"
trace_fg = "muted"
text_fg = "fg"
[status]
border_focused_fg = "fg"
border_unfocused_fg = "muted"
label_fg = "muted"
text_fg = "fg"
progress_fill_fg = "success"
progress_track_fg = "muted"
[search]
border_focused_fg = "fg"
border_unfocused_fg = "muted"
highlight_fg = "accent"
highlight_bold = false
highlight_underline = true
[screenshots]
border_focused_fg = "fg"
label_fg = "muted"
selected_border_fg = "accent"
[account]
border_focused_fg = "fg"
border_unfocused_fg = "muted"
selected_fg = "accent"
selected_bg = "overlay"
selected_bold = true
text_fg = "fg"
text_secondary_fg = "muted"
active_fg = "success"
popup_bg = "bg"
popup_border_fg = "fg"
[popup]
bg = "bg"
border_fg = "fg"
text_fg = "fg"
keybind_active_fg = "fg"
keybind_active_bold = true
keybind_inactive_fg = "muted"
[popup_confirm]
border_fg = "fg"
highlight_bg = "surface"
text_fg = "fg"
[popup_error]
bg = "bg"
border_fg = "fg"
error_fg = "error"
warn_fg = "warn"
text_fg = "fg"
badge_bg = "error"
badge_text_fg = "black"
[popup_new_instance]
bg = "bg"
border_fg = "fg"
field_active_border_fg = "fg"
field_inactive_border_fg = "muted"
text_fg = "fg"
error_fg = "error"
accent_fg = "accent"
+1 -1
View File
@@ -125,7 +125,7 @@ pub fn offline_uuid(username: &str) -> String {
format!(
"{:08x}-{:04x}-3{:03x}-{:04x}-{:012x}",
(h >> 32) as u32,
(h >> 16) as u16 & 0xFFFF,
(h >> 16) as u16,
(h >> 4) as u16 & 0x0FFF,
(h as u16 & 0x3FFF) | 0x8000,
h & 0xFFFFFFFFFFFF,
+2
View File
@@ -79,6 +79,8 @@ pub async fn init() {
.get_matches();
if matches.subcommand().is_none() {
// Force eager theme initialization before TUI starts (prevents lazy init inside render loop)
let _ = &*crate::tui::theme::THEME;
match tui::show().await {
Ok(_) => {}
Err(e) => {
+4 -4
View File
@@ -51,9 +51,9 @@ fn ensure_config_exists(default_path: &str) -> PathBuf {
config_path
}
pub fn load_config(config_path: &PathBuf) -> Result<Config, ConfigError> {
pub fn load_config(config_path: &std::path::Path) -> Result<Config, ConfigError> {
let built = match ConfigLoader::builder()
.add_source(File::from(config_path.clone()).required(false))
.add_source(File::from(config_path).required(false))
.build()
{
Ok(c) => c,
@@ -81,7 +81,7 @@ pub fn load_config(config_path: &PathBuf) -> Result<Config, ConfigError> {
}
pub static SETTINGS: Lazy<Config> = Lazy::new(|| {
let path: PathBuf = ensure_config_exists("assets/default.toml");
let path: PathBuf = ensure_config_exists("assets/config.toml");
match load_config(&path) {
Ok(config) => config,
Err(e) => {
@@ -90,7 +90,7 @@ pub static SETTINGS: Lazy<Config> = Lazy::new(|| {
general: types::General::default(),
paths: types::Paths::default(),
defaults: types::Defaults::default(),
colors: types::Colors::default(),
ui: types::Ui::default(),
}
}
}
+40 -166
View File
@@ -1,25 +1,19 @@
use dirs_next;
use ratatui::style::Color;
use serde::{Deserialize, Deserializer};
use serde::Deserialize;
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Default)]
pub struct General {
#[serde(default)]
pub debug: bool,
}
impl Default for General {
fn default() -> Self {
General { debug: false }
}
}
#[derive(Debug, Deserialize)]
pub struct Paths {
#[serde(default = "default_instances_dir")]
pub instances_dir: String,
#[serde(default = "default_meta_dir")]
pub meta_dir: String,
#[serde(default)]
pub java_path: Option<String>,
}
@@ -42,6 +36,10 @@ impl Default for Paths {
}
impl Paths {
pub fn effective_java_path(&self) -> Option<&str> {
self.java_path.as_deref().filter(|s| !s.is_empty())
}
pub fn resolve_instances_dir(&self) -> std::path::PathBuf {
let raw = &self.instances_dir;
if let Some(stripped) = raw.strip_prefix("~/") {
@@ -102,169 +100,45 @@ impl Default for Defaults {
}
}
#[derive(Debug, Deserialize, Clone)]
pub struct Colors {
#[serde(deserialize_with = "deserialize_color")]
pub background: Color,
#[serde(deserialize_with = "deserialize_color")]
pub foreground: Color,
#[serde(deserialize_with = "deserialize_color")]
pub border_focused: Color,
#[serde(deserialize_with = "deserialize_color")]
pub border_unfocused: Color,
#[serde(deserialize_with = "deserialize_color")]
pub row_highlight: Color,
#[serde(deserialize_with = "deserialize_color")]
pub row_background: Color,
#[serde(deserialize_with = "deserialize_color")]
pub row_alternate_bg: Color,
#[serde(deserialize_with = "deserialize_color", default = "default_popup_bg")]
pub popup_bg: Color,
#[serde(deserialize_with = "deserialize_color", default = "default_error")]
pub error: Color,
#[serde(deserialize_with = "deserialize_color", default = "default_warn")]
pub warn: Color,
#[serde(deserialize_with = "deserialize_color", default = "default_success")]
pub success: Color,
#[serde(deserialize_with = "deserialize_color", default = "default_accent")]
pub accent: Color,
#[serde(deserialize_with = "deserialize_color", default = "default_text_idle")]
pub text_idle: Color,
#[serde(
deserialize_with = "deserialize_color",
default = "default_progress_fill"
)]
pub progress_fill: Color,
#[serde(
deserialize_with = "deserialize_color",
default = "default_progress_track"
)]
pub progress_track: Color,
#[serde(deserialize_with = "deserialize_color", default = "default_badge_text")]
pub badge_text: Color,
#[serde(deserialize_with = "deserialize_color", default = "default_fade_to")]
pub fade_to: Color,
#[derive(Debug, Deserialize)]
pub struct Ui {
#[serde(default = "default_error_auto_dismiss_ms")]
pub error_auto_dismiss_ms: u64,
#[serde(default = "default_error_slide_start_ms")]
pub error_slide_start_ms: u64,
#[serde(default = "default_error_fly_out_ms")]
pub error_fly_out_ms: u64,
#[serde(default = "default_max_error_events")]
pub max_error_events: usize,
}
impl Default for Colors {
fn default_error_auto_dismiss_ms() -> u64 {
5000
}
fn default_error_slide_start_ms() -> u64 {
3500
}
fn default_error_fly_out_ms() -> u64 {
300
}
fn default_max_error_events() -> usize {
50
}
impl Default for Ui {
fn default() -> Self {
Colors {
background: Color::Reset,
foreground: Color::White,
border_focused: Color::White,
border_unfocused: Color::DarkGray,
row_highlight: Color::White,
row_background: Color::Reset,
row_alternate_bg: Color::Reset,
popup_bg: default_popup_bg(),
error: default_error(),
warn: default_warn(),
success: default_success(),
accent: default_accent(),
text_idle: default_text_idle(),
progress_fill: default_progress_fill(),
progress_track: default_progress_track(),
badge_text: default_badge_text(),
fade_to: default_fade_to(),
Ui {
error_auto_dismiss_ms: default_error_auto_dismiss_ms(),
error_slide_start_ms: default_error_slide_start_ms(),
error_fly_out_ms: default_error_fly_out_ms(),
max_error_events: default_max_error_events(),
}
}
}
fn default_popup_bg() -> Color {
Color::Rgb(0x1e, 0x1e, 0x1e)
}
fn default_error() -> Color {
Color::Red
}
fn default_warn() -> Color {
Color::Yellow
}
fn default_success() -> Color {
Color::Green
}
fn default_accent() -> Color {
Color::Yellow
}
fn default_text_idle() -> Color {
Color::DarkGray
}
fn default_progress_fill() -> Color {
Color::Green
}
fn default_progress_track() -> Color {
Color::DarkGray
}
fn default_badge_text() -> Color {
Color::Black
}
fn default_fade_to() -> Color {
Color::DarkGray
}
pub fn parse_color(color: &str) -> Color {
match color.to_lowercase().as_str() {
"black" => Color::Black,
"red" => Color::Red,
"green" => Color::Green,
"yellow" => Color::Yellow,
"blue" => Color::Blue,
"magenta" => Color::Magenta,
"cyan" => Color::Cyan,
"white" => Color::White,
"gray" | "grey" => Color::Gray,
"darkgray" | "darkgrey" => Color::DarkGray,
"lightred" => Color::LightRed,
"lightgreen" => Color::LightGreen,
"lightyellow" => Color::LightYellow,
"lightblue" => Color::LightBlue,
"lightmagenta" => Color::LightMagenta,
"lightcyan" => Color::LightCyan,
"reset" => Color::Reset,
hex if hex.starts_with('#') && hex.len() == 7 => {
let r = u8::from_str_radix(&hex[1..3], 16).unwrap_or_else(|_| {
tracing::warn!("Invalid hex color: {}", color);
255
});
let g = u8::from_str_radix(&hex[3..5], 16).unwrap_or_else(|_| {
tracing::warn!("Invalid hex color: {}", color);
255
});
let b = u8::from_str_radix(&hex[5..7], 16).unwrap_or_else(|_| {
tracing::warn!("Invalid hex color: {}", color);
255
});
Color::Rgb(r, g, b)
}
_ => {
tracing::warn!("Unknown color '{}', using White as fallback", color);
Color::White
}
}
}
fn deserialize_color<'de, D>(deserializer: D) -> Result<Color, D::Error>
where
D: Deserializer<'de>,
{
let color_str: String = match Deserialize::deserialize(deserializer) {
Ok(s) => s,
Err(e) => {
tracing::warn!("Failed to deserialize color field: {}", e);
return Ok(Color::White);
}
};
Ok(parse_color(&color_str))
}
#[derive(Debug, Deserialize)]
pub struct Config {
#[serde(default)]
@@ -274,5 +148,5 @@ pub struct Config {
#[serde(default)]
pub defaults: Defaults,
#[serde(default)]
pub colors: Colors,
pub ui: Ui,
}
+72 -52
View File
@@ -121,7 +121,13 @@ pub async fn launch(
.libraries
.iter()
.filter(|l| lib_allowed(l))
.filter_map(|l| l.downloads.as_ref()?.artifact.as_ref().map(|a| lib_dir.join(&a.path)))
.filter_map(|l| {
l.downloads
.as_ref()?
.artifact
.as_ref()
.map(|a| lib_dir.join(&a.path))
})
.collect();
let main_class = match config.loader {
@@ -132,7 +138,9 @@ pub async fn launch(
.join("loader-profiles")
.join(format!("fabric-{}-{}.json", config.game_version, lv));
if !profile_path.exists() {
return Err(LaunchError::MetaNotFound(profile_path.display().to_string()));
return Err(LaunchError::MetaNotFound(
profile_path.display().to_string(),
));
}
let profile: LoaderProfileJson =
serde_json::from_slice(&std::fs::read(&profile_path)?)?;
@@ -149,7 +157,9 @@ pub async fn launch(
.join("loader-profiles")
.join(format!("quilt-{}-{}.json", config.game_version, lv));
if !profile_path.exists() {
return Err(LaunchError::MetaNotFound(profile_path.display().to_string()));
return Err(LaunchError::MetaNotFound(
profile_path.display().to_string(),
));
}
let profile: LoaderProfileJson =
serde_json::from_slice(&std::fs::read(&profile_path)?)?;
@@ -166,7 +176,9 @@ pub async fn launch(
.join("loader-profiles")
.join(format!("forge-{}-{}.json", config.game_version, lv));
if !profile_path.exists() {
return Err(LaunchError::MetaNotFound(profile_path.display().to_string()));
return Err(LaunchError::MetaNotFound(
profile_path.display().to_string(),
));
}
let profile: LoaderProfileJson =
serde_json::from_slice(&std::fs::read(&profile_path)?)?;
@@ -190,7 +202,9 @@ pub async fn launch(
.join("loader-profiles")
.join(format!("neoforge-{}.json", lv));
if !profile_path.exists() {
return Err(LaunchError::MetaNotFound(profile_path.display().to_string()));
return Err(LaunchError::MetaNotFound(
profile_path.display().to_string(),
));
}
let profile: LoaderProfileJson =
serde_json::from_slice(&std::fs::read(&profile_path)?)?;
@@ -227,6 +241,12 @@ pub async fn launch(
let java = config
.java_path
.clone()
.or_else(|| {
crate::config::SETTINGS
.paths
.effective_java_path()
.map(str::to_owned)
})
.unwrap_or_else(crate::net::detect_java_path);
let mut jvm: Vec<String> = vec![
@@ -236,50 +256,50 @@ pub async fn launch(
jvm.extend(config.jvm_args.clone());
let mut account_store = crate::auth::AccountStore::load();
let (mc_username, mc_uuid, mc_token, mc_user_type) =
match account_store.active_account().cloned() {
Some(acc) => {
let (token, new_refresh) = match acc.account_type {
crate::auth::AccountType::Microsoft => {
match crate::auth::refresh_and_get_token(&acc).await {
Ok(pair) => pair,
Err(e) => {
return Err(LaunchError::Auth(format!(
"Authentication failed: {e}"
)));
}
let (mc_username, mc_uuid, mc_token, mc_user_type) = match account_store
.active_account()
.cloned()
{
Some(acc) => {
let (token, new_refresh) = match acc.account_type {
crate::auth::AccountType::Microsoft => {
match crate::auth::refresh_and_get_token(&acc).await {
Ok(pair) => pair,
Err(e) => {
return Err(LaunchError::Auth(format!("Authentication failed: {e}")));
}
}
crate::auth::AccountType::Offline => ("0".to_string(), None),
};
if let Some(new_rt) = new_refresh {
if let Some(stored) = account_store
.accounts
.iter_mut()
.find(|a| a.uuid == acc.uuid)
{
stored.refresh_token = Some(new_rt);
account_store.save();
}
}
let user_type = match acc.account_type {
crate::auth::AccountType::Microsoft => "msa",
crate::auth::AccountType::Offline => "legacy",
};
(
acc.username.clone(),
acc.uuid.clone(),
token,
user_type.to_string(),
)
crate::auth::AccountType::Offline => ("0".to_string(), None),
};
if let Some(new_rt) = new_refresh {
if let Some(stored) = account_store
.accounts
.iter_mut()
.find(|a| a.uuid == acc.uuid)
{
stored.refresh_token = Some(new_rt);
account_store.save();
}
}
None => (
"Player".to_string(),
"00000000-0000-0000-0000-000000000000".to_string(),
"0".to_string(),
"legacy".to_string(),
),
};
let user_type = match acc.account_type {
crate::auth::AccountType::Microsoft => "msa",
crate::auth::AccountType::Offline => "legacy",
};
(
acc.username.clone(),
acc.uuid.clone(),
token,
user_type.to_string(),
)
}
None => (
"Player".to_string(),
"00000000-0000-0000-0000-000000000000".to_string(),
"0".to_string(),
"legacy".to_string(),
),
};
let game_args = vec![
"--username".to_string(),
@@ -330,8 +350,7 @@ pub async fn launch(
crate::running::set_state(&name, crate::running::RunState::Running);
let log_file_path =
crate::instance::log_files::create_log_file(instances_dir, &name);
let log_file_path = crate::instance::log_files::create_log_file(instances_dir, &name);
let name_for_task = name.clone();
let instances_dir_owned = instances_dir.to_path_buf();
@@ -396,15 +415,16 @@ pub async fn launch(
if code == Some(0) {
crate::running::remove(&name_for_task);
} else {
crate::running::set_state(
&name_for_task,
crate::running::RunState::Crashed(code),
);
crate::running::set_state(&name_for_task, crate::running::RunState::Crashed(code));
}
let manager = crate::instance::InstanceManager::new(instances_dir_owned, meta_dir_owned);
if let Err(e) = manager.touch_last_played(&name_for_task) {
tracing::warn!("Failed to update last_played for '{}': {}", name_for_task, e);
tracing::warn!(
"Failed to update last_played for '{}': {}",
name_for_task,
e
);
}
crate::running::push_last_played(&name_for_task, chrono::Utc::now());
crate::running::cleanup_kill_sender(&name_for_task);
+26 -47
View File
@@ -99,10 +99,7 @@ impl ModLoaderInstaller for FabricInstaller {
}
async fn get_game_versions(&self, client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
match fabric::fetch_fabric_game_versions(client).await {
Ok(versions) => Ok(versions),
Err(e) => Err(e),
}
fabric::fetch_fabric_game_versions(client).await
}
async fn get_versions(
@@ -130,13 +127,13 @@ impl ModLoaderInstaller for FabricInstaller {
_instance_dir: &Path,
meta_dir: &Path,
) -> Result<(), NetError> {
let profile =
match fabric::fetch_fabric_profile(client, game_version, loader_version).await {
Ok(p) => p,
Err(e) => {
return Err(e);
}
};
let profile = match fabric::fetch_fabric_profile(client, game_version, loader_version).await
{
Ok(p) => p,
Err(e) => {
return Err(e);
}
};
match fabric::download_fabric_libraries(client, &profile, meta_dir).await {
Ok(()) => {}
@@ -175,10 +172,7 @@ impl ModLoaderInstaller for ForgeInstaller {
}
async fn get_game_versions(&self, client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
match forge::fetch_forge_game_versions(client).await {
Ok(versions) => Ok(versions),
Err(e) => Err(e),
}
forge::fetch_forge_game_versions(client).await
}
async fn get_versions(
@@ -186,12 +180,7 @@ impl ModLoaderInstaller for ForgeInstaller {
client: &HttpClient,
game_version: &str,
) -> Result<Vec<String>, NetError> {
match forge::fetch_forge_versions(client, game_version).await {
Ok(v) => Ok(v),
Err(e) => {
Err(e)
}
}
forge::fetch_forge_versions(client, game_version).await
}
async fn install(
@@ -305,10 +294,7 @@ impl ModLoaderInstaller for QuiltInstaller {
}
async fn get_game_versions(&self, client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
match quilt::fetch_quilt_game_versions(client).await {
Ok(versions) => Ok(versions),
Err(e) => Err(e),
}
quilt::fetch_quilt_game_versions(client).await
}
async fn get_versions(
@@ -336,13 +322,12 @@ impl ModLoaderInstaller for QuiltInstaller {
_instance_dir: &Path,
meta_dir: &Path,
) -> Result<(), NetError> {
let profile =
match quilt::fetch_quilt_profile(client, game_version, loader_version).await {
Ok(p) => p,
Err(e) => {
return Err(e);
}
};
let profile = match quilt::fetch_quilt_profile(client, game_version, loader_version).await {
Ok(p) => p,
Err(e) => {
return Err(e);
}
};
match quilt::download_quilt_libraries(client, &profile, meta_dir).await {
Ok(()) => {}
@@ -381,10 +366,7 @@ impl ModLoaderInstaller for NeoForgeInstaller {
}
async fn get_game_versions(&self, client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
match neoforge::fetch_neoforge_game_versions(client).await {
Ok(versions) => Ok(versions),
Err(e) => Err(e),
}
neoforge::fetch_neoforge_game_versions(client).await
}
async fn get_versions(
@@ -392,12 +374,7 @@ impl ModLoaderInstaller for NeoForgeInstaller {
client: &HttpClient,
game_version: &str,
) -> Result<Vec<String>, NetError> {
match neoforge::fetch_neoforge_versions(client, game_version).await {
Ok(v) => Ok(v),
Err(e) => {
Err(e)
}
}
neoforge::fetch_neoforge_versions(client, game_version).await
}
async fn install(
@@ -478,10 +455,9 @@ impl ModLoaderInstaller for NeoForgeInstaller {
tracing::warn!("Failed to save NeoForge profile: {}", e);
}
}
Err(e) => tracing::warn!(
"Failed to serialize NeoForge profile: {}",
e
),
Err(e) => {
tracing::warn!("Failed to serialize NeoForge profile: {}", e)
}
}
}
Err(e) => tracing::warn!("Failed to create loader-profiles dir: {}", e),
@@ -542,7 +518,10 @@ mod tests {
let installer = VanillaInstaller;
let tmp = std::env::temp_dir().join("mcl_test_vanilla_install");
let meta = std::env::temp_dir().join("mcl_test_meta");
match installer.install(&client, "1.20.1", "vanilla", &tmp, &meta).await {
match installer
.install(&client, "1.20.1", "vanilla", &tmp, &meta)
.await
{
Ok(()) => {}
Err(e) => assert!(false, "install failed: {}", e),
}
+24 -13
View File
@@ -109,7 +109,6 @@ impl InstanceManager {
loader_version: Option<&str>,
instance_dir: &std::path::Path,
) -> Result<InstanceConfig, InstanceError> {
let minecraft_dir = instance_dir.join(".minecraft");
for subdir in &["mods", "config", "resourcepacks", "shaderpacks", "saves"] {
match std::fs::create_dir_all(minecraft_dir.join(subdir)) {
@@ -163,21 +162,28 @@ impl InstanceManager {
}
};
let version_meta = match crate::net::mojang::fetch_version_meta(&self.client, version_entry).await {
Ok(m) => m,
Err(e) => {
return Err(InstanceError::Download(e));
}
};
let version_meta =
match crate::net::mojang::fetch_version_meta(&self.client, version_entry).await {
Ok(m) => m,
Err(e) => {
return Err(InstanceError::Download(e));
}
};
match crate::net::mojang::download_client_jar(&self.client, &version_meta, &self.meta_dir).await {
match crate::net::mojang::download_client_jar(&self.client, &version_meta, &self.meta_dir)
.await
{
Ok(_) => {}
Err(e) => {
return Err(InstanceError::Download(e));
}
}
let meta_json_path = self.meta_dir.join("versions").join(game_version).join("meta.json");
let meta_json_path = self
.meta_dir
.join("versions")
.join(game_version)
.join("meta.json");
match serde_json::to_string_pretty(&version_meta) {
Ok(json) => {
if let Err(e) = std::fs::write(&meta_json_path, &json) {
@@ -189,14 +195,17 @@ impl InstanceManager {
}
}
match crate::net::mojang::download_libraries(&self.client, &version_meta, &self.meta_dir).await {
match crate::net::mojang::download_libraries(&self.client, &version_meta, &self.meta_dir)
.await
{
Ok(_) => {}
Err(e) => {
return Err(InstanceError::Download(e));
}
}
match crate::net::mojang::download_assets(&self.client, &version_meta, &self.meta_dir).await {
match crate::net::mojang::download_assets(&self.client, &version_meta, &self.meta_dir).await
{
Ok(_) => {}
Err(e) => {
return Err(InstanceError::Download(e));
@@ -220,7 +229,7 @@ impl InstanceManager {
&self.client,
game_version,
effective_loader_version,
&instance_dir,
instance_dir,
&self.meta_dir,
)
.await
@@ -274,7 +283,9 @@ impl InstanceManager {
pub fn rename(&self, old_name: &str, new_name: &str) -> Result<(), InstanceError> {
let new_name = new_name.trim();
if new_name.is_empty() {
return Err(InstanceError::InvalidName("Name cannot be empty".to_string()));
return Err(InstanceError::InvalidName(
"Name cannot be empty".to_string(),
));
}
if old_name == new_name {
return Ok(());
+1 -1
View File
@@ -1,7 +1,7 @@
pub mod launch;
pub mod loader;
pub mod log_files;
pub mod manager;
pub mod loader;
pub mod models;
pub mod mods;
pub mod resource_packs;
+1 -9
View File
@@ -146,15 +146,7 @@ fn read_pack_description(archive: &mut zip::ZipArchive<std::fs::File>) -> String
}
fn read_pack_metadata_from_dir(dir: &Path) -> (String, String, Option<Vec<u8>>) {
let actual_dir = if dir
.file_name()
.and_then(|n| n.to_str())
.is_some_and(|n| n.ends_with(".disabled"))
{
dir.to_path_buf()
} else {
dir.to_path_buf()
};
let actual_dir = dir.to_path_buf();
let description = {
let mcmeta_path = actual_dir.join("pack.mcmeta");
+1 -1
View File
@@ -2,8 +2,8 @@ pub mod auth;
mod cli;
pub mod config;
pub mod instance;
pub mod net;
pub mod instance_logs;
pub mod net;
pub mod running;
pub mod tui;
+3 -13
View File
@@ -41,11 +41,7 @@ pub struct FabricLibrary {
pub url: String,
}
pub async fn fetch_fabric_game_versions(
client: &HttpClient,
) -> Result<Vec<GameVersion>, NetError> {
pub async fn fetch_fabric_game_versions(client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
let url = format!("{}/versions/game", FABRIC_META_BASE);
let response = match client.inner().get(&url).send().await {
Ok(r) => r,
@@ -161,10 +157,7 @@ pub async fn download_fabric_libraries(
let maven_path = match crate::net::maven_coord_to_path(&lib.name) {
Some(p) => p,
None => {
tracing::error!(
"Invalid Maven coordinate in Fabric profile: {}",
lib.name
);
tracing::error!("Invalid Maven coordinate in Fabric profile: {}", lib.name);
return Err(NetError::Parse(format!(
"Invalid Maven coordinate: {}",
lib.name
@@ -188,10 +181,7 @@ pub async fn download_fabric_libraries(
match download_file(client, &download_url, &dest, |_, _| {}).await {
Ok(()) => {}
Err(e) => {
tracing::error!(
"Failed to download Fabric library {}: {}",
lib.name, e
);
tracing::error!("Failed to download Fabric library {}: {}", lib.name, e);
return Err(e);
}
}
+4 -3
View File
@@ -186,8 +186,6 @@ pub async fn run_forge_installer(
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
@@ -198,7 +196,10 @@ mod tests {
let client = HttpClient::new();
match fetch_forge_versions(&client, "1.20.1").await {
Ok(versions) => {
assert!(!versions.is_empty(), "Should have Forge versions for 1.20.1");
assert!(
!versions.is_empty(),
"Should have Forge versions for 1.20.1"
);
}
Err(e) => assert!(false, "fetch_forge_versions failed: {}", e),
}
+8 -3
View File
@@ -4,8 +4,8 @@ pub mod mojang;
pub mod neoforge;
pub mod quilt;
use std::path::Path;
use reqwest::Client;
use std::path::Path;
use thiserror::Error;
#[derive(Debug, Error)]
@@ -35,7 +35,9 @@ impl HttpClient {
Ok(client) => HttpClient { inner: client },
Err(e) => {
tracing::error!("Failed to build HTTP client: {}", e);
HttpClient { inner: Client::new() }
HttpClient {
inner: Client::new(),
}
}
}
}
@@ -66,7 +68,10 @@ pub async fn download_file(
if !response.status().is_success() {
let status = response.status().as_u16();
tracing::error!("HTTP {} for {}", status, url);
return Err(NetError::StatusError { status, url: url.to_string() });
return Err(NetError::StatusError {
status,
url: url.to_string(),
});
}
let total = response.content_length().unwrap_or(0);
+8 -3
View File
@@ -144,9 +144,14 @@ pub async fn download_client_jar(
set_action(format!("Downloading Minecraft {}...", meta.id));
let result = download_file(client, &meta.downloads.client.url, &jar_path, |current, total| {
set_progress(current, total);
})
let result = download_file(
client,
&meta.downloads.client.url,
&jar_path,
|current, total| {
set_progress(current, total);
},
)
.await;
clear();
+2 -8
View File
@@ -6,8 +6,7 @@ use crate::instance::loader::GameVersion;
use crate::net::{download_file, HttpClient, NetError};
use crate::tui::progress::set_action;
const NEOFORGE_MAVEN_BASE: &str =
"https://maven.neoforged.net/releases/net/neoforged/neoforge";
const NEOFORGE_MAVEN_BASE: &str = "https://maven.neoforged.net/releases/net/neoforged/neoforge";
const NEOFORGE_API_BASE: &str =
"https://maven.neoforged.net/api/maven/versions/releases/net/neoforged/neoforge";
@@ -163,10 +162,7 @@ pub async fn download_neoforge_installer(
{
Ok(()) => Ok(()),
Err(e) => {
tracing::error!(
"Failed to download NeoForge installer from {}: {}",
url, e
);
tracing::error!("Failed to download NeoForge installer from {}: {}", url, e);
Err(e)
}
}
@@ -214,8 +210,6 @@ pub async fn run_neoforge_installer(
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
+7 -14
View File
@@ -38,11 +38,7 @@ pub struct QuiltLibrary {
pub url: String,
}
pub async fn fetch_quilt_game_versions(
client: &HttpClient,
) -> Result<Vec<GameVersion>, NetError> {
pub async fn fetch_quilt_game_versions(client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
let url = format!("{}/versions/game", QUILT_META_BASE);
let response = match client.inner().get(&url).send().await {
@@ -159,10 +155,7 @@ pub async fn download_quilt_libraries(
let maven_path = match crate::net::maven_coord_to_path(&lib.name) {
Some(p) => p,
None => {
tracing::error!(
"Invalid Maven coordinate in Quilt profile: {}",
lib.name
);
tracing::error!("Invalid Maven coordinate in Quilt profile: {}", lib.name);
return Err(NetError::Parse(format!(
"Invalid Maven coordinate: {}",
lib.name
@@ -186,10 +179,7 @@ pub async fn download_quilt_libraries(
match download_file(client, &download_url, &dest, |_, _| {}).await {
Ok(()) => {}
Err(e) => {
tracing::error!(
"Failed to download Quilt library {}: {}",
lib.name, e
);
tracing::error!("Failed to download Quilt library {}: {}", lib.name, e);
return Err(e);
}
}
@@ -208,7 +198,10 @@ mod tests {
let client = HttpClient::new();
match fetch_quilt_versions(&client, "1.20.1").await {
Ok(versions) => {
assert!(!versions.is_empty(), "Should have Quilt versions for 1.20.1");
assert!(
!versions.is_empty(),
"Should have Quilt versions for 1.20.1"
);
}
Err(e) => assert!(false, "fetch_quilt_versions failed: {}", e),
}
-3
View File
@@ -6,9 +6,6 @@ use std::time::Instant;
use once_cell::sync::Lazy;
use tracing::Level;
pub const AUTO_DISMISS_MS: u128 = 5000;
pub const SLIDE_START_MS: u128 = 3500;
const MAX_ERROR_EVENTS: usize = 50;
static NEXT_ERROR_ID: AtomicU64 = AtomicU64::new(1);
+87 -58
View File
@@ -6,8 +6,8 @@ use super::{
use crate::instance::{InstanceConfig, InstanceManager};
use crate::tui::error_buffer;
use crate::tui::progress;
use crate::tui::widgets::popups::confirm::{confirm_popup_area, ConfirmPopup};
use crate::tui::widgets::popups::confirm as confirm_popup;
use crate::tui::widgets::popups::confirm::{confirm_popup_area, ConfirmPopup};
use crate::tui::widgets::popups::error::{popup_area, ErrorPopup};
use color_eyre::eyre::Context;
use crossterm::event::{self, Event};
@@ -150,7 +150,7 @@ impl App {
if self.throbber_tick % 8 == 0 {
self.throbber_state.calc_next();
}
terminal.draw(|frame| self.render_frame(frame))?;
self.handle_events().wrap_err("handle events failed")?;
@@ -212,7 +212,12 @@ impl App {
])
.split(main_chunks[2]);
widgets::account::render(frame, bottom_chunks[0], self.focused, &mut self.account_state);
widgets::account::render(
frame,
bottom_chunks[0],
self.focused,
&mut self.account_state,
);
widgets::details::render(
frame,
bottom_chunks[1],
@@ -220,7 +225,12 @@ impl App {
self.profiles_state.selected_instance(),
&self.instance_manager.instances_dir,
);
widgets::status::render(frame, bottom_chunks[2], self.focused, &mut self.throbber_state);
widgets::status::render(
frame,
bottom_chunks[2],
self.focused,
&mut self.throbber_state,
);
if self.focused == FocusedArea::OverviewExpanded {
self.render_log_overlay(frame);
@@ -257,18 +267,16 @@ impl App {
fn handle_events(&mut self) -> color_eyre::Result<()> {
match crossterm::event::poll(Duration::from_millis(16)) {
Ok(true) => {
match event::read() {
Ok(Event::Key(key_event)) if key_event.kind == KeyEventKind::Press => self
.handle_key_event(key_event)
.wrap_err_with(|| format!("handling key event failed:\n{key_event:#?}")),
Ok(_) => Ok(()),
Err(e) => {
tracing::error!("Event read error: {}", e);
Ok(())
}
Ok(true) => match event::read() {
Ok(Event::Key(key_event)) if key_event.kind == KeyEventKind::Press => self
.handle_key_event(key_event)
.wrap_err_with(|| format!("handling key event failed:\n{key_event:#?}")),
Ok(_) => Ok(()),
Err(e) => {
tracing::error!("Event read error: {}", e);
Ok(())
}
}
},
Ok(false) => Ok(()),
Err(e) => {
tracing::error!("Event poll error: {}", e);
@@ -363,17 +371,11 @@ impl App {
return Ok(());
}
} else if self.content_tab == widgets::content::ContentTab::Screenshots {
if widgets::screenshots_grid::handle_key(
&key_event,
&mut self.screenshots_state,
) {
if widgets::screenshots_grid::handle_key(&key_event, &mut self.screenshots_state) {
return Ok(());
}
} else if self.content_tab == widgets::content::ContentTab::Worlds {
if widgets::content_list::handle_key_no_toggle(
&key_event,
&mut self.worlds_state,
) {
if widgets::content_list::handle_key_no_toggle(&key_event, &mut self.worlds_state) {
return Ok(());
}
} else {
@@ -427,7 +429,12 @@ impl App {
let old_name = inst.name.clone();
match self.instance_manager.rename(&old_name, &new_name) {
Ok(()) => {
if let Some(inst) = self.profiles_state.instances.iter_mut().find(|i| i.name == old_name) {
if let Some(inst) = self
.profiles_state
.instances
.iter_mut()
.find(|i| i.name == old_name)
{
inst.name = new_name.trim().to_string();
}
}
@@ -496,7 +503,9 @@ impl App {
&& key_event.modifiers.contains(KeyModifiers::SHIFT) =>
{
if let Some(instance) = self.profiles_state.selected_instance() {
let dir = self.instance_manager.instances_dir
let dir = self
.instance_manager
.instances_dir
.join(&instance.name)
.join(".minecraft");
if let Err(e) = std::process::Command::new("xdg-open")
@@ -601,7 +610,9 @@ impl App {
fn run_editor(terminal: &mut ratatui::DefaultTerminal, path: &std::path::Path) {
use ratatui::crossterm::{
terminal::{disable_raw_mode, enable_raw_mode, LeaveAlternateScreen, EnterAlternateScreen},
terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
},
ExecutableCommand,
};
use std::io::stdout;
@@ -612,7 +623,17 @@ impl App {
let is_tui_editor = matches!(
editor.rsplit('/').next().unwrap_or(&editor),
"vi" | "vim" | "nvim" | "neovim" | "nano" | "micro" | "helix" | "hx" | "emacs" | "ne" | "joe" | "mcedit"
"vi" | "vim"
| "nvim"
| "neovim"
| "nano"
| "micro"
| "helix"
| "hx"
| "emacs"
| "ne"
| "joe"
| "mcedit"
);
if is_tui_editor {
@@ -666,9 +687,13 @@ impl App {
}
fn dismiss_expired_errors(&self) {
use crate::config::SETTINGS;
loop {
match error_buffer::peek_error() {
Some(event) if event.pushed_at.elapsed().as_millis() >= error_buffer::AUTO_DISMISS_MS => {
Some(event)
if event.pushed_at.elapsed().as_millis()
>= SETTINGS.ui.error_auto_dismiss_ms as u128 =>
{
error_buffer::pop_error();
}
_ => break,
@@ -715,9 +740,7 @@ impl App {
layout::{Alignment, Margin},
style::{Modifier, Style},
text::Line,
widgets::{
Block, BorderType, Clear, Paragraph, Scrollbar, ScrollbarOrientation,
},
widgets::{Block, Clear, Paragraph, Scrollbar, ScrollbarOrientation},
};
let area = frame.area();
@@ -732,30 +755,30 @@ impl App {
.collect();
let visible_height = overlay.height.saturating_sub(2) as usize;
let was_at_bottom = self.log_overlay_scroll >= self.log_overlay_max_scroll.saturating_sub(1);
let was_at_bottom =
self.log_overlay_scroll >= self.log_overlay_max_scroll.saturating_sub(1);
self.log_overlay_max_scroll = filtered.len().saturating_sub(visible_height);
if was_at_bottom {
self.log_overlay_scroll = self.log_overlay_max_scroll;
} else if self.log_overlay_scroll > self.log_overlay_max_scroll {
if was_at_bottom || self.log_overlay_scroll > self.log_overlay_max_scroll {
self.log_overlay_scroll = self.log_overlay_max_scroll;
}
self.log_overlay_scrollbar = ratatui::widgets::ScrollbarState::new(
self.log_overlay_max_scroll,
)
.position(self.log_overlay_scroll);
self.log_overlay_scrollbar =
ratatui::widgets::ScrollbarState::new(self.log_overlay_max_scroll)
.position(self.log_overlay_scroll);
let mut block = Block::bordered()
.title_top(Line::from(" Logs ").style(
Style::default()
.fg(THEME.colors.foreground)
.add_modifier(Modifier::BOLD),
))
.title_top(
Line::from(" Logs ").style(
Style::default()
.fg(THEME.log_overlay.text_fg)
.add_modifier(Modifier::BOLD),
),
)
.title_bottom(
crate::tui::widgets::popups::keybind_line(&[("O", " close"), ("/", " search")])
.alignment(Alignment::Right),
)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(THEME.colors.border_focused));
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(THEME.log_overlay.border_fg));
if let Some(sl) = self.log_overlay_search.title_line() {
block = block.title_top(sl);
@@ -771,13 +794,13 @@ impl App {
.take(visible_height)
.map(|line| {
let style = if line.contains("ERROR") || line.contains("FATAL") {
Style::default().fg(THEME.colors.error)
Style::default().fg(THEME.log_overlay.error_fg)
} else if line.contains("WARN") {
Style::default().fg(THEME.colors.warn)
Style::default().fg(THEME.log_overlay.warn_fg)
} else if line.contains("DEBUG") || line.contains("TRACE") {
Style::default().fg(THEME.colors.text_idle)
Style::default().fg(THEME.log_overlay.debug_fg)
} else {
Style::default().fg(THEME.colors.foreground)
Style::default().fg(THEME.log_overlay.text_fg)
};
search.highlight_line(line, style)
})
@@ -797,7 +820,7 @@ impl App {
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.log_overlay.border_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2503}")
@@ -810,7 +833,8 @@ impl App {
fn sync_error_effects(&mut self, events: &[error_buffer::ErrorEvent]) {
use crate::tui::theme::THEME;
let active_ids: std::collections::HashSet<u64> = events.iter().map(|event| event.id).collect();
let active_ids: std::collections::HashSet<u64> =
events.iter().map(|event| event.id).collect();
self.error_effects.retain(|id, _| active_ids.contains(id));
for event in events {
@@ -819,7 +843,7 @@ impl App {
Motion::RightToLeft,
8,
0,
THEME.colors.popup_bg,
THEME.log_overlay.bg,
(300, Interpolation::SineOut),
))
});
@@ -833,19 +857,24 @@ impl App {
event: &error_buffer::ErrorEvent,
elapsed_ms: u128,
) {
use crate::config::SETTINGS;
use crate::tui::theme::THEME;
const FLY_OUT_MS: u128 = 300;
let fly_start_ms = error_buffer::AUTO_DISMISS_MS.saturating_sub(FLY_OUT_MS);
let fly_out_ms = SETTINGS.ui.error_fly_out_ms as u128;
let fly_start_ms = SETTINGS.ui.error_auto_dismiss_ms as u128
- fly_out_ms.min(SETTINGS.ui.error_auto_dismiss_ms as u128);
if elapsed_ms >= fly_start_ms {
let entry = self.error_effects.entry(event.id).or_insert(ErrorEffectState::Idle);
let entry = self
.error_effects
.entry(event.id)
.or_insert(ErrorEffectState::Idle);
if !matches!(entry, ErrorEffectState::FadingOut(_)) {
*entry = ErrorEffectState::FadingOut(fx::slide_out(
Motion::LeftToRight,
8,
0,
THEME.colors.popup_bg,
(FLY_OUT_MS as u32, Interpolation::SineIn),
THEME.log_overlay.bg,
(fly_out_ms as u32, Interpolation::SineIn),
));
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
pub mod error_buffer;
pub mod layout;
pub mod logging;
pub mod error_buffer;
pub mod progress;
pub mod theme;
pub mod widgets;
+1515 -2
View File
File diff suppressed because it is too large. Load diff
+51 -45
View File
@@ -5,7 +5,7 @@ use ratatui::{
layout::Rect,
style::{Color, Modifier, Style},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph, Widget},
widgets::{Block, Borders, Paragraph, Widget},
Frame,
};
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
@@ -214,15 +214,15 @@ pub fn drain_device_code(state: &mut AccountState) {
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut AccountState) {
let color = if focused == FocusedArea::Account {
THEME.colors.border_focused
THEME.account.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.account.border_unfocused_fg
};
let mut block = Block::default()
.title(styled_title("Accounts", true))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(color));
if focused == FocusedArea::Account {
@@ -240,7 +240,8 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut A
if state.store.accounts.is_empty() {
frame.render_widget(
Paragraph::new("No accounts.").style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new("No accounts.")
.style(Style::default().fg(THEME.account.text_secondary_fg)),
inner,
);
} else {
@@ -284,14 +285,10 @@ fn render_account_list(
let (username, acc_type, is_active) = &accounts[context.index];
let show_selected = is_focused && context.is_selected;
let stripe_bg = if context.index % 2 == 0 {
Color::Reset
} else {
THEME.colors.row_alternate_bg
};
let stripe_bg = Color::Reset;
let bg = if show_selected {
THEME.colors.row_background
THEME.account.selected_bg
} else {
stripe_bg
};
@@ -299,27 +296,33 @@ fn render_account_list(
let active_marker = if *is_active { "\u{25b8} " } else { " " };
let style = if show_selected {
Style::default()
.fg(THEME.colors.row_highlight)
.add_modifier(Modifier::BOLD)
let mut s = Style::default().fg(THEME.account.selected_fg);
if THEME.account.selected_bold {
s = s.add_modifier(Modifier::BOLD);
}
s
} else if *is_active {
Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.account.text_fg)
.add_modifier(Modifier::BOLD)
} else {
Style::default().fg(THEME.colors.foreground)
Style::default().fg(THEME.account.text_fg)
};
let mut spans = vec![
Span::styled(active_marker, Style::default().fg(THEME.colors.accent)),
Span::styled(active_marker, Style::default().fg(THEME.account.active_fg)),
Span::styled(username.clone(), style),
];
if *acc_type == AccountType::Offline {
let offline_style = if show_selected {
Style::default().fg(THEME.colors.row_highlight)
let mut s = Style::default().fg(THEME.account.selected_fg);
if THEME.account.selected_bold {
s = s.add_modifier(Modifier::BOLD);
}
s
} else {
Style::default().fg(THEME.colors.text_idle)
Style::default().fg(THEME.account.text_secondary_fg)
};
spans.push(Span::styled(" (Offline)", offline_style));
}
@@ -350,11 +353,11 @@ fn render_choose_popup(frame: &mut Frame) {
PopupFrame {
title: Line::from(" Add Account ").centered(),
border_color: THEME.colors.border_focused,
border_color: THEME.account.border_focused_fg,
bg: None,
keybinds: Some(Line::from(Span::styled(
" Esc: cancel ",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.account.text_secondary_fg),
))),
search_line: None,
content: Box::new(|inner, buf| {
@@ -364,24 +367,24 @@ fn render_choose_popup(frame: &mut Frame) {
Span::styled(
" [m] ",
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.account.active_fg)
.add_modifier(Modifier::BOLD),
),
Span::styled(
"Microsoft Account",
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.account.text_fg),
),
]),
Line::from(vec![
Span::styled(
" [o] ",
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.account.active_fg)
.add_modifier(Modifier::BOLD),
),
Span::styled(
"Offline Account",
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.account.text_fg),
),
]),
];
@@ -400,12 +403,12 @@ fn render_offline_popup(frame: &mut Frame, name: &str) {
title: Line::from(Span::styled(
" Offline Account ",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.account.border_focused_fg)
.add_modifier(Modifier::BOLD),
))
.centered(),
border_color: THEME.colors.border_focused,
bg: Some(THEME.colors.popup_bg),
border_color: THEME.account.border_focused_fg,
bg: Some(THEME.account.popup_bg),
keybinds: Some(keybind_line(&[("Enter", " confirm"), ("Esc", " cancel")])),
search_line: None,
content: Box::new(move |inner, buf| {
@@ -413,22 +416,22 @@ fn render_offline_popup(frame: &mut Frame, name: &str) {
Line::from(vec![
Span::styled(
"Username...",
Style::default().fg(THEME.colors.border_unfocused),
Style::default().fg(THEME.account.border_unfocused_fg),
),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.account.border_focused_fg)
.add_modifier(Modifier::SLOW_BLINK),
),
])
} else {
Line::from(vec![
Span::styled(name.as_str(), Style::default().fg(THEME.colors.foreground)),
Span::styled(name.as_str(), Style::default().fg(THEME.account.text_fg)),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.account.border_focused_fg)
.add_modifier(Modifier::SLOW_BLINK),
),
])
@@ -451,7 +454,7 @@ fn render_confirm_delete(frame: &mut Frame, state: &AccountState, idx: usize) {
let title = Line::from(Span::styled(
format!(" Delete '{}' ", username),
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.account.border_focused_fg)
.add_modifier(Modifier::BOLD),
));
@@ -461,13 +464,13 @@ fn render_confirm_delete(frame: &mut Frame, state: &AccountState, idx: usize) {
PopupFrame {
title,
border_color: THEME.colors.border_focused,
bg: Some(THEME.colors.row_alternate_bg),
border_color: THEME.account.border_focused_fg,
bg: Some(THEME.account.popup_bg),
keybinds: Some(keybind_line(&[("Enter", " confirm")])),
search_line: None,
content: Box::new(|inner, buf| {
Paragraph::new("This will permanently remove this account")
.style(Style::default().fg(THEME.colors.foreground))
.style(Style::default().fg(THEME.account.text_fg))
.render(inner, buf);
}),
}
@@ -484,46 +487,49 @@ fn render_device_code_popup(frame: &mut Frame, info: &DeviceCodeInfo) {
title: Line::from(Span::styled(
" Microsoft Login ",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.account.border_focused_fg)
.add_modifier(Modifier::BOLD),
))
.centered(),
border_color: THEME.colors.border_focused,
bg: Some(THEME.colors.popup_bg),
border_color: THEME.account.border_focused_fg,
bg: Some(THEME.account.popup_bg),
keybinds: Some(keybind_line(&[("Esc", " cancel")])),
search_line: None,
content: Box::new(move |inner, buf| {
let text = if code.is_empty() {
vec![Line::from(Span::styled(
"Connecting to Microsoft...",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.account.text_secondary_fg),
))]
} else {
vec![
Line::from(Span::styled(
"Open this URL in your browser:",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.account.text_secondary_fg),
)),
Line::from(Span::styled(
uri.as_str(),
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.account.active_fg)
.add_modifier(Modifier::BOLD),
)),
Line::from(""),
Line::from(vec![
Span::styled("Enter code: ", Style::default().fg(THEME.colors.text_idle)),
Span::styled(
"Enter code: ",
Style::default().fg(THEME.account.text_secondary_fg),
),
Span::styled(
code.as_str(),
Style::default()
.fg(THEME.colors.success)
.fg(THEME.account.active_fg)
.add_modifier(Modifier::BOLD),
),
]),
Line::from(""),
Line::from(Span::styled(
"Waiting for authentication...",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.account.text_secondary_fg),
)),
]
};
+29 -29
View File
@@ -2,7 +2,7 @@ use ratatui::{
layout::{Alignment, Constraint, Layout, Rect},
style::{Modifier, Style},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph},
widgets::{Block, Borders, Paragraph},
Frame,
};
use throbber_widgets_tui::{Throbber, ThrobberState};
@@ -79,9 +79,9 @@ pub fn render(
let is_focused = focused == FocusedArea::Content;
let border_color = if is_focused {
THEME.colors.border_focused
THEME.content.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.content.border_unfocused_fg
};
let tab_titles: Vec<Span> = ContentTab::ALL
@@ -92,21 +92,21 @@ pub fn render(
if i > 0 {
spans.push(Span::styled(
"\u{2022}",
Style::default().fg(THEME.colors.border_unfocused),
Style::default().fg(THEME.content.border_unfocused_fg),
));
}
if i == tab.index() {
spans.push(Span::styled(
format!(" {} ", t.label()),
Style::default()
.fg(THEME.colors.accent)
.bg(THEME.colors.row_background)
.add_modifier(Modifier::BOLD),
));
let mut style = Style::default()
.fg(THEME.content.tab_active_fg)
.bg(THEME.content.selected_bg);
if THEME.content.tab_active_bold {
style = style.add_modifier(Modifier::BOLD);
}
spans.push(Span::styled(format!(" {} ", t.label()), style));
} else {
spans.push(Span::styled(
format!(" {} ", t.label()),
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.content.text_fg),
));
}
spans
@@ -131,7 +131,7 @@ pub fn render(
let mut block = Block::default()
.title_top(Line::from(tab_titles))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(border_color));
if let Some(sl) = search_line {
@@ -224,7 +224,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -249,7 +249,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -274,7 +274,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -288,7 +288,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -302,7 +302,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -327,7 +327,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -343,15 +343,15 @@ pub fn title(
throbber_state: &mut ThrobberState,
) {
let color = if focused == FocusedArea::Content {
THEME.colors.border_focused
THEME.content.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.content.border_unfocused_fg
};
let block = Block::default()
.title(styled_title("Content", true))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(color));
let inner = block.inner(area);
@@ -361,7 +361,7 @@ pub fn title(
None => {
frame.render_widget(
Paragraph::new("No instance selected")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
inner,
);
}
@@ -380,12 +380,12 @@ pub fn title(
.label(inst.name.as_str())
.style(
Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.content.text_fg)
.add_modifier(Modifier::BOLD),
)
.throbber_style(
Style::default()
.fg(THEME.colors.success)
.fg(THEME.general.success)
.add_modifier(Modifier::BOLD),
)
.throbber_set(throbber_widgets_tui::BRAILLE_EIGHT_DOUBLE)
@@ -398,13 +398,13 @@ pub fn title(
Span::styled(
"\u{2717} ",
Style::default()
.fg(THEME.colors.error)
.fg(THEME.general.error)
.add_modifier(Modifier::BOLD),
),
Span::styled(
inst.name.as_str(),
Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.content.text_fg)
.add_modifier(Modifier::BOLD),
),
])),
@@ -416,7 +416,7 @@ pub fn title(
Paragraph::new(Span::styled(
inst.name.as_str(),
Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.content.text_fg)
.add_modifier(Modifier::BOLD),
)),
left_area,
@@ -430,7 +430,7 @@ pub fn title(
};
frame.render_widget(
Paragraph::new(loader_str)
.style(Style::default().fg(THEME.colors.border_focused))
.style(Style::default().fg(THEME.content.border_focused_fg))
.alignment(Alignment::Right),
right_area,
);
+47 -49
View File
@@ -239,11 +239,7 @@ pub fn handle_key_no_toggle(key_event: &KeyEvent, state: &mut ContentListState)
true
}
KeyCode::Enter if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
if let Some(&real_idx) = state
.list_state
.selected
.and_then(|i| filtered.get(i))
{
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i)) {
if let Some(dir) = state.entries[real_idx].path.parent() {
if let Err(e) = std::process::Command::new("xdg-open")
.arg(dir)
@@ -285,11 +281,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
true
}
KeyCode::Enter if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
if let Some(&real_idx) = state
.list_state
.selected
.and_then(|i| filtered.get(i))
{
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i)) {
if let Some(dir) = state.entries[real_idx].path.parent() {
if let Err(e) = std::process::Command::new("xdg-open")
.arg(dir)
@@ -304,19 +296,11 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
true
}
KeyCode::Enter => {
if let Some(&real_idx) = state
.list_state
.selected
.and_then(|i| filtered.get(i))
{
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i)) {
state.list_state.selected = Some(real_idx);
state.toggle_selected();
state.list_state.selected = Some(
filtered
.iter()
.position(|&i| i == real_idx)
.unwrap_or(0),
);
state.list_state.selected =
Some(filtered.iter().position(|&i| i == real_idx).unwrap_or(0));
}
true
}
@@ -334,7 +318,8 @@ pub fn render(
) {
if state.loading {
frame.render_widget(
Paragraph::new(loading_text).style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new(loading_text)
.style(Style::default().fg(THEME.content_list.text_secondary_fg)),
area,
);
return;
@@ -344,7 +329,8 @@ pub fn render(
if filtered.is_empty() {
frame.render_widget(
Paragraph::new(empty_text).style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new(empty_text)
.style(Style::default().fg(THEME.content_list.text_secondary_fg)),
area,
);
return;
@@ -373,38 +359,50 @@ pub fn render(
let stripe_bg = if context.index % 2 == 0 {
Color::Reset
} else {
THEME.colors.row_alternate_bg
THEME.content_list.row_alt_bg
};
let (name_style, description_style, background) = match (*enabled, show_selected) {
(true, true) => (
Style::default()
.fg(THEME.colors.row_highlight)
.add_modifier(Modifier::BOLD),
Style::default().fg(THEME.colors.row_highlight),
THEME.colors.row_background,
),
(true, true) => {
let mut ns = Style::default().fg(THEME.content_list.selected_fg);
if THEME.content_list.selected_bold {
ns = ns.add_modifier(Modifier::BOLD);
}
(
ns,
Style::default().fg(THEME.content_list.selected_fg),
THEME.content_list.selected_bg,
)
}
(true, false) => (
Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.content_list.text_fg)
.add_modifier(Modifier::BOLD),
Style::default().fg(THEME.colors.text_idle),
stripe_bg,
),
(false, true) => (
Style::default()
.fg(THEME.colors.row_highlight)
.add_modifier(Modifier::CROSSED_OUT),
Style::default().fg(THEME.colors.row_highlight),
THEME.colors.row_background,
),
(false, false) => (
Style::default()
.fg(THEME.colors.text_idle)
.add_modifier(Modifier::CROSSED_OUT),
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.content_list.text_secondary_fg),
stripe_bg,
),
(false, true) => {
let mut ns = Style::default().fg(THEME.content_list.selected_fg);
if THEME.content_list.disabled_crossed_out {
ns = ns.add_modifier(Modifier::CROSSED_OUT);
}
(
ns,
Style::default().fg(THEME.content_list.selected_fg),
THEME.content_list.selected_bg,
)
}
(false, false) => {
let mut ns = Style::default().fg(THEME.content_list.text_secondary_fg);
if THEME.content_list.disabled_crossed_out {
ns = ns.add_modifier(Modifier::CROSSED_OUT);
}
(
ns,
Style::default().fg(THEME.content_list.text_secondary_fg),
stripe_bg,
)
}
};
let has_icon = icon_pixels.is_some();
@@ -488,7 +486,7 @@ pub fn render(
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.content_list.border_focused_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2551}")
@@ -599,7 +597,7 @@ fn icon_spans(icon_pixels: Option<&Vec<Vec<IconCell>>>, row: usize) -> Vec<Span<
.collect(),
None => vec![Span::styled(
" ",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.content_list.text_secondary_fg),
)],
}
}
+8 -8
View File
@@ -2,7 +2,7 @@ use ratatui::{
layout::Rect,
style::{Modifier, Style},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph},
widgets::{Block, Borders, Paragraph},
Frame,
};
@@ -20,15 +20,15 @@ pub fn render(
_instances_dir: &std::path::Path,
) {
let color = if focused == FocusedArea::Settings {
THEME.colors.border_focused
THEME.details.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.details.border_unfocused_fg
};
let mut block = Block::default()
.title(styled_title("Settings", true))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(color));
if focused == FocusedArea::Settings {
@@ -47,17 +47,17 @@ pub fn render(
let Some(inst) = instance else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.details.label_fg)),
inner,
);
return;
};
let label_style = Style::default().fg(THEME.colors.text_idle);
let label_style = Style::default().fg(THEME.details.label_fg);
let value_style = Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.details.value_fg)
.add_modifier(Modifier::BOLD);
let dim_style = Style::default().fg(THEME.colors.border_unfocused);
let dim_style = Style::default().fg(THEME.details.border_unfocused_fg);
let memory_min = inst.memory_min.as_deref().unwrap_or("512M");
let memory_max = inst.memory_max.as_deref().unwrap_or("2G");
+39 -33
View File
@@ -6,9 +6,7 @@ use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style},
text::{Line, Span},
widgets::{
Block, BorderType, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState,
},
widgets::{Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
Frame,
};
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
@@ -246,27 +244,27 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut LogsState) -> bool {
KeyCode::Char('j') | KeyCode::Down => {
if state.viewer_scroll < state.viewer_max_scroll {
state.viewer_scroll += 1;
state.viewer_scrollbar_state = ScrollbarState::new(state.viewer_max_scroll)
.position(state.viewer_scroll);
state.viewer_scrollbar_state =
ScrollbarState::new(state.viewer_max_scroll).position(state.viewer_scroll);
}
true
}
KeyCode::Char('k') | KeyCode::Up => {
state.viewer_scroll = state.viewer_scroll.saturating_sub(1);
state.viewer_scrollbar_state = ScrollbarState::new(state.viewer_max_scroll)
.position(state.viewer_scroll);
state.viewer_scrollbar_state =
ScrollbarState::new(state.viewer_max_scroll).position(state.viewer_scroll);
true
}
KeyCode::Char('G') => {
state.viewer_scroll = state.viewer_max_scroll;
state.viewer_scrollbar_state = ScrollbarState::new(state.viewer_max_scroll)
.position(state.viewer_scroll);
state.viewer_scrollbar_state =
ScrollbarState::new(state.viewer_max_scroll).position(state.viewer_scroll);
true
}
KeyCode::Char('g') => {
state.viewer_scroll = 0;
state.viewer_scrollbar_state = ScrollbarState::new(state.viewer_max_scroll)
.position(state.viewer_scroll);
state.viewer_scrollbar_state =
ScrollbarState::new(state.viewer_max_scroll).position(state.viewer_scroll);
true
}
KeyCode::Esc => {
@@ -344,7 +342,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut LogsState) -> bool {
pub fn render(frame: &mut Frame, area: Rect, state: &mut LogsState, is_focused: bool) {
if state.loading {
frame.render_widget(
Paragraph::new("Loading logs...").style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new("Loading logs...").style(Style::default().fg(THEME.logs.text_fg)),
area,
);
return;
@@ -355,7 +353,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut LogsState, is_focused:
if display_count == 0 {
frame.render_widget(
Paragraph::new("No logs yet.").style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new("No logs yet.").style(Style::default().fg(THEME.logs.text_fg)),
area,
);
return;
@@ -382,14 +380,14 @@ fn render_list(
) {
let list_focused = is_focused && !state.viewer_focused;
let border_color = if list_focused {
THEME.colors.border_focused
THEME.logs.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.logs.border_unfocused_fg
};
let block = Block::default()
.borders(Borders::RIGHT)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(border_color));
let inner = block.inner(area);
@@ -413,25 +411,31 @@ fn render_list(
let show_selected = list_focused && context.is_selected;
let style = if *is_live && show_selected {
Style::default()
.fg(THEME.colors.success)
.add_modifier(Modifier::BOLD)
let s = Style::default().fg(THEME.logs.running_fg);
if THEME.logs.selected_bold {
s.add_modifier(Modifier::BOLD)
} else {
s
}
} else if *is_live {
Style::default().fg(THEME.colors.success)
Style::default().fg(THEME.logs.running_fg)
} else if show_selected {
Style::default()
.fg(THEME.colors.row_highlight)
.add_modifier(Modifier::BOLD)
let s = Style::default().fg(THEME.logs.selected_fg);
if THEME.logs.selected_bold {
s.add_modifier(Modifier::BOLD)
} else {
s
}
} else {
Style::default().fg(THEME.colors.text_idle)
Style::default().fg(THEME.logs.text_fg)
};
let bg = if show_selected {
THEME.colors.row_background
THEME.logs.selected_bg
} else if context.index % 2 == 0 {
Color::Reset
} else {
THEME.colors.row_alternate_bg
THEME.logs.row_alt_bg
};
let item = ratatui::text::Text::from(Line::from(Span::styled(name.clone(), style)))
@@ -454,7 +458,7 @@ fn render_list(
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.logs.border_focused_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2551}")
@@ -522,7 +526,7 @@ fn render_viewer(
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.logs.border_focused_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2551}")
@@ -536,12 +540,14 @@ fn render_viewer(
fn line_level_style(line: &str) -> Style {
let upper = line.to_uppercase();
if upper.contains("ERROR") || upper.contains("FATAL") || upper.contains("[STDERR]") {
Style::default().fg(THEME.colors.error)
Style::default().fg(THEME.logs.error_fg)
} else if upper.contains("WARN") {
Style::default().fg(THEME.colors.warn)
} else if upper.contains("DEBUG") || upper.contains("TRACE") {
Style::default().fg(THEME.colors.text_idle)
Style::default().fg(THEME.logs.warn_fg)
} else if upper.contains("DEBUG") {
Style::default().fg(THEME.logs.debug_fg)
} else if upper.contains("TRACE") {
Style::default().fg(THEME.logs.trace_fg)
} else {
Style::default().fg(THEME.colors.foreground)
Style::default().fg(THEME.logs.text_fg)
}
}
+3 -3
View File
@@ -1,18 +1,18 @@
use crate::tui::theme::THEME;
use crossterm::event::KeyEvent;
use ratatui::{
style::Style,
text::{Line, Span},
};
use crate::tui::theme::THEME;
pub mod account;
pub mod content;
pub mod content_list;
pub mod details;
pub mod logs_viewer;
pub mod screenshots_grid;
pub mod popups;
pub mod profiles;
pub mod screenshots_grid;
pub mod search;
pub mod status;
@@ -24,7 +24,7 @@ pub fn styled_title(title: &str, highlight: bool) -> Line<'_> {
let first = chars.next().unwrap_or_default().to_string();
let rest: String = chars.collect();
Line::from(vec![
Span::styled(first, Style::default().fg(THEME.colors.accent)),
Span::styled(first, Style::default().fg(THEME.general.accent)),
Span::raw(rest),
])
}
+4 -2
View File
@@ -3,9 +3,11 @@ use ratatui::{
layout::{Alignment, Rect},
style::{Color, Style},
text::Line,
widgets::{Block, BorderType, Clear, Widget},
widgets::{Block, Clear, Widget},
};
use crate::tui::theme::THEME;
pub struct PopupFrame<'a> {
pub title: Line<'a>,
pub border_color: Color,
@@ -25,7 +27,7 @@ impl<'a> Widget for PopupFrame<'a> {
let mut block = Block::bordered()
.title_top(self.title)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(self.border_color));
if let Some(sl) = self.search_line {
+4 -4
View File
@@ -66,20 +66,20 @@ impl Widget for ConfirmPopup {
let title = Line::from(vec![Span::styled(
format!(" Delete '{}' ", self.instance_name),
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.popup_confirm.border_fg)
.add_modifier(Modifier::BOLD),
)]);
let kb = keybind_line(&[("Enter", " confirm")]);
let popup = PopupFrame {
title,
border_color: THEME.colors.border_focused,
bg: Some(THEME.colors.row_alternate_bg),
border_color: THEME.popup_confirm.border_fg,
bg: Some(THEME.popup_confirm.highlight_bg),
keybinds: Some(kb),
search_line: None,
content: Box::new(|inner, buf| {
Paragraph::new("This will permanently remove the instance")
.style(Style::default().fg(THEME.colors.foreground))
.style(Style::default().fg(THEME.popup_confirm.text_fg))
.render(inner, buf);
}),
};
+9 -8
View File
@@ -8,7 +8,8 @@ use ratatui::{
use tracing::Level;
use super::base::PopupFrame;
use crate::tui::error_buffer::{ErrorEvent, AUTO_DISMISS_MS};
use crate::config::SETTINGS;
use crate::tui::error_buffer::ErrorEvent;
use crate::tui::theme::THEME;
pub struct ErrorPopup {
@@ -24,15 +25,15 @@ impl ErrorPopup {
impl Widget for ErrorPopup {
fn render(self, area: Rect, buf: &mut Buffer) {
let (border_color, label) = match self.event.level {
Level::ERROR => (THEME.colors.error, "ERROR"),
Level::WARN => (THEME.colors.warn, "WARN"),
_ => (THEME.colors.border_focused, "INFO"),
Level::ERROR => (THEME.popup_error.error_fg, "ERROR"),
Level::WARN => (THEME.popup_error.warn_fg, "WARN"),
_ => (THEME.popup_error.border_fg, "INFO"),
};
let title = Line::from(vec![Span::styled(
format!(" {} ", label),
Style::default()
.fg(THEME.colors.badge_text)
.fg(THEME.popup_error.badge_text_fg)
.bg(border_color)
.add_modifier(Modifier::BOLD),
)]);
@@ -41,13 +42,13 @@ impl Widget for ErrorPopup {
let popup = PopupFrame {
title,
border_color,
bg: Some(THEME.colors.popup_bg),
bg: Some(THEME.popup_error.bg),
keybinds: None,
search_line: None,
content: Box::new(move |inner, buf| {
Paragraph::new(message.as_str())
.wrap(Wrap { trim: true })
.style(Style::default().fg(THEME.colors.foreground))
.style(Style::default().fg(THEME.popup_error.text_fg))
.render(inner, buf);
}),
};
@@ -62,7 +63,7 @@ pub fn popup_area(frame_area: Rect, message: &str, base_y: u16, elapsed_ms: u128
const MAX_W: usize = 58;
const MIN_W: usize = 22;
if elapsed_ms >= AUTO_DISMISS_MS {
if elapsed_ms >= SETTINGS.ui.error_auto_dismiss_ms as u128 {
return None;
}
+29 -12
View File
@@ -46,17 +46,26 @@ pub fn top_right_rect(frame: Rect, inner_w: usize, inner_h: usize) -> Rect {
let popup_h = popup_h.min(frame.height.saturating_sub(2));
let x = frame.width.saturating_sub(popup_w + 2);
let y = 1u16;
Rect { x, y, width: popup_w, height: popup_h }
Rect {
x,
y,
width: popup_w,
height: popup_h,
}
}
pub fn keybind_line(binds: &[(&str, &str)]) -> ratatui::text::Line<'static> {
use ratatui::{style::{Modifier, Style}, text::{Line, Span}};
use crate::tui::theme::THEME;
use ratatui::{
style::{Modifier, Style},
text::{Line, Span},
};
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 key_style = Style::default().fg(THEME.popup.keybind_active_fg);
if THEME.popup.keybind_active_bold {
key_style = key_style.add_modifier(Modifier::BOLD);
}
let dim_style = Style::default().fg(THEME.popup.keybind_inactive_fg);
let mut spans: Vec<Span<'static>> = Vec::new();
for (i, (key, label)) in binds.iter().enumerate() {
@@ -75,20 +84,28 @@ 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;
use ratatui::{
style::{Modifier, Style},
text::{Line, Span},
};
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 key_style = Style::default().fg(THEME.popup.keybind_active_fg);
if THEME.popup.keybind_active_bold {
key_style = key_style.add_modifier(Modifier::BOLD);
}
let dim_style = Style::default().fg(THEME.popup.keybind_inactive_fg);
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 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;
+58 -53
View File
@@ -1,5 +1,8 @@
use super::base::PopupFrame;
use crate::instance::{loader::{get_installer, GameVersion}, models::ModLoader};
use crate::instance::{
loader::{get_installer, GameVersion},
models::ModLoader,
};
use crate::tui::layout::FocusedArea;
use crate::tui::theme::THEME;
use crate::tui::widgets::profiles;
@@ -15,8 +18,10 @@ use ratatui::{
use std::sync::{Arc, Mutex};
use tui_prompts::{FocusState, State as PromptState, TextState};
static WIZARD_STATE: Lazy<Arc<Mutex<WizardState>>> = Lazy::new(|| Arc::new(Mutex::new(WizardState::default())));
static WIZARD_RESULT: Lazy<Arc<Mutex<Option<WizardParams>>>> = Lazy::new(|| Arc::new(Mutex::new(None)));
static WIZARD_STATE: Lazy<Arc<Mutex<WizardState>>> =
Lazy::new(|| Arc::new(Mutex::new(WizardState::default())));
static WIZARD_RESULT: Lazy<Arc<Mutex<Option<WizardParams>>>> =
Lazy::new(|| Arc::new(Mutex::new(None)));
#[derive(Debug, Clone)]
pub struct WizardParams {
@@ -151,8 +156,8 @@ pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
let popup = PopupFrame {
title: wizard_title(&snapshot),
border_color: THEME.colors.border_focused,
bg: Some(THEME.colors.popup_bg),
border_color: THEME.popup_new_instance.border_fg,
bg: Some(THEME.popup_new_instance.bg),
keybinds: Some(keybinds),
search_line,
content: Box::new(move |popup_area, buf| {
@@ -188,7 +193,9 @@ pub fn handle_key(key_event: &KeyEvent, profiles_state: &mut profiles::State) {
WizardStep::Name => handle_name_key(&mut state, key_event, profiles_state),
WizardStep::Version => handle_version_key(&mut state, key_event, profiles_state),
WizardStep::Loader => handle_loader_key(&mut state, key_event, profiles_state),
WizardStep::LoaderVersion => handle_loader_version_key(&mut state, key_event, profiles_state),
WizardStep::LoaderVersion => {
handle_loader_version_key(&mut state, key_event, profiles_state)
}
WizardStep::Confirm => handle_confirm_key(&mut state, key_event, profiles_state),
}
}
@@ -216,7 +223,9 @@ pub fn popup_rect(frame_area: Rect) -> Rect {
frame_area.centered(w, Constraint::Length(h))
}
WizardStep::Version | WizardStep::LoaderVersion => {
let h = (frame_area.height * 2 / 3).max(10).min(frame_area.height.saturating_sub(4));
let h = (frame_area.height * 2 / 3)
.max(10)
.min(frame_area.height.saturating_sub(4));
frame_area.centered(w, Constraint::Length(h))
}
WizardStep::Loader => {
@@ -455,40 +464,44 @@ fn wizard_title(_state: &WizardState) -> Line<'static> {
fn step_keybinds(state: &WizardState) -> ratatui::text::Line<'static> {
use super::keybind_line;
match state.step {
WizardStep::Name => keybind_line(&[("Enter", " continue")]),
WizardStep::Loader => keybind_line(&[("h", " back"), ("Enter", " select")]),
WizardStep::Version => keybind_line(&[("/", " search"), ("s", " snap"), ("h", " back"), ("Enter", " select")]),
WizardStep::Name => keybind_line(&[("Enter", " continue")]),
WizardStep::Loader => keybind_line(&[("h", " back"), ("Enter", " select")]),
WizardStep::Version => keybind_line(&[
("/", " search"),
("s", " snap"),
("h", " back"),
("Enter", " select"),
]),
WizardStep::LoaderVersion => keybind_line(&[("h", " back"), ("Enter", " select")]),
WizardStep::Confirm => keybind_line(&[("h", " back"), ("Enter", " create")]),
WizardStep::Confirm => keybind_line(&[("h", " back"), ("Enter", " create")]),
}
}
fn render_name_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
use ratatui::text::{Line, Span};
use ratatui::style::Modifier;
use ratatui::text::{Line, Span};
let value = state.name_state.value();
let line = if value.is_empty() {
Line::from(vec![
Span::styled(
"Instance name...",
Style::default()
.fg(THEME.colors.border_unfocused),
Style::default().fg(THEME.popup_new_instance.field_inactive_border_fg),
),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.popup_new_instance.border_fg)
.add_modifier(Modifier::SLOW_BLINK),
),
])
} else {
Line::from(vec![
Span::styled(value, Style::default().fg(THEME.colors.foreground)),
Span::styled(value, Style::default().fg(THEME.popup_new_instance.text_fg)),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.popup_new_instance.border_fg)
.add_modifier(Modifier::SLOW_BLINK),
),
])
@@ -501,13 +514,13 @@ fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
match &state.versions {
LoadState::Idle | LoadState::Loading => {
Paragraph::new("Loading versions...")
.style(Style::default().fg(THEME.colors.border_unfocused))
.style(Style::default().fg(THEME.popup_new_instance.field_inactive_border_fg))
.render(area, buf);
}
LoadState::Error(message) => {
Paragraph::new(message.as_str())
.wrap(Wrap { trim: true })
.style(Style::default().fg(THEME.colors.error))
.style(Style::default().fg(THEME.popup_new_instance.error_fg))
.render(area, buf);
}
LoadState::Loaded(_) => {
@@ -521,7 +534,7 @@ fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
};
ListItem::new(Line::from(Span::styled(
format!("{}{}", version.id, suffix),
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.popup_new_instance.text_fg),
)))
})
.collect();
@@ -529,7 +542,7 @@ fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
let list = List::new(items)
.highlight_style(
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.popup_new_instance.accent_fg)
.add_modifier(Modifier::BOLD),
)
.highlight_symbol("▶ ");
@@ -554,7 +567,7 @@ fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer
.map(|loader| {
ListItem::new(Line::from(Span::styled(
loader.to_string(),
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.popup_new_instance.text_fg),
)))
})
.collect();
@@ -562,7 +575,7 @@ fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer
let list = List::new(items)
.highlight_style(
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.popup_new_instance.accent_fg)
.add_modifier(Modifier::BOLD),
)
.highlight_symbol("▶ ");
@@ -571,14 +584,10 @@ fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer
StatefulWidget::render(list, area, buf, &mut list_state);
}
fn render_loader_version_step(
state: &WizardState,
area: Rect,
buf: &mut ratatui::buffer::Buffer,
) {
fn render_loader_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
if state.selected_loader() == ModLoader::Vanilla {
Paragraph::new("Vanilla has no loader version.")
.style(Style::default().fg(THEME.colors.border_unfocused))
.style(Style::default().fg(THEME.popup_new_instance.field_inactive_border_fg))
.render(area, buf);
return;
}
@@ -586,13 +595,13 @@ fn render_loader_version_step(
match &state.loader_versions {
LoadState::Idle | LoadState::Loading => {
Paragraph::new(format!("Loading {} versions...", state.selected_loader()))
.style(Style::default().fg(THEME.colors.border_unfocused))
.style(Style::default().fg(THEME.popup_new_instance.field_inactive_border_fg))
.render(area, buf);
}
LoadState::Error(message) => {
Paragraph::new(message.as_str())
.wrap(Wrap { trim: true })
.style(Style::default().fg(THEME.colors.error))
.style(Style::default().fg(THEME.popup_new_instance.error_fg))
.render(area, buf);
}
LoadState::Loaded(versions) => {
@@ -601,7 +610,7 @@ fn render_loader_version_step(
.map(|version| {
ListItem::new(Line::from(Span::styled(
version.clone(),
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.popup_new_instance.text_fg),
)))
})
.collect();
@@ -609,7 +618,7 @@ fn render_loader_version_step(
let list = List::new(items)
.highlight_style(
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.popup_new_instance.accent_fg)
.add_modifier(Modifier::BOLD),
)
.highlight_symbol("▶ ");
@@ -634,7 +643,7 @@ fn render_confirm_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
.unwrap_or_else(|| "<not selected>".to_string())
};
let label_style = Style::default().fg(THEME.colors.border_focused);
let label_style = Style::default().fg(THEME.popup_new_instance.border_fg);
Paragraph::new(vec![
Line::from(vec![
@@ -654,7 +663,7 @@ fn render_confirm_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
Span::raw(loader_version),
]),
])
.style(Style::default().fg(THEME.colors.foreground))
.style(Style::default().fg(THEME.popup_new_instance.text_fg))
.wrap(Wrap { trim: true })
.render(area, buf);
}
@@ -715,16 +724,14 @@ fn ensure_versions_loaded(state: &mut WizardState) {
tracing::error!("Wizard state lock poisoned: {}", e);
}
},
Err(e) => {
match versions_arc.lock() {
Ok(mut s) => {
s.versions = LoadState::Error(e.to_string());
}
Err(lock_error) => {
tracing::error!("Wizard state lock poisoned: {}", lock_error);
}
Err(e) => match versions_arc.lock() {
Ok(mut s) => {
s.versions = LoadState::Error(e.to_string());
}
}
Err(lock_error) => {
tracing::error!("Wizard state lock poisoned: {}", lock_error);
}
},
}
});
}
@@ -749,16 +756,14 @@ fn ensure_loader_versions_loaded(state: &mut WizardState, loader: ModLoader, gam
tracing::error!("Wizard state lock poisoned: {}", e);
}
},
Err(e) => {
match versions_arc.lock() {
Ok(mut s) => {
s.loader_versions = LoadState::Error(e.to_string());
}
Err(lock_error) => {
tracing::error!("Wizard state lock poisoned: {}", lock_error);
}
Err(e) => match versions_arc.lock() {
Ok(mut s) => {
s.loader_versions = LoadState::Error(e.to_string());
}
}
Err(lock_error) => {
tracing::error!("Wizard state lock poisoned: {}", lock_error);
}
},
}
});
}
+28 -26
View File
@@ -1,16 +1,17 @@
use crate::tui::theme::THEME;
use crossterm::event::KeyCode;
use ratatui::{
layout::Rect,
style::{Color, Modifier, Style},
style::{Modifier, Style},
text::{Line, Span, Text},
widgets::{Block, BorderType, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState},
widgets::{Block, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState},
Frame,
};
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 crate::tui::layout::FocusedArea;
use super::{search::SearchState, styled_title, WidgetKey};
@@ -34,13 +35,12 @@ fn format_last_played(last_played: Option<chrono::DateTime<chrono::Utc>>) -> Str
fn loader_color(loader: crate::instance::models::ModLoader) -> ratatui::style::Color {
use crate::instance::models::ModLoader;
use ratatui::style::Color;
match loader {
ModLoader::Vanilla => Color::Green,
ModLoader::Fabric => Color::Rgb(0x71, 0xa5, 0xde),
ModLoader::Forge => Color::Rgb(0xe0, 0x7b, 0x39),
ModLoader::NeoForge => Color::Rgb(0xe0, 0x54, 0x1b),
ModLoader::Quilt => Color::Rgb(0xa6, 0x5c, 0xcb),
ModLoader::Vanilla => THEME.profiles.loader_vanilla,
ModLoader::Fabric => THEME.profiles.loader_fabric,
ModLoader::Forge => THEME.profiles.loader_forge,
ModLoader::NeoForge => THEME.profiles.loader_neoforge,
ModLoader::Quilt => THEME.profiles.loader_quilt,
}
}
@@ -194,15 +194,15 @@ impl WidgetKey for State {
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut State) {
let color = if focused == FocusedArea::Profiles {
THEME.colors.border_focused
THEME.profiles.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.profiles.border_unfocused_fg
};
let mut block = Block::default()
.title(styled_title("Profiles", true))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(color));
if let Some(search_line) = state.search.title_line() {
@@ -224,25 +224,27 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
let instance = &state.instances[idx];
let stripe_bg = if context.index % 2 == 0 {
Color::Reset
THEME.general.bg
} else {
THEME.colors.row_alternate_bg
THEME.profiles.row_alt_bg
};
let (name_style, meta_style, bg) = if context.is_selected {
let mut style = Style::default().fg(THEME.profiles.selected_fg);
if THEME.profiles.selected_bold {
style = style.add_modifier(Modifier::BOLD);
}
(
Style::default()
.fg(THEME.colors.row_highlight)
.add_modifier(Modifier::BOLD),
Style::default().fg(THEME.colors.row_highlight),
THEME.colors.row_background,
style,
Style::default().fg(THEME.profiles.selected_fg),
THEME.profiles.selected_bg,
)
} else {
(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.profiles.border_focused_fg)
.add_modifier(Modifier::BOLD),
Style::default().fg(THEME.colors.border_unfocused),
Style::default().fg(THEME.profiles.border_unfocused_fg),
stripe_bg,
)
};
@@ -257,11 +259,11 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
let rename_val = state.renaming.as_deref().unwrap_or("");
Line::from(vec![
stripe.clone(),
Span::styled(rename_val, Style::default().fg(THEME.colors.foreground)),
Span::styled(rename_val, Style::default().fg(THEME.profiles.text_fg)),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.profiles.border_focused_fg)
.add_modifier(Modifier::SLOW_BLINK),
),
])
@@ -275,11 +277,11 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
let (meta_text, meta_text_style) = match get_run_state(&instance.name) {
Some(RunState::Authenticating) => (
"Authenticating".to_string(),
Style::default().fg(THEME.colors.success),
Style::default().fg(THEME.profiles.running_fg),
),
Some(RunState::Running) | Some(RunState::Starting) => (
"Playing".to_string(),
Style::default().fg(THEME.colors.success),
Style::default().fg(THEME.profiles.running_fg),
),
_ => (format_last_played(instance.last_played), meta_style),
};
@@ -300,7 +302,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.profiles.border_focused_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2551}")
+16 -20
View File
@@ -237,16 +237,12 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
}
true
}
KeyCode::Char('H') | KeyCode::Left
if key_event.modifiers.contains(KeyModifiers::SHIFT) =>
{
KeyCode::Char('H') | KeyCode::Left if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
state.selected = state.selected.saturating_sub(1);
state.ensure_visible();
true
}
KeyCode::Char('J') | KeyCode::Down
if key_event.modifiers.contains(KeyModifiers::SHIFT) =>
{
KeyCode::Char('J') | KeyCode::Down if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
let next = state.selected + cols;
if next < count {
state.selected = next;
@@ -254,9 +250,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
state.ensure_visible();
true
}
KeyCode::Char('K') | KeyCode::Up
if key_event.modifiers.contains(KeyModifiers::SHIFT) =>
{
KeyCode::Char('K') | KeyCode::Up if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
state.selected = state.selected.saturating_sub(cols);
state.ensure_visible();
true
@@ -280,7 +274,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
if state.loading {
frame.render_widget(
Paragraph::new("Loading screenshots...")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.screenshots.label_fg)),
area,
);
return;
@@ -288,7 +282,8 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
if state.entries.is_empty() {
frame.render_widget(
Paragraph::new("No screenshots.").style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new("No screenshots.")
.style(Style::default().fg(THEME.screenshots.label_fg)),
area,
);
return;
@@ -305,7 +300,10 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
.first()
.map(|e| (e.width, e.height))
.unwrap_or((1920, 1080));
let (fw, fh) = (state.font_size.0.max(1) as u32, state.font_size.1.max(1) as u32);
let (fw, fh) = (
state.font_size.0.max(1) as u32,
state.font_size.1.max(1) as u32,
);
let img_rows = (cell_width as u32 * fw * img_h / (fh * img_w)).max(2) as u16;
let cell_height = img_rows + NAME_ROW_HEIGHT + GAP;
let visible_rows = (area.height / cell_height).max(1) as usize;
@@ -339,11 +337,9 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
let is_selected = is_focused && idx == state.selected;
let [img_area, name_area] = Layout::vertical([
Constraint::Min(0),
Constraint::Length(NAME_ROW_HEIGHT),
])
.areas(cell);
let [img_area, name_area] =
Layout::vertical([Constraint::Min(0), Constraint::Length(NAME_ROW_HEIGHT)])
.areas(cell);
if let Some(proto) = state.protocols.get_mut(&idx) {
let widget: StatefulImage<StatefulProtocol> =
@@ -354,10 +350,10 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
let name = &state.entries[idx].name;
let name_style = if is_selected {
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.screenshots.selected_border_fg)
.add_modifier(Modifier::BOLD)
} else {
Style::default().fg(THEME.colors.text_idle)
Style::default().fg(THEME.screenshots.label_fg)
};
let truncated = if name.len() > cell_width as usize {
@@ -384,7 +380,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.screenshots.border_focused_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2551}")
+2 -2
View File
@@ -77,9 +77,9 @@ impl SearchState {
return None;
}
let dim = Style::default().fg(THEME.colors.border_unfocused);
let dim = Style::default().fg(THEME.search.border_unfocused_fg);
let accent = Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.search.border_focused_fg)
.add_modifier(Modifier::BOLD);
let mut spans = vec![
+13 -15
View File
@@ -2,7 +2,7 @@ use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Modifier, Style},
text::Span,
widgets::{Block, BorderType, Borders, Gauge, Paragraph},
widgets::{Block, Borders, Gauge, Paragraph},
Frame,
};
use throbber_widgets_tui::{Throbber, ThrobberState};
@@ -20,15 +20,15 @@ pub fn render(
throbber_state: &mut ThrobberState,
) {
let border_color = if focused == FocusedArea::Overview {
THEME.colors.border_focused
THEME.status.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.status.border_unfocused_fg
};
let block = Block::default()
.title(styled_title("Overview", true))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(border_color));
let state = match PROGRESS.lock() {
@@ -37,7 +37,7 @@ pub fn render(
frame.render_widget(
Paragraph::new(Span::styled(
"Ready",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.status.label_fg),
))
.block(block),
area,
@@ -50,7 +50,7 @@ pub fn render(
frame.render_widget(
Paragraph::new(Span::styled(
"Ready",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.status.label_fg),
))
.block(block),
area,
@@ -77,20 +77,19 @@ pub fn render(
let gauge = Gauge::default()
.gauge_style(
Style::default()
.fg(THEME.colors.progress_fill)
.bg(THEME.colors.progress_track)
.fg(THEME.status.progress_fill_fg)
.bg(THEME.status.progress_track_fg)
.add_modifier(Modifier::BOLD),
)
.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)),
Paragraph::new(action_text).style(Style::default().fg(THEME.status.text_fg)),
chunks[1],
);
if !sub_text.is_empty() {
frame.render_widget(
Paragraph::new(sub_text)
.style(Style::default().fg(THEME.colors.border_unfocused)),
Paragraph::new(sub_text).style(Style::default().fg(THEME.status.label_fg)),
chunks[2],
);
}
@@ -100,17 +99,16 @@ pub fn render(
Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).split(inner);
let throbber = Throbber::default()
.label(action_text)
.style(Style::default().fg(THEME.colors.foreground))
.style(Style::default().fg(THEME.status.text_fg))
.throbber_style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.status.border_focused_fg)
.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)
.style(Style::default().fg(THEME.colors.border_unfocused)),
Paragraph::new(sub_text).style(Style::default().fg(THEME.status.label_fg)),
chunks[1],
);
}