refactor: reorganize source and tests
This commit is contained in:
1 parent
15d76c18a0
commit
c6205a337c
139 files changed
+5532
-5548
No files matched your search
@@ -1,90 +0,0 @@
|
||||
// thread-safe FIFO queue for error/warning toasts displayed in the UI.
|
||||
// also (ab)used for INFO toasts like "desktop shortcut created" because
|
||||
// why build a separate notification system when this one works fine.
|
||||
//
|
||||
// callers pass id: 0 and push_error assigns a real unique id. the id is
|
||||
// used by the render layer to track per-toast animation state.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
use tracing::Level;
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
pub static ERROR_EVENTS: LazyLock<Arc<Mutex<VecDeque<ErrorEvent>>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(VecDeque::new())));
|
||||
|
||||
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();
|
||||
}
|
||||
crate::tui::request_redraw();
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Error buffer lock poisoned: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn has_errors() -> bool {
|
||||
match ERROR_EVENTS.lock() {
|
||||
Ok(events) => !events.is_empty(),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn pop_error() -> Option<ErrorEvent> {
|
||||
match ERROR_EVENTS.lock() {
|
||||
Ok(mut events) => {
|
||||
let event = events.pop_front();
|
||||
if event.is_some() {
|
||||
crate::tui::request_redraw();
|
||||
}
|
||||
event
|
||||
}
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn peek_error() -> Option<ErrorEvent> {
|
||||
match ERROR_EVENTS.lock() {
|
||||
Ok(events) => events.front().cloned(),
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
// returned in reverse order (newest first) so they stack top-down in the UI
|
||||
pub fn peek_all_errors() -> Vec<ErrorEvent> {
|
||||
match ERROR_EVENTS.lock() {
|
||||
Ok(events) => events.iter().rev().cloned().collect(),
|
||||
Err(_) => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/error_buffer.rs"]
|
||||
mod tests;
|
||||
+11
-11
@@ -6,9 +6,9 @@ use std::time::Duration;
|
||||
use super::Tui;
|
||||
use super::app::{App, PENDING_INSTANCES};
|
||||
use super::widgets::{self, popups::import_modpack, popups::new_instance};
|
||||
use crate::feedback::errors as error_buffer;
|
||||
use crate::feedback::progress;
|
||||
use crate::instance::InstanceManager;
|
||||
use crate::tui::error_buffer;
|
||||
use crate::tui::progress;
|
||||
|
||||
impl App {
|
||||
/// main loop: poll async results and input at ~60Hz, drawing only when state changes
|
||||
@@ -17,7 +17,7 @@ impl App {
|
||||
.checked_sub(Duration::from_secs(1))
|
||||
.unwrap_or_else(std::time::Instant::now);
|
||||
while !self.exit {
|
||||
let redraw_requested = super::take_redraw_request();
|
||||
let redraw_requested = crate::feedback::take_redraw_request();
|
||||
// check if any popup wizard finished and wants to create/import
|
||||
if let Some(params) = new_instance::take_result() {
|
||||
self.spawn_create(params);
|
||||
@@ -86,7 +86,7 @@ impl App {
|
||||
self.ensure_provider_conflict_popup();
|
||||
self.ensure_active_discovery_loaded();
|
||||
let progress_active = progress::is_active();
|
||||
let spinner_active = progress_active || crate::running::has_active();
|
||||
let spinner_active = progress_active || crate::instance::runtime::has_active();
|
||||
if spinner_active {
|
||||
// only advance the spinner every 8 ticks to keep it readable
|
||||
self.throbber_tick = self.throbber_tick.wrapping_add(1);
|
||||
@@ -366,7 +366,7 @@ impl App {
|
||||
Ok(config) => {
|
||||
if let Ok(mut pending) = pending_instances.lock() {
|
||||
pending.push(config);
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -393,11 +393,11 @@ impl App {
|
||||
Ok(config) => {
|
||||
if let Ok(mut pending) = pending_instances.lock() {
|
||||
pending.push(config);
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
crate::tui::progress::clear();
|
||||
crate::feedback::progress::clear();
|
||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||
id: 0,
|
||||
level: tracing::Level::ERROR,
|
||||
@@ -496,7 +496,7 @@ impl App {
|
||||
|
||||
pub(super) fn spawn_launch(&self, instance: crate::instance::InstanceConfig) {
|
||||
use crate::instance::launch;
|
||||
use crate::running;
|
||||
use crate::instance::runtime;
|
||||
|
||||
let instance = match self.instance_manager.load_one(&instance.name) {
|
||||
Ok(config) => config,
|
||||
@@ -511,7 +511,7 @@ impl App {
|
||||
}
|
||||
};
|
||||
|
||||
running::set_state(&instance.name, running::RunState::Authenticating);
|
||||
runtime::set_state(&instance.name, runtime::RunState::Authenticating);
|
||||
|
||||
let instances_dir = self.instance_manager.instances_dir.clone();
|
||||
let meta_dir = self.instance_manager.meta_dir.clone();
|
||||
@@ -519,7 +519,7 @@ impl App {
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = launch::launch(&instance, &instances_dir, &meta_dir).await {
|
||||
tracing::error!("Failed to launch '{}': {}", instance.name, e);
|
||||
running::remove(&instance.name);
|
||||
runtime::remove(&instance.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -550,7 +550,7 @@ impl App {
|
||||
}
|
||||
|
||||
fn drain_pending_last_played(&mut self) {
|
||||
for (name, time) in crate::running::drain_last_played() {
|
||||
for (name, time) in crate::instance::runtime::drain_last_played() {
|
||||
for inst in &mut self.instances_state.instances {
|
||||
if inst.name == name {
|
||||
inst.last_played = Some(time);
|
||||
|
||||
+19
-16
@@ -11,7 +11,7 @@ use super::app::{App, FocusedArea};
|
||||
use super::widgets::{
|
||||
self, WidgetKey, popups::confirm as confirm_popup, popups::import_modpack, popups::new_instance,
|
||||
};
|
||||
use crate::tui::error_buffer;
|
||||
use crate::feedback::errors as error_buffer;
|
||||
|
||||
impl App {
|
||||
pub(super) fn handle_mouse_event(&mut self, event: MouseEvent) {
|
||||
@@ -582,12 +582,12 @@ impl App {
|
||||
{
|
||||
if let Some(instance) = self.instances_state.selected_instance().cloned() {
|
||||
let can_launch = matches!(
|
||||
crate::running::get(&instance.name),
|
||||
None | Some(crate::running::RunState::Crashed(_))
|
||||
crate::instance::runtime::get(&instance.name),
|
||||
None | Some(crate::instance::runtime::RunState::Crashed(_))
|
||||
);
|
||||
if can_launch {
|
||||
crate::running::remove(&instance.name);
|
||||
crate::instance_logs::clear(&instance.name);
|
||||
crate::instance::runtime::remove(&instance.name);
|
||||
crate::instance::logs::live::clear(&instance.name);
|
||||
self.spawn_launch(instance);
|
||||
}
|
||||
}
|
||||
@@ -606,7 +606,7 @@ impl App {
|
||||
&& !self.instances_state.search.active =>
|
||||
{
|
||||
if let Some(instance) = self.instances_state.selected_instance() {
|
||||
crate::running::send_kill(&instance.name);
|
||||
crate::instance::runtime::send_kill(&instance.name);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@@ -689,8 +689,9 @@ impl App {
|
||||
instance.loader.to_string().to_lowercase()
|
||||
));
|
||||
tokio::spawn(async move {
|
||||
let registry =
|
||||
crate::content_provider::ProviderRegistry::modrinth(crate::net::HttpClient::new());
|
||||
let registry = crate::instance::content::provider::ProviderRegistry::modrinth(
|
||||
crate::net::HttpClient::new(),
|
||||
);
|
||||
let result = match registry.preferred("modrinth") {
|
||||
Some(provider) => match provider
|
||||
.compatible_versions(
|
||||
@@ -741,7 +742,7 @@ impl App {
|
||||
let project = match request.cached_project {
|
||||
Some(project) => project,
|
||||
None => {
|
||||
let progress = crate::tui::progress::ProgressTask::start(format!(
|
||||
let progress = crate::feedback::progress::ProgressTask::start(format!(
|
||||
"Loading {} from Modrinth",
|
||||
request.project_title
|
||||
));
|
||||
@@ -783,7 +784,7 @@ impl App {
|
||||
}
|
||||
image_urls.sort();
|
||||
image_urls.dedup();
|
||||
let progress = crate::tui::progress::ProgressTask::start(format!(
|
||||
let progress = crate::feedback::progress::ProgressTask::start(format!(
|
||||
"Loading images for {}",
|
||||
project.title
|
||||
));
|
||||
@@ -868,14 +869,15 @@ impl App {
|
||||
} else {
|
||||
format!("Installing {}", request.project_title)
|
||||
};
|
||||
let progress = crate::tui::progress::ProgressTask::start(action);
|
||||
let progress = crate::feedback::progress::ProgressTask::start(action);
|
||||
progress.set_sub_action(&request.version.version_number);
|
||||
let client = crate::net::HttpClient::new();
|
||||
let result = async {
|
||||
tokio::fs::create_dir_all(&destination)
|
||||
.await
|
||||
.map_err(crate::net::NetError::from)?;
|
||||
let registry = crate::content_provider::ProviderRegistry::modrinth(client);
|
||||
let registry =
|
||||
crate::instance::content::provider::ProviderRegistry::modrinth(client);
|
||||
let provider = registry.preferred("modrinth").ok_or_else(|| {
|
||||
crate::net::NetError::Parse(
|
||||
"Modrinth content provider is unavailable".to_owned(),
|
||||
@@ -1053,7 +1055,8 @@ impl App {
|
||||
|
||||
tokio::spawn(async move {
|
||||
let client = crate::net::HttpClient::new();
|
||||
let registry = crate::content_provider::ProviderRegistry::modrinth(client.clone());
|
||||
let registry =
|
||||
crate::instance::content::provider::ProviderRegistry::modrinth(client.clone());
|
||||
let result = match registry.preferred("modrinth") {
|
||||
Some(provider) => {
|
||||
provider
|
||||
@@ -1109,9 +1112,9 @@ impl App {
|
||||
let Ok(_permit) = icon_slots.acquire_owned().await else {
|
||||
return;
|
||||
};
|
||||
let progress = crate::tui::progress::ProgressTask::start(format!(
|
||||
"Downloading icon for {file_stem}"
|
||||
));
|
||||
let progress = crate::feedback::progress::ProgressTask::start(
|
||||
format!("Downloading icon for {file_stem}"),
|
||||
);
|
||||
match client.get_bytes(&url).await {
|
||||
Ok(bytes) if !bytes.is_empty() => {
|
||||
if let Some(parent) = cached_icon.parent() {
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ use tracing_subscriber::{EnvFilter, Layer};
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use crate::tui::error_buffer::{self, ErrorEvent};
|
||||
use crate::feedback::errors::{self as error_buffer, ErrorEvent};
|
||||
|
||||
const MINECRAFT_LOG_TARGET: &str = "mc_instance";
|
||||
const DEFAULT_FILE_FILTER: &str = "warn,rmcl=trace";
|
||||
|
||||
+5
-15
@@ -1,29 +1,19 @@
|
||||
// tui entrypoint: sets up the terminal, runs the app, cleans up on exit.
|
||||
|
||||
pub mod app;
|
||||
pub mod error_buffer;
|
||||
mod event;
|
||||
mod input;
|
||||
pub mod logging;
|
||||
pub mod progress;
|
||||
mod render;
|
||||
pub mod widgets;
|
||||
|
||||
pub use crate::feedback::errors as error_buffer;
|
||||
pub use crate::feedback::progress;
|
||||
pub use crate::feedback::request_redraw;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests;
|
||||
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
static REDRAW_REQUESTED: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
pub fn request_redraw() {
|
||||
REDRAW_REQUESTED.store(true, Ordering::Release);
|
||||
}
|
||||
|
||||
pub(super) fn take_redraw_request() -> bool {
|
||||
REDRAW_REQUESTED.swap(false, Ordering::AcqRel)
|
||||
}
|
||||
|
||||
pub type Tui = ratatui::DefaultTerminal;
|
||||
|
||||
pub async fn show() -> color_eyre::Result<()> {
|
||||
@@ -234,7 +224,7 @@ async fn rebuild_runtime_cache_screen(
|
||||
});
|
||||
|
||||
while !task.is_finished() {
|
||||
let progress = crate::tui::progress::PROGRESS
|
||||
let progress = crate::feedback::progress::PROGRESS
|
||||
.lock()
|
||||
.ok()
|
||||
.map(|progress| progress.clone())
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
// global progress state shared between background tasks and the status bar widget.
|
||||
// background tasks set the action/progress, the render loop reads it every frame.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct ProgressState {
|
||||
pub current_action: Option<String>,
|
||||
pub progress: Option<(u64, u64)>,
|
||||
pub sub_action: Option<String>,
|
||||
tasks: BTreeMap<u64, TaskState>,
|
||||
legacy_active: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct TaskState {
|
||||
action: String,
|
||||
sub_action: Option<String>,
|
||||
progress: Option<(u64, u64)>,
|
||||
}
|
||||
|
||||
pub static PROGRESS: LazyLock<Arc<Mutex<ProgressState>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(ProgressState::default())));
|
||||
static NEXT_TASK_ID: AtomicU64 = AtomicU64::new(1);
|
||||
|
||||
pub struct ProgressTask {
|
||||
id: u64,
|
||||
finished: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ProgressTaskHandle {
|
||||
id: u64,
|
||||
}
|
||||
|
||||
impl ProgressTask {
|
||||
pub fn start(action: impl Into<String>) -> Self {
|
||||
let id = NEXT_TASK_ID.fetch_add(1, Ordering::Relaxed);
|
||||
let action = action.into();
|
||||
if let Ok(mut state) = PROGRESS.lock() {
|
||||
state.tasks.insert(
|
||||
id,
|
||||
TaskState {
|
||||
action: action.clone(),
|
||||
sub_action: None,
|
||||
progress: None,
|
||||
},
|
||||
);
|
||||
refresh_visible(&mut state);
|
||||
}
|
||||
tracing::info!("{}", action);
|
||||
crate::tui::request_redraw();
|
||||
Self {
|
||||
id,
|
||||
finished: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle(&self) -> ProgressTaskHandle {
|
||||
ProgressTaskHandle { id: self.id }
|
||||
}
|
||||
|
||||
pub fn set_action(&self, text: impl Into<String>) {
|
||||
update_task_action(self.id, text.into());
|
||||
}
|
||||
|
||||
pub fn set_sub_action(&self, text: impl Into<String>) {
|
||||
update_task_sub_action(self.id, text.into());
|
||||
}
|
||||
|
||||
pub fn set_progress(&self, current: u64, total: u64) {
|
||||
update_task_progress(self.id, current, total);
|
||||
}
|
||||
|
||||
pub fn finish(mut self) {
|
||||
self.remove();
|
||||
self.finished = true;
|
||||
}
|
||||
|
||||
pub fn fail(mut self, error: impl std::fmt::Display) {
|
||||
tracing::warn!("Progress task failed: {error}");
|
||||
self.remove();
|
||||
self.finished = true;
|
||||
}
|
||||
|
||||
fn remove(&self) {
|
||||
if let Ok(mut state) = PROGRESS.lock() {
|
||||
state.tasks.remove(&self.id);
|
||||
refresh_visible(&mut state);
|
||||
}
|
||||
crate::tui::request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
impl ProgressTaskHandle {
|
||||
pub fn set_sub_action(&self, text: impl Into<String>) {
|
||||
update_task_sub_action(self.id, text.into());
|
||||
}
|
||||
|
||||
pub fn set_progress(&self, current: u64, total: u64) {
|
||||
update_task_progress(self.id, current, total);
|
||||
}
|
||||
}
|
||||
|
||||
fn update_task_action(id: u64, text: String) {
|
||||
if let Ok(mut state) = PROGRESS.lock() {
|
||||
if let Some(task) = state.tasks.get_mut(&id) {
|
||||
task.action = text;
|
||||
}
|
||||
refresh_visible(&mut state);
|
||||
}
|
||||
crate::tui::request_redraw();
|
||||
}
|
||||
|
||||
fn update_task_sub_action(id: u64, text: String) {
|
||||
if let Ok(mut state) = PROGRESS.lock() {
|
||||
if let Some(task) = state.tasks.get_mut(&id) {
|
||||
task.sub_action = Some(text);
|
||||
}
|
||||
refresh_visible(&mut state);
|
||||
}
|
||||
crate::tui::request_redraw();
|
||||
}
|
||||
|
||||
fn update_task_progress(id: u64, current: u64, total: u64) {
|
||||
if let Ok(mut state) = PROGRESS.lock() {
|
||||
if let Some(task) = state.tasks.get_mut(&id) {
|
||||
task.progress = Some((current, total));
|
||||
}
|
||||
refresh_visible(&mut state);
|
||||
}
|
||||
crate::tui::request_redraw();
|
||||
}
|
||||
|
||||
impl Drop for ProgressTask {
|
||||
fn drop(&mut self) {
|
||||
if !self.finished {
|
||||
self.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn refresh_visible(state: &mut ProgressState) {
|
||||
if let Some((_, task)) = state.tasks.last_key_value() {
|
||||
state.current_action = Some(task.action.clone());
|
||||
state.sub_action.clone_from(&task.sub_action);
|
||||
state.progress = task.progress;
|
||||
} else if !state.legacy_active {
|
||||
state.current_action = None;
|
||||
state.sub_action = None;
|
||||
state.progress = None;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_action(text: impl Into<String>) {
|
||||
let text = text.into();
|
||||
match PROGRESS.lock() {
|
||||
Ok(mut state) => {
|
||||
state.legacy_active = true;
|
||||
state.current_action = Some(text.clone());
|
||||
crate::tui::request_redraw();
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Progress lock poisoned: {}", e);
|
||||
}
|
||||
}
|
||||
tracing::info!("{}", text);
|
||||
}
|
||||
|
||||
pub fn set_progress(current: u64, total: u64) {
|
||||
match PROGRESS.lock() {
|
||||
Ok(mut state) => {
|
||||
state.progress = Some((current, total));
|
||||
crate::tui::request_redraw();
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Progress lock poisoned: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_sub_action(text: impl Into<String>) {
|
||||
let text = text.into();
|
||||
match PROGRESS.lock() {
|
||||
Ok(mut state) => {
|
||||
state.sub_action = Some(text.clone());
|
||||
crate::tui::request_redraw();
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Progress lock poisoned: {}", e);
|
||||
}
|
||||
}
|
||||
tracing::debug!(" {}", text);
|
||||
}
|
||||
|
||||
pub fn clear() {
|
||||
match PROGRESS.lock() {
|
||||
Ok(mut state) => {
|
||||
state.legacy_active = false;
|
||||
refresh_visible(&mut state);
|
||||
crate::tui::request_redraw();
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Progress lock poisoned: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_active() -> bool {
|
||||
PROGRESS
|
||||
.lock()
|
||||
.is_ok_and(|state| state.current_action.is_some())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/progress.rs"]
|
||||
mod tests;
|
||||
+1
-1
@@ -13,7 +13,7 @@ use super::app::{App, ErrorEffectState, FocusedArea};
|
||||
use super::widgets::{
|
||||
self, popups::confirm as confirm_popup, popups::import_modpack, popups::new_instance,
|
||||
};
|
||||
use crate::tui::error_buffer;
|
||||
use crate::feedback::errors as error_buffer;
|
||||
use crate::tui::widgets::popups::confirm::{ConfirmPopup, confirm_popup_area};
|
||||
use crate::tui::widgets::popups::error::{ErrorPopup, popup_area};
|
||||
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
use super::*;
|
||||
use crate::tui::tests::UI_TEST_LOCK;
|
||||
|
||||
fn clear_errors_for_test() {
|
||||
ERROR_EVENTS.lock().unwrap().clear();
|
||||
}
|
||||
|
||||
fn make_event(msg: &str) -> ErrorEvent {
|
||||
ErrorEvent {
|
||||
id: 0,
|
||||
level: Level::ERROR,
|
||||
message: msg.to_string(),
|
||||
pushed_at: Instant::now(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn peek_does_not_remove() {
|
||||
let _guard = UI_TEST_LOCK.lock().unwrap();
|
||||
clear_errors_for_test();
|
||||
|
||||
push_error(make_event("peek-test"));
|
||||
|
||||
let count_before = peek_all_errors().len();
|
||||
let peeked = peek_error();
|
||||
let count_after = peek_all_errors().len();
|
||||
|
||||
assert_eq!(
|
||||
count_before, count_after,
|
||||
"peek should not change queue length"
|
||||
);
|
||||
|
||||
assert!(peeked.is_some());
|
||||
assert_eq!(peeked.unwrap().message, "peek-test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn peek_all_returns_newest_first() {
|
||||
let _guard = UI_TEST_LOCK.lock().unwrap();
|
||||
clear_errors_for_test();
|
||||
|
||||
push_error(make_event("newest_a"));
|
||||
push_error(make_event("newest_b"));
|
||||
|
||||
let all = peek_all_errors();
|
||||
|
||||
assert_eq!(all.len(), 2);
|
||||
assert!(all[0].message.ends_with("_b"));
|
||||
assert!(all[1].message.ends_with("_a"));
|
||||
assert!(all[0].id > all[1].id);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auto_assigned_ids_are_unique() {
|
||||
let _guard = UI_TEST_LOCK.lock().unwrap();
|
||||
clear_errors_for_test();
|
||||
|
||||
push_error(make_event("unique_1"));
|
||||
push_error(make_event("unique_2"));
|
||||
|
||||
let all = peek_all_errors();
|
||||
|
||||
assert_eq!(all.len(), 2);
|
||||
assert_ne!(all[0].id, all[1].id);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overflow_drops_oldest() {
|
||||
let _guard = UI_TEST_LOCK.lock().unwrap();
|
||||
clear_errors_for_test();
|
||||
|
||||
for i in 0..(MAX_ERROR_EVENTS + 10) {
|
||||
push_error(make_event(&format!("overflow_{i}")));
|
||||
}
|
||||
|
||||
let all = peek_all_errors();
|
||||
|
||||
assert_eq!(all.len(), MAX_ERROR_EVENTS);
|
||||
|
||||
assert!(!all.iter().any(|e| e.message == "overflow_0"));
|
||||
assert!(!all.iter().any(|e| e.message == "overflow_9"));
|
||||
|
||||
assert!(all.iter().any(|e| e.message == "overflow_10"));
|
||||
assert!(all.iter().any(|e| e.message == "overflow_59"));
|
||||
}
|
||||
@@ -3,9 +3,9 @@ use std::collections::{HashMap, HashSet};
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
|
||||
use ratatui::{Terminal, backend::TestBackend};
|
||||
|
||||
use super::UI_TEST_LOCK;
|
||||
use crate::auth::{Account, AccountStore, AccountType};
|
||||
use crate::instance::{InstanceConfig, InstanceManager, ModLoader};
|
||||
use crate::tests::TEST_LOCK;
|
||||
use crate::tui::{
|
||||
app::{App, FocusedArea},
|
||||
widgets,
|
||||
@@ -21,17 +21,15 @@ pub(in crate::tui) struct UiHarness {
|
||||
|
||||
impl UiHarness {
|
||||
pub fn new() -> Self {
|
||||
let guard = UI_TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner());
|
||||
let guard = TEST_LOCK.lock().unwrap_or_else(|error| error.into_inner());
|
||||
widgets::popups::confirm::clear_pending();
|
||||
widgets::popups::new_instance::reset_for_test();
|
||||
widgets::popups::import_modpack::reset_for_test();
|
||||
crate::tui::error_buffer::ERROR_EVENTS
|
||||
crate::feedback::errors::ERROR_EVENTS
|
||||
.lock()
|
||||
.expect("error buffer")
|
||||
.clear();
|
||||
crate::tui::progress::clear();
|
||||
crate::feedback::progress::clear();
|
||||
|
||||
let temp = tempfile::tempdir().expect("temporary UI data");
|
||||
let instances_dir = temp.path().join("instances");
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
mod flows;
|
||||
pub(super) mod harness;
|
||||
mod snapshots;
|
||||
|
||||
use std::sync::Mutex;
|
||||
|
||||
pub(crate) static UI_TEST_LOCK: Mutex<()> = Mutex::new(());
|
||||
@@ -1,57 +0,0 @@
|
||||
use super::*;
|
||||
use crate::tui::tests::UI_TEST_LOCK;
|
||||
|
||||
#[test]
|
||||
fn newest_task_is_visible_and_drop_restores_previous_task() {
|
||||
let _guard = UI_TEST_LOCK.lock().unwrap();
|
||||
clear();
|
||||
let first = ProgressTask::start("first");
|
||||
first.set_progress(1, 2);
|
||||
{
|
||||
let second = ProgressTask::start("second");
|
||||
second.set_sub_action("working");
|
||||
let state = PROGRESS.lock().unwrap();
|
||||
assert_eq!(state.current_action.as_deref(), Some("second"));
|
||||
assert_eq!(state.sub_action.as_deref(), Some("working"));
|
||||
}
|
||||
let state = PROGRESS.lock().unwrap();
|
||||
assert_eq!(state.current_action.as_deref(), Some("first"));
|
||||
assert_eq!(state.progress, Some((1, 2)));
|
||||
drop(state);
|
||||
first.finish();
|
||||
clear();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn changing_phase_keeps_the_existing_progress_visible() {
|
||||
let _guard = UI_TEST_LOCK.lock().unwrap();
|
||||
clear();
|
||||
let task = ProgressTask::start("inventory");
|
||||
task.set_progress(4, 10);
|
||||
task.set_action("provider matching");
|
||||
|
||||
let state = PROGRESS.lock().unwrap();
|
||||
assert_eq!(state.current_action.as_deref(), Some("provider matching"));
|
||||
assert_eq!(state.progress, Some((4, 10)));
|
||||
drop(state);
|
||||
|
||||
task.finish();
|
||||
assert!(!is_active());
|
||||
clear();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clearing_legacy_progress_keeps_owned_tasks() {
|
||||
let _guard = UI_TEST_LOCK.lock().unwrap();
|
||||
clear();
|
||||
let task = ProgressTask::start("indexing");
|
||||
set_action("legacy download");
|
||||
clear();
|
||||
|
||||
let state = PROGRESS.lock().unwrap();
|
||||
assert_eq!(state.current_action.as_deref(), Some("indexing"));
|
||||
drop(state);
|
||||
|
||||
task.finish();
|
||||
clear();
|
||||
}
|
||||
@@ -13,16 +13,16 @@ fn empty_app_renders_the_complete_frame() {
|
||||
#[test]
|
||||
fn active_progress_is_visible_in_the_complete_frame() {
|
||||
let mut ui = UiHarness::new();
|
||||
crate::tui::progress::set_action("Downloading test data");
|
||||
crate::tui::progress::set_sub_action("one.jar");
|
||||
crate::tui::progress::set_progress(1, 2);
|
||||
crate::feedback::progress::set_action("Downloading test data");
|
||||
crate::feedback::progress::set_sub_action("one.jar");
|
||||
crate::feedback::progress::set_progress(1, 2);
|
||||
|
||||
ui.draw();
|
||||
|
||||
let screen = ui.screen();
|
||||
assert!(screen.contains("Downloading test data"));
|
||||
assert!(screen.contains("one.jar"));
|
||||
crate::tui::progress::clear();
|
||||
crate::feedback::progress::clear();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use crate::tui::tests::UI_TEST_LOCK;
|
||||
use crate::tests::TEST_LOCK;
|
||||
use chrono::Utc;
|
||||
use crossterm::event::KeyModifiers;
|
||||
|
||||
@@ -283,9 +283,7 @@ fn discovery_delete_only_clears_the_matching_installed_badge() {
|
||||
|
||||
#[test]
|
||||
fn successful_install_marks_the_project_and_closes_the_popup() {
|
||||
let _guard = UI_TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner());
|
||||
let _guard = TEST_LOCK.lock().unwrap_or_else(|error| error.into_inner());
|
||||
let project = DiscoveryProject {
|
||||
id: "project".to_owned(),
|
||||
slug: "project".to_owned(),
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
use ratatui::{Terminal, backend::TestBackend};
|
||||
|
||||
fn formatted_text(source: &str, width: u16) -> ratatui::text::Text<'static> {
|
||||
super::external_markdown_text(source, width).0
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn html_images_are_extracted_and_raw_html_is_removed() {
|
||||
let document = super::Document::new(
|
||||
@@ -89,7 +93,7 @@ fn inserted_html_keeps_its_content_and_hides_tag_shells() {
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
let text = super::formatted_text(source, 80);
|
||||
let text = formatted_text(source, 80);
|
||||
let rendered = text
|
||||
.lines
|
||||
.iter()
|
||||
@@ -123,7 +127,7 @@ fn nested_inline_html_uses_dom_conversion_for_links_and_emphasis() {
|
||||
assert!(source.contains("[**Supported**](https://example.com)"));
|
||||
assert!(!source.contains('<'));
|
||||
|
||||
let text = super::formatted_text(source, 80);
|
||||
let text = formatted_text(source, 80);
|
||||
let supported = text
|
||||
.lines
|
||||
.iter()
|
||||
@@ -162,7 +166,7 @@ fn markdown_images_inside_links_do_not_leave_the_link_destination() {
|
||||
|
||||
#[test]
|
||||
fn visible_link_text_does_not_include_the_destination() {
|
||||
let text = super::formatted_text("[buying me a coffee](https://example.com/donate)", 80);
|
||||
let text = formatted_text("[buying me a coffee](https://example.com/donate)", 80);
|
||||
let rendered = text
|
||||
.lines
|
||||
.iter()
|
||||
@@ -227,7 +231,7 @@ fn only_explicitly_centered_project_images_are_centered() {
|
||||
|
||||
#[test]
|
||||
fn headings_hide_markers_and_rules_use_terminal_lines() {
|
||||
let text = super::formatted_text("## Known Issues\n\n---", 12);
|
||||
let text = formatted_text("## Known Issues\n\n---", 12);
|
||||
let rendered = text
|
||||
.lines
|
||||
.iter()
|
||||
@@ -246,7 +250,7 @@ fn headings_hide_markers_and_rules_use_terminal_lines() {
|
||||
|
||||
#[test]
|
||||
fn all_heading_levels_are_bold() {
|
||||
let text = super::formatted_text("### Performance", 20);
|
||||
let text = formatted_text("### Performance", 20);
|
||||
let heading = text
|
||||
.lines
|
||||
.iter()
|
||||
@@ -301,7 +305,7 @@ fn unrelated_and_later_headings_are_kept() {
|
||||
|
||||
#[test]
|
||||
fn lists_use_terminal_bullets() {
|
||||
let text = super::formatted_text("- first\n - nested\n- second", 20);
|
||||
let text = formatted_text("- first\n - nested\n- second", 20);
|
||||
let rendered = text
|
||||
.lines
|
||||
.iter()
|
||||
@@ -317,7 +321,7 @@ fn lists_use_terminal_bullets() {
|
||||
|
||||
#[test]
|
||||
fn wrapped_list_items_keep_a_hanging_indent() {
|
||||
let text = super::formatted_text("- one two three four", 16);
|
||||
let text = formatted_text("- one two three four", 16);
|
||||
let rendered = text
|
||||
.lines
|
||||
.iter()
|
||||
@@ -347,7 +351,7 @@ fn markdown_headings_with_inline_html_are_converted_as_one_block() {
|
||||
})
|
||||
.unwrap();
|
||||
assert!(!source.contains('<'), "{source}");
|
||||
let rendered = super::formatted_text(source, 80)
|
||||
let rendered = formatted_text(source, 80)
|
||||
.lines
|
||||
.iter()
|
||||
.flat_map(|line| &line.spans)
|
||||
@@ -388,7 +392,7 @@ fn emphasis_survives_html_list_conversion_without_literal_markers() {
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
let text = super::formatted_text(source, 80);
|
||||
let text = formatted_text(source, 80);
|
||||
let rendered = text
|
||||
.lines
|
||||
.iter()
|
||||
@@ -419,7 +423,7 @@ fn emphasis_next_to_html_tag_boundaries_does_not_leak_markers() {
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
let rendered = super::formatted_text(source, 100)
|
||||
let rendered = formatted_text(source, 100)
|
||||
.lines
|
||||
.iter()
|
||||
.flat_map(|line| &line.spans)
|
||||
@@ -430,7 +434,7 @@ fn emphasis_next_to_html_tag_boundaries_does_not_leak_markers() {
|
||||
|
||||
#[test]
|
||||
fn fenced_code_blocks_are_rendered_without_fences() {
|
||||
let text = super::formatted_text("```json5\n{\n \"enabled\": true\n}\n```", 24);
|
||||
let text = formatted_text("```json5\n{\n \"enabled\": true\n}\n```", 24);
|
||||
let rendered = text
|
||||
.lines
|
||||
.iter()
|
||||
@@ -462,7 +466,7 @@ fn fenced_code_blocks_are_rendered_without_fences() {
|
||||
|
||||
#[test]
|
||||
fn tables_wrap_cells_without_breaking_the_columns() {
|
||||
let text = super::formatted_text(
|
||||
let text = formatted_text(
|
||||
"| Mod | Status | Note |\n| --- | --- | --- |\n| Player Animator | Supported | This means mods that use it like Better Combat and Emotecraft |",
|
||||
48,
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ use ratatui::backend::TestBackend;
|
||||
use std::time::Instant;
|
||||
use tracing::Level;
|
||||
|
||||
use crate::tui::error_buffer::ErrorEvent;
|
||||
use crate::feedback::errors::ErrorEvent;
|
||||
|
||||
fn render(event: ErrorEvent, width: u16, height: u16) -> Terminal<TestBackend> {
|
||||
let backend = TestBackend::new(width, height);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use crate::tui::tests::UI_TEST_LOCK;
|
||||
use crate::tests::TEST_LOCK;
|
||||
use ratatui::Terminal;
|
||||
use ratatui::backend::TestBackend;
|
||||
|
||||
@@ -12,7 +12,7 @@ fn reset_import_state(step: ImportStep) {
|
||||
|
||||
#[test]
|
||||
fn import_modpack_renders_input_step() {
|
||||
let _serial = UI_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
reset_import_state(ImportStep::Input);
|
||||
|
||||
let backend = TestBackend::new(60, 12);
|
||||
@@ -25,7 +25,7 @@ fn import_modpack_renders_input_step() {
|
||||
|
||||
#[test]
|
||||
fn import_modpack_renders_fetching_step() {
|
||||
let _serial = UI_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
reset_import_state(ImportStep::Fetching);
|
||||
|
||||
let backend = TestBackend::new(60, 12);
|
||||
@@ -43,7 +43,7 @@ fn import_modpack_renders_fetching_step() {
|
||||
fn import_modpack_renders_version_step() {
|
||||
use crate::net::modrinth::VersionInfo;
|
||||
|
||||
let _serial = UI_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
{
|
||||
let mut guard = IMPORT_STATE.lock().expect("IMPORT_STATE lock");
|
||||
*guard = ImportWizardState::default();
|
||||
@@ -90,7 +90,7 @@ fn import_modpack_renders_confirm_step() {
|
||||
use crate::instance::models::ModLoader;
|
||||
use std::path::PathBuf;
|
||||
|
||||
let _serial = UI_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
{
|
||||
let mut guard = IMPORT_STATE.lock().expect("IMPORT_STATE lock");
|
||||
*guard = ImportWizardState::default();
|
||||
@@ -125,7 +125,7 @@ fn import_modpack_renders_confirm_step_without_loader_version() {
|
||||
use crate::instance::models::ModLoader;
|
||||
use std::path::PathBuf;
|
||||
|
||||
let _serial = UI_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
{
|
||||
let mut guard = IMPORT_STATE.lock().expect("IMPORT_STATE lock");
|
||||
*guard = ImportWizardState::default();
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::instance::{
|
||||
ModLoader,
|
||||
import::{ImportSummary, PackFormat},
|
||||
};
|
||||
use crate::tui::tests::UI_TEST_LOCK;
|
||||
use crate::tests::TEST_LOCK;
|
||||
|
||||
fn key(code: KeyCode) -> KeyEvent {
|
||||
KeyEvent::new(code, KeyModifiers::NONE)
|
||||
@@ -29,9 +29,7 @@ fn summary() -> ImportSummary {
|
||||
|
||||
#[test]
|
||||
fn empty_input_is_ignored_and_escape_closes_the_popup() {
|
||||
let _guard = UI_TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner());
|
||||
let _guard = TEST_LOCK.lock().unwrap_or_else(|error| error.into_inner());
|
||||
let mut instances = instances::State {
|
||||
show_import_popup: true,
|
||||
..instances::State::default()
|
||||
@@ -47,9 +45,7 @@ fn empty_input_is_ignored_and_escape_closes_the_popup() {
|
||||
|
||||
#[test]
|
||||
fn confirm_returns_the_import_summary() {
|
||||
let _guard = UI_TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner());
|
||||
let _guard = TEST_LOCK.lock().unwrap_or_else(|error| error.into_inner());
|
||||
let mut instances = instances::State {
|
||||
show_import_popup: true,
|
||||
..instances::State::default()
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
use super::state;
|
||||
|
||||
pub(crate) fn reset() {
|
||||
state::IMPORT_STATE
|
||||
.lock()
|
||||
.expect("import wizard state")
|
||||
.reset();
|
||||
*state::IMPORT_RESULT.lock().expect("import wizard result") = None;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use crate::tui::tests::UI_TEST_LOCK;
|
||||
use crate::tests::TEST_LOCK;
|
||||
use ratatui::Terminal;
|
||||
use ratatui::backend::TestBackend;
|
||||
|
||||
@@ -15,7 +15,7 @@ fn reset_wizard_state(step: WizardStep) {
|
||||
|
||||
#[test]
|
||||
fn new_instance_renders_name_step() {
|
||||
let _serial = UI_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
// Name is the default step; render touches no network helpers.
|
||||
reset_wizard_state(WizardStep::Name);
|
||||
|
||||
@@ -29,7 +29,7 @@ fn new_instance_renders_name_step() {
|
||||
|
||||
#[test]
|
||||
fn new_instance_renders_loader_step() {
|
||||
let _serial = UI_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
// Loader step is reached after Name; render just paints the hardcoded
|
||||
// loader list, no network.
|
||||
reset_wizard_state(WizardStep::Loader);
|
||||
@@ -50,7 +50,7 @@ fn new_instance_renders_loader_step() {
|
||||
fn new_instance_renders_version_step() {
|
||||
use crate::instance::loader::GameVersion;
|
||||
|
||||
let _serial = UI_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
{
|
||||
let mut guard = WIZARD_STATE.lock().expect("WIZARD_STATE lock");
|
||||
*guard = WizardState::default();
|
||||
@@ -86,7 +86,7 @@ fn new_instance_renders_version_step() {
|
||||
fn new_instance_renders_loader_version_step() {
|
||||
use crate::instance::loader::GameVersion;
|
||||
|
||||
let _serial = UI_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
{
|
||||
let mut guard = WIZARD_STATE.lock().expect("WIZARD_STATE lock");
|
||||
*guard = WizardState::default();
|
||||
@@ -115,7 +115,7 @@ fn new_instance_renders_confirm_step() {
|
||||
use crate::instance::loader::GameVersion;
|
||||
use tui_prompts::TextState;
|
||||
|
||||
let _serial = UI_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let _serial = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
{
|
||||
let mut guard = WIZARD_STATE.lock().expect("WIZARD_STATE lock");
|
||||
*guard = WizardState::default();
|
||||
|
||||
@@ -2,7 +2,7 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use tui_prompts::TextState;
|
||||
|
||||
use super::*;
|
||||
use crate::tui::tests::UI_TEST_LOCK;
|
||||
use crate::tests::TEST_LOCK;
|
||||
|
||||
fn key(code: KeyCode) -> KeyEvent {
|
||||
KeyEvent::new(code, KeyModifiers::NONE)
|
||||
@@ -10,9 +10,7 @@ fn key(code: KeyCode) -> KeyEvent {
|
||||
|
||||
#[test]
|
||||
fn vanilla_wizard_reaches_confirm_and_returns_parameters() {
|
||||
let _guard = UI_TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner());
|
||||
let _guard = TEST_LOCK.lock().unwrap_or_else(|error| error.into_inner());
|
||||
let mut instances = instances::State {
|
||||
show_popup: true,
|
||||
..instances::State::default()
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
use super::state;
|
||||
|
||||
pub(crate) fn reset() {
|
||||
state::WIZARD_STATE.lock().expect("wizard state").reset();
|
||||
*state::WIZARD_RESULT.lock().expect("wizard result") = None;
|
||||
}
|
||||
@@ -420,7 +420,7 @@ impl DiscoveryState {
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ impl DiscoveryState {
|
||||
};
|
||||
entry.installed_path = None;
|
||||
entry.title_suffix = None;
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
true
|
||||
}
|
||||
|
||||
@@ -520,14 +520,14 @@ impl DiscoveryState {
|
||||
offset,
|
||||
result,
|
||||
});
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_action_result(pending: &PendingActions, result: DiscoveryActionResult) {
|
||||
if let Ok(mut pending) = pending.lock() {
|
||||
pending.push(result);
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -689,24 +689,20 @@ impl DiscoveryState {
|
||||
} else {
|
||||
"installed"
|
||||
};
|
||||
crate::tui::error_buffer::push_error(
|
||||
crate::tui::error_buffer::ErrorEvent {
|
||||
id: request_id,
|
||||
level: tracing::Level::INFO,
|
||||
message: format!("{project_title}: {action}"),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
},
|
||||
);
|
||||
crate::feedback::errors::push_error(crate::feedback::errors::ErrorEvent {
|
||||
id: request_id,
|
||||
level: tracing::Level::INFO,
|
||||
message: format!("{project_title}: {action}"),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
Err(error) => {
|
||||
crate::tui::error_buffer::push_error(
|
||||
crate::tui::error_buffer::ErrorEvent {
|
||||
id: request_id,
|
||||
level: tracing::Level::ERROR,
|
||||
message: format!("{project_title}: {error}"),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
},
|
||||
);
|
||||
crate::feedback::errors::push_error(crate::feedback::errors::ErrorEvent {
|
||||
id: request_id,
|
||||
level: tracing::Level::ERROR,
|
||||
message: format!("{project_title}: {error}"),
|
||||
pushed_at: std::time::Instant::now(),
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ pub struct ContentStream {
|
||||
impl ContentStream {
|
||||
pub fn send(&self, entry: ContentEntry) -> bool {
|
||||
if self.sender.send(ContentStreamUpdate::Entry(entry)).is_ok() {
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@@ -58,7 +58,7 @@ impl ContentStream {
|
||||
})
|
||||
.is_ok()
|
||||
{
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@@ -71,7 +71,7 @@ impl ContentStream {
|
||||
.send(ContentStreamUpdate::IconUnavailable { file_stem, path })
|
||||
.is_ok()
|
||||
{
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@@ -80,7 +80,7 @@ impl ContentStream {
|
||||
|
||||
pub fn upsert(&self, entry: ContentEntry) -> bool {
|
||||
if self.sender.send(ContentStreamUpdate::Upsert(entry)).is_ok() {
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@@ -93,7 +93,7 @@ impl ContentStream {
|
||||
.send(ContentStreamUpdate::Retain(file_stems))
|
||||
.is_ok()
|
||||
{
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@@ -287,7 +287,7 @@ impl ContentListState {
|
||||
self.pending_entry_images.remove(&stem);
|
||||
}
|
||||
self.rebuild_display_metadata();
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ impl ContentListState {
|
||||
}
|
||||
if changed {
|
||||
self.images_dirty = true;
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
changed
|
||||
}
|
||||
@@ -375,7 +375,7 @@ impl ContentListState {
|
||||
bytes,
|
||||
description,
|
||||
});
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
}
|
||||
Ok(_) => {}
|
||||
@@ -559,7 +559,7 @@ impl ContentListState {
|
||||
&& let Ok(mut pending) = pending.lock()
|
||||
{
|
||||
pending.push(result);
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -924,7 +924,7 @@ impl ContentListState {
|
||||
} else {
|
||||
*slot = Some(diff);
|
||||
}
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
|
||||
let no_pending = pending_paths.lock().is_ok_and(|pending| pending.is_empty());
|
||||
@@ -1260,7 +1260,7 @@ async fn load_provider_metadata(
|
||||
.ok()
|
||||
.filter(|bytes| !bytes.is_empty() && image::load_from_memory(bytes).is_ok());
|
||||
|
||||
let registry = crate::content_provider::ProviderRegistry::modrinth(client.clone());
|
||||
let registry = crate::instance::content::provider::ProviderRegistry::modrinth(client.clone());
|
||||
let provider = registry.preferred(provider_id).ok_or_else(|| {
|
||||
crate::net::NetError::Parse(format!("Content provider '{provider_id}' is unavailable"))
|
||||
})?;
|
||||
|
||||
@@ -778,8 +778,8 @@ pub fn title(
|
||||
let [left_area, right_area] =
|
||||
Layout::horizontal([Constraint::Min(0), Constraint::Length(32)]).areas(inner);
|
||||
|
||||
use crate::running::RunState;
|
||||
let run_state = crate::running::get(&inst.name);
|
||||
use crate::instance::runtime::RunState;
|
||||
let run_state = crate::instance::runtime::get(&inst.name);
|
||||
|
||||
match run_state {
|
||||
Some(RunState::Authenticating)
|
||||
|
||||
@@ -14,7 +14,7 @@ use ratatui::{
|
||||
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
|
||||
|
||||
use crate::instance::models::InstanceConfig;
|
||||
use crate::running::{RunState, get as get_run_state};
|
||||
use crate::instance::runtime::{RunState, get as get_run_state};
|
||||
use crate::tui::app::FocusedArea;
|
||||
|
||||
use super::{WidgetKey, search::SearchState, styled_title};
|
||||
|
||||
@@ -18,7 +18,7 @@ use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
|
||||
|
||||
use crate::config::theme::{BORDER_STYLE, THEME};
|
||||
use crate::instance::launch::parser::LogLevel;
|
||||
use crate::instance::log_files::{LogFileEntry, read_log_file, scan_log_files};
|
||||
use crate::instance::logs::files::{LogFileEntry, read_log_file, scan_log_files};
|
||||
|
||||
type PendingLogs = Arc<Mutex<Option<(String, Vec<LogFileEntry>)>>>;
|
||||
|
||||
@@ -93,7 +93,7 @@ impl LogsState {
|
||||
|
||||
if let Ok(mut slot) = pending.lock() {
|
||||
*slot = Some((tag, entries));
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -140,11 +140,11 @@ impl LogsState {
|
||||
return;
|
||||
};
|
||||
if !matches!(
|
||||
crate::running::get(name),
|
||||
crate::instance::runtime::get(name),
|
||||
Some(
|
||||
crate::running::RunState::Authenticating
|
||||
| crate::running::RunState::Starting
|
||||
| crate::running::RunState::Running
|
||||
crate::instance::runtime::RunState::Authenticating
|
||||
| crate::instance::runtime::RunState::Starting
|
||||
| crate::instance::runtime::RunState::Running
|
||||
)
|
||||
) {
|
||||
return;
|
||||
@@ -164,7 +164,7 @@ impl LogsState {
|
||||
|
||||
if let Ok(mut slot) = pending.lock() {
|
||||
*slot = Some((tag, entries));
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -174,10 +174,10 @@ impl LogsState {
|
||||
fn has_live(&self) -> bool {
|
||||
let name = self.loaded_for.as_deref().unwrap_or("");
|
||||
matches!(
|
||||
crate::running::get(name),
|
||||
Some(crate::running::RunState::Running)
|
||||
| Some(crate::running::RunState::Starting)
|
||||
| Some(crate::running::RunState::Crashed(_))
|
||||
crate::instance::runtime::get(name),
|
||||
Some(crate::instance::runtime::RunState::Running)
|
||||
| Some(crate::instance::runtime::RunState::Starting)
|
||||
| Some(crate::instance::runtime::RunState::Crashed(_))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -580,7 +580,7 @@ fn render_viewer(
|
||||
|
||||
let all_lines: Vec<ViewerLine> = if is_live {
|
||||
let name = state.loaded_for.as_deref().unwrap_or("");
|
||||
crate::instance_logs::get_entries(name)
|
||||
crate::instance::logs::live::get_entries(name)
|
||||
.into_iter()
|
||||
.map(|line| ViewerLine {
|
||||
text: line.text,
|
||||
|
||||
@@ -569,11 +569,6 @@ fn push_text_block(blocks: &mut Vec<DocumentBlock>, source: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn formatted_text(source: &str, width: u16) -> Text<'static> {
|
||||
external_markdown_text(source, width).0
|
||||
}
|
||||
|
||||
fn external_markdown_text(source: &str, width: u16) -> (Text<'static>, Vec<LinkTarget>) {
|
||||
let theme = markdown_theme();
|
||||
let rule_style = theme.rule;
|
||||
@@ -1479,7 +1474,7 @@ fn prepare_image(
|
||||
if let Ok(mut pending) = pending.lock() {
|
||||
pending.push(PreparedImageResult { url, key, result });
|
||||
}
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use tracing::Level;
|
||||
use super::base::PopupFrame;
|
||||
use crate::config::SETTINGS;
|
||||
use crate::config::theme::THEME;
|
||||
use crate::tui::error_buffer::ErrorEvent;
|
||||
use crate::feedback::errors::ErrorEvent;
|
||||
|
||||
pub struct ErrorPopup {
|
||||
pub event: ErrorEvent,
|
||||
|
||||
@@ -5,10 +5,7 @@ pub use render::{popup_rect, render};
|
||||
pub use state::{ImportResult, ImportStep, ImportWizardState, handle_key, take_result};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn reset_for_test() {
|
||||
state::IMPORT_STATE
|
||||
.lock()
|
||||
.expect("import wizard state")
|
||||
.reset();
|
||||
*state::IMPORT_RESULT.lock().expect("import wizard result") = None;
|
||||
}
|
||||
#[path = "../../../tests/widgets/popups/import_modpack/support.rs"]
|
||||
mod test_support;
|
||||
#[cfg(test)]
|
||||
pub(crate) use test_support::reset as reset_for_test;
|
||||
@@ -407,7 +407,7 @@ fn close_popup(state: &mut ImportWizardState, instances_state: &mut instances::S
|
||||
}
|
||||
|
||||
fn push_import_error(msg: String) {
|
||||
crate::tui::error_buffer::push_error(crate::tui::error_buffer::ErrorEvent {
|
||||
crate::feedback::errors::push_error(crate::feedback::errors::ErrorEvent {
|
||||
id: 0,
|
||||
level: Level::ERROR,
|
||||
message: msg,
|
||||
|
||||
@@ -7,7 +7,7 @@ pub use render::{popup_rect, render};
|
||||
pub use state::{WizardParams, WizardState, WizardStep, handle_key, take_result};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn reset_for_test() {
|
||||
state::WIZARD_STATE.lock().expect("wizard state").reset();
|
||||
*state::WIZARD_RESULT.lock().expect("wizard result") = None;
|
||||
}
|
||||
#[path = "../../../tests/widgets/popups/new_instance/support.rs"]
|
||||
mod test_support;
|
||||
#[cfg(test)]
|
||||
pub(crate) use test_support::reset as reset_for_test;
|
||||
@@ -111,7 +111,7 @@ impl ScreenshotsState {
|
||||
|
||||
if let Ok(mut slot) = pending.lock() {
|
||||
*slot = Some((tag, entries));
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -169,7 +169,7 @@ impl ScreenshotsState {
|
||||
&& let Ok(mut slot) = pending.lock()
|
||||
{
|
||||
slot.push((idx, img));
|
||||
crate::tui::request_redraw();
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ fn effective_java_path(instance: &InstanceConfig) -> String {
|
||||
.java_path
|
||||
.clone()
|
||||
.or_else(|| SETTINGS.paths.effective_java_path().map(str::to_string))
|
||||
.unwrap_or_else(crate::net::detect_java_path)
|
||||
.unwrap_or_else(crate::instance::java::detect_java_path)
|
||||
}
|
||||
|
||||
fn java_version_label(java_path: &str) -> String {
|
||||
|
||||
@@ -11,8 +11,8 @@ use ratatui::{
|
||||
use throbber_widgets_tui::{Throbber, ThrobberState};
|
||||
|
||||
use crate::config::theme::{BORDER_STYLE, THEME};
|
||||
use crate::feedback::progress::PROGRESS;
|
||||
use crate::tui::app::FocusedArea;
|
||||
use crate::tui::progress::PROGRESS;
|
||||
|
||||
use super::styled_title;
|
||||
|
||||
|
||||
Reference in new issue
Block a user