style: remove redundant code narration

This commit is contained in:
objz committed 2026-10-01 13:53:12 +02:00
1 parent 495f31778b
commit 783fb76f06
115 files changed
+19 -746

No files matched your search

-7
View File
@@ -1,10 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// account management panel: list, add (microsoft/offline), delete
// microsoft auth uses the device code flow, so it polls a shared mutex
// for the result while showing the user a code to enter in their browser
use std::sync::{Arc, Mutex};
use crossterm::event::{KeyCode, KeyEvent};
@@ -196,8 +192,6 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut AccountState) -> bool {
}
}
// the device code arrives asynchronously from the auth thread,
// so it gets pulled out of a global mutex once it's ready
pub fn drain_device_code(state: &mut AccountState) {
if let AddMode::DeviceCodeWaiting { info, .. } = &mut state.add_mode
&& info.user_code.is_empty()
@@ -335,7 +329,6 @@ fn render_account_list(
frame.render_stateful_widget(list, area, &mut state.list_state);
}
// center a popup of given size within the terminal. nothing fancy
fn popup_area(frame: &Frame, width: u16, height: u16) -> Rect {
let area = frame.area();
let x = area.x + (area.width.saturating_sub(width)) / 2;
-27
View File
@@ -1,11 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// generic scrollable list for content items (mods, resource packs, shaders, worlds).
// supports toggling items on/off by renaming files with .disabled suffix,
// search filtering, per-instance caching, and directory change detection.
// also handles minecraft's formatting codes for colored mod names/descriptions
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::path::Path;
@@ -245,7 +240,6 @@ struct PaginationState {
const REMOVAL_GRACE: std::time::Duration = std::time::Duration::from_millis(500);
// result from the notify-triggered background diff
struct WatcherDiff {
toggled: Vec<(String, bool, std::path::PathBuf)>,
removed: Vec<String>,
@@ -292,19 +286,15 @@ pub struct ContentListState {
cache: HashMap<String, CachedList>,
sort_metadata: RefCell<HashMap<std::path::PathBuf, FileSortMetadata>>,
filtered_cache: RefCell<Option<CachedSelection>>,
// streaming: individual entries arrive here during initial load
stream_rx: Option<mpsc::Receiver<ContentStreamUpdate>>,
stream_order: ContentStreamOrder,
progressive_source_stream: bool,
staged_source_updates: Option<Vec<ContentStreamUpdate>>,
source_order_ready: bool,
preview_count: usize,
// file watcher: notify callback spawns background work,
// precomputed diff lands here for the UI to pick up
watcher_diff: Arc<Mutex<Option<WatcherDiff>>>,
_watcher: Option<notify::RecommendedWatcher>,
watched_dir: Option<std::path::PathBuf>,
// stored for the watcher to scan individual new files
scan_one_fn: Option<ScanOneFn>,
content_ext: Option<&'static str>,
pagination: Option<PaginationState>,
@@ -1175,7 +1165,6 @@ impl ContentListState {
};
self.images_dirty |= update.requires_reconcile;
// apply toggles (enabled/path changes)
tracing::debug!(
"Applying content watcher diff for {}: toggled={} removed={} added={}",
self.loaded_for.as_deref().unwrap_or("<unknown>"),
@@ -1214,7 +1203,6 @@ impl ContentListState {
.or_insert_with(std::time::Instant::now);
}
// insert new entries in sorted position
for mut entry in diff.added {
self.sort_metadata.get_mut().remove(&entry.path);
let replacement = self.entries.iter().position(|existing| {
@@ -1310,13 +1298,10 @@ impl ContentListState {
removed
}
// starts a notify file watcher on the given directory. changes trigger
// a background diff that lands in watcher_diff for drain_watcher to apply.
pub fn watch_dir(&mut self, dir: std::path::PathBuf) {
use notify::{RecursiveMode, Watcher};
use std::sync::atomic::{AtomicBool, Ordering};
// drop previous watcher
self._watcher = None;
let watcher_diff = self.watcher_diff.clone();
@@ -1706,9 +1691,6 @@ impl ContentListState {
}
}
// saves current entries to cache before loading new ones, and restores
// from cache if this instance was seen before (avoids re-scanning).
// content_dir is the actual directory to scan (e.g. .minecraft/mods).
pub fn start_load(
&mut self,
content_dir: &Path,
@@ -1724,7 +1706,6 @@ impl ContentListState {
self.pending_entry_images.clear();
self.pending_removals.clear();
// save current entries to cache
if let Some(prev) = self.loaded_for.take()
&& !self.entries.is_empty()
{
@@ -1743,7 +1724,6 @@ impl ContentListState {
);
}
// try cache first
// files modified while another instance was active become a real problem.
if let Some(cached) = self.cache.remove(instance_name) {
self.entries = cached.entries;
@@ -1769,7 +1749,6 @@ impl ContentListState {
return;
}
// no cache, stream entries one by one as each file is scanned
let stream = self.start_stream(instance_name);
let dir = content_dir.to_path_buf();
@@ -2690,8 +2669,6 @@ fn searchable_spans(
}
}
// parses minecraft's section-sign (U+00A7) formatting codes into styled spans.
// handles colors (0-f), bold (l), strikethrough (m), underline (n), italic (o), reset (r)
fn parse_mc_text(text: &str, base_style: Style) -> Vec<Span<'static>> {
let mut spans = Vec::new();
let mut current_style = base_style;
@@ -2976,10 +2953,6 @@ fn watcher_event_handling(kind: &notify::EventKind) -> WatcherEventHandling {
}
}
// reads a content directory and builds a stem -> (path, enabled) map.
// used both by watch_dir to initialize known state and by the watcher
// thread to detect changes. when ext is empty (worlds), only directories
// are included.
fn diff_directory(
dir: &std::path::Path,
ext: &str,
-2
View File
@@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// the tabbed content area: mods, resource packs, shaders, screenshots, worlds, logs
pub mod discovery;
pub mod list;
pub mod tabs;
-8
View File
@@ -1,10 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// the outer frame for the content area: tab bar, keybind footer,
// and dispatching render calls to the active tab's widget.
// also renders the instance name/version header with run state indicators.
use ratatui::{
Frame,
layout::{Alignment, Constraint, Direction, Layout, Margin, Rect},
@@ -357,8 +353,6 @@ pub fn render(
_ => false,
};
// keybinds change depending on which tab is active and whether
// the content panel or instances panel has focus
let kb: Option<&[(&str, &str)]> = if is_focused {
Some(match (mode, tab) {
(ContentMode::Discover, _) if discovery_unavailable => {
@@ -1762,8 +1756,6 @@ fn discovery_version_label(version: &crate::net::modrinth::VersionInfo) -> Strin
version.version_number.clone()
}
// the header bar above the content tabs, showing instance name, loader info,
// and a spinner/error indicator when the instance is running or crashed
pub fn title(
frame: &mut Frame,
area: Rect,
-4
View File
@@ -1,10 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// the instance list on the left side of the UI.
// handles search/filter, scrollbar sync, and inline renaming.
// each row shows instance name + "last played" or current run state.
use crate::config::theme::{BORDER_STYLE, THEME};
use crossterm::event::KeyCode;
use ratatui::{
-8
View File
@@ -1,11 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// split-pane log viewer: file list on the left, log content on the right.
// supports live log tailing when the instance is running, plus search
// filtering in both the file list and the viewer pane.
// log scanning runs on a background thread to avoid blocking the UI.
use std::path::Path;
use std::sync::{Arc, Mutex};
@@ -132,7 +127,6 @@ impl LogsState {
}
}
// periodically re-scan log files in case new ones appeared while playing.
pub fn try_rescan(&mut self) {
if self.last_rescan.elapsed() < std::time::Duration::from_secs(2) {
return;
@@ -676,8 +670,6 @@ fn log_level_style(level: LogLevel) -> Style {
}
}
// color-code log lines by severity so errors actually stand out
// instead of drowning in a wall of white text
fn line_level_style(line: &str) -> Style {
let theme = THEME.as_ref();
let upper = line.to_uppercase();
-2
View File
@@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// shared widget utilities and the trait all key-handling widgets implement
use crate::config::theme::THEME;
use crossterm::event::KeyEvent;
use ratatui::{
-5
View File
@@ -1,10 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// base frame that all popups render inside. handles the border, title bar,
// keybind footer, and optional search indicator. content is injected via closure
// so each popup type only worries about its inner area.
use ratatui::{
buffer::{Buffer, CellDiffOption},
layout::{Alignment, Rect},
@@ -40,7 +36,6 @@ impl<'a> Widget for PopupFrame<'a> {
})
.collect::<Vec<_>>();
// clear first so the popup doesn't layer on top of whatever was underneath
Clear.render(area, buf);
if let Some(bg) = self.bg {
-3
View File
@@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// "are you sure?" popup for destructive actions. uses global state so the
// confirmation target persists across render frames.
use std::sync::LazyLock;
use std::sync::Mutex;
-5
View File
@@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// toast-style error/warning popup that auto-dismisses after a timeout.
// stacks in the top-right corner; border color changes based on severity.
use ratatui::{
buffer::Buffer,
layout::Rect,
@@ -66,8 +63,6 @@ impl Widget for ErrorPopup {
}
}
// returns None when the toast has lived past its expiry, which is
// what triggers removal from the render loop
pub fn popup_area(frame_area: Rect, message: &str, base_y: u16, elapsed_ms: u128) -> Option<Rect> {
use super::word_wrap_size;
@@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// modal editor for launcher-wide settings.
use crossterm::event::{KeyCode, KeyEvent};
use ratatui::{
Frame,
@@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// rendering for the modpack import wizard. same pattern as new_instance:
// snapshot the state, pick the right step renderer, done.
use super::super::LoadState;
use super::super::base::PopupFrame;
use super::state::{DISCOVERY_STATE, IMPORT_STATE, ImportStep, ImportWizardState};
@@ -1,10 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// state machine for the modpack import wizard.
// browses modpacks from configured providers and keeps the archive import flow
// for modrinth URLs, project slugs, version IDs, and local pack archives.
use super::super::LoadState;
use crate::instance::import::{ImportInput, ImportSummary, parse_import_input};
use crate::net::modrinth::{self, VersionInfo};
@@ -387,7 +383,6 @@ fn handle_confirm_key(
}
}
// pushes an error toast and rewinds the wizard to a previous step
fn update_current_request(
state_arc: &Arc<Mutex<ImportWizardState>>,
request_id: u64,
@@ -419,8 +414,6 @@ fn begin_import_request(state: &mut ImportWizardState) -> u64 {
request_id
}
// parses user input to figure out what they gave us, then dispatches
// to the appropriate resolve path (slug lookup, direct version, or local file)
fn start_resolve(state: &mut ImportWizardState) {
let input_text = state.input.clone();
state.step = ImportStep::Fetching;
@@ -559,8 +552,6 @@ fn resolve_local_file(state_arc: Arc<Mutex<ImportWizardState>>, request_id: u64,
}
}
// user picked a version from the list. download the .mrpack,
// build a summary, and move to confirm.
fn start_version_download(state: &mut ImportWizardState) {
let version = match selected_version(state) {
Some(v) => v.clone(),
@@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// modal editor for settings belonging to the selected Minecraft instance.
use crossterm::event::{KeyCode, KeyEvent};
use ratatui::{
Frame,
-5
View File
@@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// shared utilities for popup widgets: layout helpers, word wrapping, keybind rendering.
// individual popup types live in their own submodules.
pub mod base;
pub mod confirm;
pub mod error;
@@ -41,8 +38,6 @@ pub(crate) fn compare_game_versions(a: &str, b: &str) -> std::cmp::Ordering {
a_parts.len().cmp(&b_parts.len())
}
// figures out the (width, height) a text block will need after word wrapping.
// used to size popups before rendering so they fit their content snugly.
pub fn word_wrap_size(text: &str, max_inner_width: usize) -> (usize, usize) {
if text.is_empty() || max_inner_width == 0 {
return (0, 1);
@@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// rendering for the new instance wizard. each step gets its own render fn
// and the popup resizes itself based on which step is active.
use super::super::LoadState;
use super::state::{
WIZARD_STATE, WizardState, WizardStep, clamp_loader_version_index, clamp_version_index,
@@ -33,7 +30,6 @@ pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
clamp_version_index(&mut state);
}
// vanilla has no loader version, so skip straight to confirm
if state.step == WizardStep::LoaderVersion {
if state.selected_loader() == ModLoader::Vanilla {
state.step = WizardStep::Confirm;
@@ -141,7 +137,6 @@ fn step_keybinds(state: &WizardState) -> ratatui::text::Line<'static> {
fn render_name_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
let theme = THEME.as_ref();
let value = state.name_state.value();
// \u{2588} is the full block char used as a fake blinking cursor
let line = if value.is_empty() {
Line::from(vec![
Span::styled("Instance name...", Style::default().fg(theme.text_dim())),
+3 -14
View File
@@ -1,10 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// state machine and input handling for the new instance wizard.
// flow: Name -> Loader -> Version -> LoaderVersion -> Confirm
// version lists are fetched lazily from the network when you reach that step.
use crate::instance::{loader::GameVersion, models::ModLoader};
use crate::tui::widgets::instances;
use crossterm::event::{KeyCode, KeyEvent};
@@ -16,7 +12,6 @@ use super::super::LoadState;
pub(crate) static WIZARD_STATE: LazyLock<Arc<Mutex<WizardState>>> =
LazyLock::new(|| Arc::new(Mutex::new(WizardState::default())));
// populated on confirm, consumed by the main event loop to actually create the instance
pub(crate) static WIZARD_RESULT: LazyLock<Arc<Mutex<Option<WizardParams>>>> =
LazyLock::new(|| Arc::new(Mutex::new(None)));
@@ -163,7 +158,6 @@ fn handle_version_key(
key_event: &KeyEvent,
instances_state: &mut instances::State,
) {
// Search mode: route char input to search query
if state.version_search.active {
match key_event.code {
KeyCode::Esc => {
@@ -176,12 +170,8 @@ fn handle_version_key(
clamp_version_index(state);
return;
}
KeyCode::Char('j') | KeyCode::Down => {
// fall through to navigation below
}
KeyCode::Char('k') | KeyCode::Up => {
// fall through to navigation below
}
KeyCode::Char('j') | KeyCode::Down => {}
KeyCode::Char('k') | KeyCode::Up => {}
KeyCode::Char(c) => {
state.version_search.push(c);
state.version_idx = 0; // reset to top of filtered list
@@ -384,8 +374,7 @@ pub(crate) fn clamp_loader_version_index(state: &mut WizardState) {
}
}
// only fires on the Idle -> Loading transition to avoid spamming requests.
// the spawned task writes results back into WIZARD_STATE when done.
// Spawn only on Idle -> Loading to avoid repeating network requests per frame.
pub(crate) fn ensure_versions_loaded(state: &mut WizardState) {
if !matches!(state.versions, LoadState::Idle) {
return;
-2
View File
@@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// Shared selection list used by the new-instance wizard and settings pickers.
use ratatui::{
buffer::Buffer,
layout::Rect,
@@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// Reusable interactive controls shared by instance and launcher settings.
use std::{
collections::{BTreeMap, BTreeSet},
path::{Path, PathBuf},
-2
View File
@@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// shared network loading for Minecraft and mod-loader version pickers.
use crate::instance::{
loader::{GameVersion, get_installer},
models::ModLoader,
+1 -9
View File
@@ -1,10 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// responsive grid of screenshot thumbnails rendered directly in the terminal.
// images load lazily on background threads as they scroll into view,
// and get converted to terminal graphics via ratatui-image protocols.
use std::collections::{HashMap, HashSet};
use std::path::Path;
use std::sync::{Arc, Mutex};
@@ -23,8 +19,6 @@ use unicode_segmentation::UnicodeSegmentation;
use crate::config::theme::THEME;
use crate::instance::screenshots::ScreenshotEntry;
// grid cell sizing constraints in terminal columns.
// the grid auto-fits columns within these bounds depending on terminal width
const TARGET_CELL_WIDTH: u16 = 34;
const MIN_CELL_WIDTH: u16 = 24;
const MAX_CELL_WIDTH: u16 = 52;
@@ -373,9 +367,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
let cols = target_cols.clamp(min_cols, max_cols);
let cell_width = area.width / cols as u16;
// figure out how tall each thumbnail should be in terminal rows.
// need the font's pixel aspect ratio to keep screenshots from
// looking stretched since terminal cells aren't square
// Terminal cells are not square; use the font's aspect ratio to avoid stretching.
let (img_w, img_h) = state
.entries
.first()
-6
View File
@@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// reusable incremental search state used across multiple widgets.
// handles case-insensitive filtering and inline match highlighting.
use crossterm::event::KeyModifiers;
use ratatui::{
style::{Modifier, Style},
@@ -53,8 +50,6 @@ impl SearchState {
text.to_lowercase().contains(&self.query.to_lowercase())
}
// splits text into spans, bolding+underlining the parts that match
// the query so every searchable widget can use the same styling
pub fn highlight_spans(&self, text: &str, base_style: Style) -> Vec<Span<'static>> {
if self.query.is_empty() {
return vec![Span::styled(text.to_owned(), base_style)];
@@ -94,7 +89,6 @@ impl SearchState {
Line::from(self.highlight_spans(text, base_style))
}
// renders the "/ query█" indicator in the block title bar
pub fn title_line(&self) -> Option<Line<'static>> {
if !self.active && self.query.is_empty() {
return None;
-3
View File
@@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// settings panel: manages config profiles and shows compact instance info.
// detailed instance and launcher configuration opens in the TUI popups.
use std::path::{Path, PathBuf};
use crossterm::event::{KeyCode, KeyEvent};
-3
View File
@@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// the "overview" panel showing download/install progress.
// shows a gauge when the total is known, or a spinner when it's not.
use ratatui::{
Frame,
layout::{Constraint, Layout, Rect},