fix: suppress keybinds in input mode, fix profiles, add slide-in errors
This commit is contained in:
1 parent
59ad22e6e8
commit
dcd62f06d7
8 files changed
+301
-87
No files matched your search
Generated
+144
-4
@@ -58,6 +58,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anpa"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d032745fe46100dbcb28ee6e30f12c4b148786f8889e07cd0a3445eeb54970f"
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.18"
|
||||
@@ -224,6 +230,31 @@ dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bon"
|
||||
version = "3.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f47dbe92550676ee653353c310dfb9cf6ba17ee70396e1f7cf0a2020ad49b2fe"
|
||||
dependencies = [
|
||||
"bon-macros",
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bon-macros"
|
||||
version = "3.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "519bd3116aeeb42d5372c29d982d16d0170d3d4a5ed85fc7dd91642ffff3c67c"
|
||||
dependencies = [
|
||||
"darling 0.20.11",
|
||||
"ident_case",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.2"
|
||||
@@ -593,8 +624,18 @@ version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
"darling_core 0.20.11",
|
||||
"darling_macro 0.20.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0"
|
||||
dependencies = [
|
||||
"darling_core 0.21.3",
|
||||
"darling_macro 0.21.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -611,13 +652,38 @@ dependencies = [
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_core 0.20.11",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81"
|
||||
dependencies = [
|
||||
"darling_core 0.21.3",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
@@ -643,6 +709,17 @@ dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive-getters"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74ef43543e701c01ad77d3a5922755c6a1d71b22d942cb8042be4994b380caff"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_arbitrary"
|
||||
version = "1.4.2"
|
||||
@@ -676,6 +753,18 @@ dependencies = [
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_setters"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7e6f6fa1f03c14ae082120b84b3c7fbd7b8588d924cf2d7c3daf9afd49df8b9"
|
||||
dependencies = [
|
||||
"darling 0.21.3",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
@@ -1370,7 +1459,7 @@ version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bf9fed6d91cfb734e7476a06bde8300a1b94e217e1b523b6f0cd1a01998c71d"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"darling 0.20.11",
|
||||
"indoc",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -1643,6 +1732,7 @@ dependencies = [
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tachyonfx",
|
||||
"thiserror 2.0.12",
|
||||
"throbber-widgets-tui",
|
||||
"tokio",
|
||||
@@ -1650,6 +1740,8 @@ dependencies = [
|
||||
"tracing-appender",
|
||||
"tracing-subscriber",
|
||||
"tui-logger",
|
||||
"tui-popup",
|
||||
"tui-prompts",
|
||||
"tui-scrollview",
|
||||
"tui-widget-list",
|
||||
"zip",
|
||||
@@ -1676,6 +1768,12 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "micromath"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3c8dda44ff03a2f238717214da50f65d5a53b45cd213a7370424ffdb6fae815"
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.17"
|
||||
@@ -2752,6 +2850,21 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tachyonfx"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c144c687e9f3628c06add1b6db585a68d3cd285a9d7213b9bca836771e337592"
|
||||
dependencies = [
|
||||
"anpa",
|
||||
"bon",
|
||||
"compact_str",
|
||||
"micromath",
|
||||
"ratatui-core",
|
||||
"thiserror 2.0.12",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.23.0"
|
||||
@@ -3191,6 +3304,33 @@ dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tui-popup"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "440ccb456a6e4c6141e985c37b9b93378c0f108303c0448f64dfc7959ed7fa3a"
|
||||
dependencies = [
|
||||
"derive-getters",
|
||||
"derive_setters",
|
||||
"document-features",
|
||||
"ratatui-core",
|
||||
"ratatui-widgets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tui-prompts"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2237609b6d31db3635072e3c2a0a501ab546ce4bbdc96cf1a62c2e7ce0ac7e0f"
|
||||
dependencies = [
|
||||
"crossterm",
|
||||
"itertools",
|
||||
"ratatui-core",
|
||||
"ratatui-macros",
|
||||
"ratatui-widgets",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tui-scrollview"
|
||||
version = "0.6.4"
|
||||
|
||||
+11
-1
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "mcl"
|
||||
version = "0.1.0"
|
||||
authors = ["72-S"]
|
||||
authors = ["objz"]
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -19,13 +19,23 @@ 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"
|
||||
tachyonfx = "0.25"
|
||||
throbber-widgets-tui = "0.11"
|
||||
thiserror = "2"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tracing = "0.1"
|
||||
tracing-appender = "0.2"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
tui-popup = "0.7"
|
||||
tui-prompts = "0.6"
|
||||
tui-logger = { version = "0.18", features = ["tracing-support"] }
|
||||
tui-scrollview = "0.6"
|
||||
tui-widget-list = "0.15"
|
||||
zip = "2"
|
||||
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
opt-level = "s"
|
||||
strip = true
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
|
||||
@@ -9,9 +10,11 @@ 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);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ErrorEvent {
|
||||
pub id: u64,
|
||||
pub level: Level,
|
||||
pub message: String,
|
||||
pub pushed_at: Instant,
|
||||
@@ -23,6 +26,8 @@ pub static ERROR_EVENTS: Lazy<Arc<Mutex<VecDeque<ErrorEvent>>>> =
|
||||
pub fn push_error(event: ErrorEvent) {
|
||||
match ERROR_EVENTS.lock() {
|
||||
Ok(mut events) => {
|
||||
let mut event = event;
|
||||
event.id = NEXT_ERROR_ID.fetch_add(1, Ordering::Relaxed);
|
||||
events.push_back(event);
|
||||
while events.len() > MAX_ERROR_EVENTS {
|
||||
events.pop_front();
|
||||
|
||||
+74
-1
@@ -17,8 +17,10 @@ use ratatui::{
|
||||
layout::{Constraint, Direction, Layout},
|
||||
Frame,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
use tachyonfx::{fx, Effect, EffectRenderer, Interpolation, Motion};
|
||||
|
||||
static PENDING_INSTANCES: Lazy<Arc<Mutex<Vec<InstanceConfig>>>> =
|
||||
Lazy::new(|| Arc::new(Mutex::new(Vec::new())));
|
||||
@@ -31,6 +33,13 @@ pub struct App {
|
||||
instance_manager: InstanceManager,
|
||||
log_list_state: tui_logger::TuiWidgetState,
|
||||
throbber_state: throbber_widgets_tui::ThrobberState,
|
||||
error_effects: HashMap<u64, ErrorEffectState>,
|
||||
}
|
||||
|
||||
enum ErrorEffectState {
|
||||
SlidingIn(Effect),
|
||||
Idle,
|
||||
FadingOut(Effect),
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Copy, PartialEq)]
|
||||
@@ -79,6 +88,7 @@ impl Default for App {
|
||||
log_list_state: tui_logger::TuiWidgetState::new()
|
||||
.set_default_display_level(log::LevelFilter::Debug),
|
||||
throbber_state: throbber_widgets_tui::ThrobberState::default(),
|
||||
error_effects: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,13 +152,15 @@ impl App {
|
||||
}
|
||||
|
||||
let all_errors = error_buffer::peek_all_errors();
|
||||
self.sync_error_effects(&all_errors);
|
||||
let mut next_y: u16 = 1;
|
||||
for event in all_errors {
|
||||
let elapsed_ms = event.pushed_at.elapsed().as_millis();
|
||||
match popup_area(frame.area(), &event.message, next_y, elapsed_ms) {
|
||||
Some(area) => {
|
||||
next_y = next_y.saturating_add(area.height + 1);
|
||||
frame.render_widget(ErrorPopup::new(event), area);
|
||||
frame.render_widget(ErrorPopup::new(event.clone()), area);
|
||||
self.render_error_effect(frame, area, &event, elapsed_ms);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
@@ -243,6 +255,11 @@ impl App {
|
||||
new_instance::handle_key(&key_event, &mut self.profiles_state);
|
||||
}
|
||||
_ => {
|
||||
if self.focused == FocusedArea::Profiles && self.profiles_state.search.active {
|
||||
self.profiles_state.handle_key(&key_event);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
match key_event.code {
|
||||
KeyCode::Char('q') => self.exit = true,
|
||||
KeyCode::Char('P') => self.focused = FocusedArea::Profiles,
|
||||
@@ -379,4 +396,60 @@ impl App {
|
||||
|
||||
frame.render_widget(widget, overlay);
|
||||
}
|
||||
|
||||
fn sync_error_effects(&mut self, events: &[error_buffer::ErrorEvent]) {
|
||||
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 {
|
||||
self.error_effects.entry(event.id).or_insert_with(|| {
|
||||
ErrorEffectState::SlidingIn(fx::slide_in(
|
||||
Motion::RightToLeft,
|
||||
8,
|
||||
0,
|
||||
ratatui::style::Color::Reset,
|
||||
(300, Interpolation::SineOut),
|
||||
))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn render_error_effect(
|
||||
&mut self,
|
||||
frame: &mut Frame,
|
||||
area: ratatui::layout::Rect,
|
||||
event: &error_buffer::ErrorEvent,
|
||||
elapsed_ms: u128,
|
||||
) {
|
||||
const FADE_OUT_MS: u128 = 500;
|
||||
let fade_start_ms = error_buffer::AUTO_DISMISS_MS.saturating_sub(FADE_OUT_MS);
|
||||
|
||||
if elapsed_ms >= fade_start_ms {
|
||||
let entry = self.error_effects.entry(event.id).or_insert(ErrorEffectState::Idle);
|
||||
if !matches!(entry, ErrorEffectState::FadingOut(_)) {
|
||||
*entry = ErrorEffectState::FadingOut(tachyonfx::fx::fade_to_fg(
|
||||
ratatui::style::Color::DarkGray,
|
||||
(FADE_OUT_MS as u32, Interpolation::SineIn),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(effect_state) = self.error_effects.get_mut(&event.id) {
|
||||
match effect_state {
|
||||
ErrorEffectState::SlidingIn(effect) => {
|
||||
if effect.running() {
|
||||
frame.render_effect(effect, area, tachyonfx::Duration::from_millis(16));
|
||||
} else {
|
||||
*effect_state = ErrorEffectState::Idle;
|
||||
}
|
||||
}
|
||||
ErrorEffectState::Idle => {}
|
||||
ErrorEffectState::FadingOut(effect) => {
|
||||
if effect.running() {
|
||||
frame.render_effect(effect, area, tachyonfx::Duration::from_millis(16));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,7 @@ impl<S: Subscriber> Layer<S> for StatusLayer {
|
||||
|
||||
if level <= Level::WARN {
|
||||
error_buffer::push_error(ErrorEvent {
|
||||
id: 0,
|
||||
level,
|
||||
message: visitor.message,
|
||||
pushed_at: std::time::Instant::now(),
|
||||
|
||||
@@ -8,7 +8,7 @@ use ratatui::{
|
||||
use tracing::Level;
|
||||
|
||||
use super::base::PopupFrame;
|
||||
use crate::tui::error_buffer::{ErrorEvent, AUTO_DISMISS_MS, SLIDE_START_MS};
|
||||
use crate::tui::error_buffer::{ErrorEvent, AUTO_DISMISS_MS};
|
||||
use crate::tui::theme::THEME;
|
||||
|
||||
pub struct ErrorPopup {
|
||||
@@ -74,29 +74,10 @@ pub fn popup_area(frame_area: Rect, message: &str, base_y: u16, elapsed_ms: u128
|
||||
let popup_w = popup_w.min(frame_area.width.saturating_sub(4));
|
||||
let popup_h = popup_h.min(frame_area.height.saturating_sub(2));
|
||||
let base_x = frame_area.width.saturating_sub(popup_w + 2);
|
||||
|
||||
if elapsed_ms < SLIDE_START_MS {
|
||||
return Some(Rect {
|
||||
x: base_x,
|
||||
y: base_y,
|
||||
width: popup_w,
|
||||
height: popup_h,
|
||||
});
|
||||
}
|
||||
|
||||
let progress = (elapsed_ms - SLIDE_START_MS) as f32 / (AUTO_DISMISS_MS - SLIDE_START_MS) as f32;
|
||||
let slide = (progress * popup_w as f32) as u16;
|
||||
let new_x = base_x.saturating_add(slide);
|
||||
|
||||
if new_x >= frame_area.width {
|
||||
return None;
|
||||
}
|
||||
|
||||
let visible_w = frame_area.width.saturating_sub(new_x);
|
||||
Some(Rect {
|
||||
x: new_x,
|
||||
x: base_x,
|
||||
y: base_y,
|
||||
width: visible_w.min(popup_w),
|
||||
width: popup_w,
|
||||
height: popup_h,
|
||||
})
|
||||
}
|
||||
@@ -5,7 +5,6 @@ use crate::tui::theme::THEME;
|
||||
use crate::tui::widgets::profiles;
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use once_cell::sync::Lazy;
|
||||
use ratatui_textarea::{Input, TextArea};
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
@@ -14,6 +13,7 @@ use ratatui::{
|
||||
Frame,
|
||||
};
|
||||
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)));
|
||||
@@ -53,7 +53,7 @@ impl<T> Default for LoadState<T> {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WizardState {
|
||||
pub step: WizardStep,
|
||||
pub name_textarea: TextArea<'static>,
|
||||
pub name_state: TextState<'static>,
|
||||
pub versions: LoadState<Vec<GameVersion>>,
|
||||
pub version_idx: usize,
|
||||
pub show_snapshots: bool,
|
||||
@@ -65,13 +65,9 @@ pub struct WizardState {
|
||||
|
||||
impl Default for WizardState {
|
||||
fn default() -> Self {
|
||||
let mut textarea = TextArea::default();
|
||||
textarea.set_cursor_line_style(Style::default());
|
||||
textarea.set_placeholder_text("Instance name...");
|
||||
|
||||
Self {
|
||||
step: WizardStep::Name,
|
||||
name_textarea: textarea,
|
||||
name_state: TextState::new().with_focus(FocusState::Focused),
|
||||
versions: LoadState::Idle,
|
||||
version_idx: 0,
|
||||
show_snapshots: false,
|
||||
@@ -240,23 +236,17 @@ fn handle_name_key(
|
||||
profiles_state: &mut profiles::State,
|
||||
) {
|
||||
match key_event.code {
|
||||
KeyCode::Esc | KeyCode::Left | KeyCode::Char('h') => {
|
||||
KeyCode::Esc => {
|
||||
close_popup(state, profiles_state);
|
||||
}
|
||||
KeyCode::Enter | KeyCode::Right | KeyCode::Char('l') => {
|
||||
if state
|
||||
.name_textarea
|
||||
.lines()
|
||||
.first()
|
||||
.map(|line| line.trim().is_empty())
|
||||
.unwrap_or(true)
|
||||
{
|
||||
KeyCode::Enter => {
|
||||
if state.name_state.value().trim().is_empty() {
|
||||
return;
|
||||
}
|
||||
state.step = WizardStep::Loader;
|
||||
}
|
||||
_ => {
|
||||
state.name_textarea.input(Input::from(key_event.clone()));
|
||||
state.name_state.handle_key_event(key_event.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -427,12 +417,7 @@ fn handle_confirm_key(
|
||||
};
|
||||
|
||||
let params = WizardParams {
|
||||
name: state
|
||||
.name_textarea
|
||||
.lines()
|
||||
.first()
|
||||
.map(|line| line.trim().to_string())
|
||||
.unwrap_or_default(),
|
||||
name: state.name_state.value().trim().to_string(),
|
||||
game_version: selected_version,
|
||||
loader: state.selected_loader(),
|
||||
loader_version: if state.selected_loader() == ModLoader::Vanilla {
|
||||
@@ -483,9 +468,16 @@ fn step_keybinds(state: &WizardState) -> ratatui::text::Line<'static> {
|
||||
}
|
||||
|
||||
fn render_name_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let mut textarea = state.name_textarea.clone();
|
||||
textarea.set_style(Style::default().fg(THEME.colors.foreground));
|
||||
textarea.render(area, buf);
|
||||
let value = state.name_state.value();
|
||||
let display = if value.is_empty() {
|
||||
"█".to_string()
|
||||
} else {
|
||||
format!("{}█", value)
|
||||
};
|
||||
|
||||
Paragraph::new(display)
|
||||
.style(Style::default().fg(THEME.colors.foreground))
|
||||
.render(area, buf);
|
||||
}
|
||||
|
||||
fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
@@ -617,13 +609,7 @@ fn render_confirm_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
|
||||
Paragraph::new(vec![
|
||||
Line::from(vec![
|
||||
Span::styled("Name: ", label_style),
|
||||
Span::raw(
|
||||
state.name_textarea
|
||||
.lines()
|
||||
.first()
|
||||
.cloned()
|
||||
.unwrap_or_default(),
|
||||
),
|
||||
Span::raw(state.name_state.value()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("MC: ", label_style),
|
||||
|
||||
+44
-26
@@ -119,27 +119,34 @@ impl State {
|
||||
|
||||
impl WidgetKey for State {
|
||||
fn handle_key(&mut self, key_event: &crossterm::event::KeyEvent) {
|
||||
if self.search.active {
|
||||
match key_event.code {
|
||||
KeyCode::Esc => {
|
||||
self.search.deactivate();
|
||||
self.list_state.selected = Some(0);
|
||||
self.update_scrollbar();
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
self.search.pop();
|
||||
self.list_state.selected = Some(0);
|
||||
self.update_scrollbar();
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
self.search.push(c);
|
||||
self.list_state.selected = Some(0);
|
||||
self.update_scrollbar();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
match key_event.code {
|
||||
KeyCode::Char('/') if !self.search.active => {
|
||||
KeyCode::Char('/') => {
|
||||
self.search.activate();
|
||||
self.list_state.selected = Some(0);
|
||||
self.update_scrollbar();
|
||||
}
|
||||
KeyCode::Esc if self.search.active => {
|
||||
self.search.deactivate();
|
||||
self.list_state.selected = Some(0);
|
||||
self.update_scrollbar();
|
||||
}
|
||||
KeyCode::Backspace if self.search.active => {
|
||||
self.search.pop();
|
||||
self.list_state.selected = Some(0);
|
||||
self.update_scrollbar();
|
||||
}
|
||||
KeyCode::Char(c) if self.search.active && c != 'j' && c != 'k' => {
|
||||
self.search.push(c);
|
||||
self.list_state.selected = Some(0);
|
||||
self.update_scrollbar();
|
||||
}
|
||||
KeyCode::Char('a') => {
|
||||
self.show_popup = true;
|
||||
self.update_scrollbar();
|
||||
@@ -183,31 +190,42 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
let idx = filtered[context.index];
|
||||
let instance = &state.instances[idx];
|
||||
|
||||
let name_line = Line::from(vec![
|
||||
Span::raw(" "),
|
||||
Span::styled(
|
||||
instance.name.as_str(),
|
||||
let (name_style, info_style, bg) = if context.is_selected {
|
||||
(
|
||||
Style::default()
|
||||
.fg(THEME.colors.row_highlight)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(THEME.colors.foreground),
|
||||
THEME.colors.row_alternate_bg,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
Style::default()
|
||||
.fg(THEME.colors.border_focused)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
Style::default().fg(THEME.colors.border_unfocused),
|
||||
THEME.colors.row_background,
|
||||
)
|
||||
};
|
||||
|
||||
let name_line = Line::from(vec![
|
||||
Span::raw(" "),
|
||||
Span::styled(instance.name.as_str(), name_style),
|
||||
]);
|
||||
let info_line = Line::from(vec![
|
||||
Span::raw(" "),
|
||||
Span::styled(
|
||||
format!("{} \u{00b7} {}", instance.game_version, instance.loader),
|
||||
Style::default().fg(THEME.colors.border_unfocused),
|
||||
info_style,
|
||||
),
|
||||
]);
|
||||
let spacer = Line::from("");
|
||||
|
||||
let item = Text::from(vec![name_line, info_line, spacer]);
|
||||
let item = Text::from(vec![name_line, info_line, spacer]).style(Style::default().bg(bg));
|
||||
(item, 3)
|
||||
});
|
||||
|
||||
let list = ListView::new(builder, count)
|
||||
.block(block)
|
||||
.style(Style::default().bg(THEME.colors.row_alternate_bg));
|
||||
let list = ListView::new(builder, count).block(block);
|
||||
|
||||
frame.render_stateful_widget(list, area, &mut state.list_state);
|
||||
|
||||
|
||||
Reference in new issue
Block a user