merge: resolve conflicts keeping streaming load and notify watcher

This commit is contained in:
objz committed 2026-04-25 15:23:49 +02:00
commit 82665bd4e6
50 files changed
+592 -345

No files matched your search

+23 -32
View File
@@ -6,17 +6,17 @@ use std::sync::{Arc, Mutex};
use crossterm::event::{KeyCode, KeyEvent};
use ratatui::{
Frame,
layout::Rect,
style::{Modifier, Style},
text::{Line, Span},
widgets::{Block, Borders, Paragraph, Widget},
Frame,
};
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
use crate::auth::{self, AccountStore, AccountType, AuthResult, DeviceCodeInfo};
use crate::config::theme::{BORDER_STYLE, THEME};
use crate::tui::app::FocusedArea;
use crate::config::theme::{THEME, BORDER_STYLE};
use super::styled_title;
@@ -59,11 +59,10 @@ impl AccountState {
// can't block on it because the TUI needs to keep rendering
pub fn drain_auth_result(&mut self) {
if let AddMode::DeviceCodeWaiting { pending, .. } = &self.add_mode {
let result = match pending.lock() { Ok(mut slot) => {
slot.take()
} _ => {
None
}};
let result = match pending.lock() {
Ok(mut slot) => slot.take(),
_ => None,
};
if let Some(result) = result {
match result {
@@ -210,11 +209,12 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut AccountState) -> bool {
pub fn drain_device_code(state: &mut AccountState) {
if let AddMode::DeviceCodeWaiting { info, .. } = &mut state.add_mode
&& info.user_code.is_empty()
&& let Ok(mut slot) = auth::DEVICE_CODE_DISPLAY.lock()
&& let Some(dc_info) = slot.take() {
info.user_code = dc_info.user_code;
info.verification_uri = dc_info.verification_uri;
}
&& let Ok(mut slot) = auth::DEVICE_CODE_DISPLAY.lock()
&& let Some(dc_info) = slot.take()
{
info.user_code = dc_info.user_code;
info.verification_uri = dc_info.verification_uri;
}
}
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut AccountState) {
@@ -246,8 +246,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut A
if state.store.accounts.is_empty() {
frame.render_widget(
Paragraph::new("No accounts.")
.style(Style::default().fg(theme.text_dim())),
Paragraph::new("No accounts.").style(Style::default().fg(theme.text_dim())),
inner,
);
} else {
@@ -299,7 +298,9 @@ fn render_account_list(
let active_marker = if *is_active { "\u{25b8} " } else { " " };
let style = if show_selected {
Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD)
Style::default()
.fg(theme.accent())
.add_modifier(Modifier::BOLD)
} else if *is_active {
Style::default()
.fg(theme.text())
@@ -315,7 +316,9 @@ fn render_account_list(
if *acc_type == AccountType::Offline {
let offline_style = if show_selected {
Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD)
Style::default()
.fg(theme.accent())
.add_modifier(Modifier::BOLD)
} else {
Style::default().fg(theme.text_dim())
};
@@ -372,10 +375,7 @@ fn render_choose_popup(frame: &mut Frame) {
.fg(accent_color)
.add_modifier(Modifier::BOLD),
),
Span::styled(
"Microsoft Account",
Style::default().fg(text_color),
),
Span::styled("Microsoft Account", Style::default().fg(text_color)),
]),
Line::from(vec![
Span::styled(
@@ -384,10 +384,7 @@ fn render_choose_popup(frame: &mut Frame) {
.fg(accent_color)
.add_modifier(Modifier::BOLD),
),
Span::styled(
"Offline Account",
Style::default().fg(text_color),
),
Span::styled("Offline Account", Style::default().fg(text_color)),
]),
];
Paragraph::new(text).render(inner, buf);
@@ -422,10 +419,7 @@ fn render_offline_popup(frame: &mut Frame, name: &str) {
content: Box::new(move |inner, buf| {
let line = if name.is_empty() {
Line::from(vec![
Span::styled(
"Username...",
Style::default().fg(dim_color),
),
Span::styled("Username...", Style::default().fg(dim_color)),
Span::styled(
"\u{2588}",
Style::default()
@@ -534,10 +528,7 @@ fn render_device_code_popup(frame: &mut Frame, info: &DeviceCodeInfo) {
)),
Line::from(""),
Line::from(vec![
Span::styled(
"Enter code: ",
Style::default().fg(dim_color),
),
Span::styled("Enter code: ", Style::default().fg(dim_color)),
Span::styled(
code.as_str(),
Style::default()
+1 -1
View File
@@ -3,5 +3,5 @@
pub mod list;
pub mod tabs;
pub use tabs::{ContentTab, render, title};
pub use list::{ContentListState, handle_key, handle_key_no_toggle};
pub use tabs::{ContentTab, render, title};
+17 -7
View File
@@ -3,16 +3,16 @@
// also renders the instance name/version header with run state indicators.
use ratatui::{
Frame,
layout::{Alignment, Constraint, Layout, Rect},
style::{Modifier, Style},
text::{Line, Span},
widgets::{Block, Borders, Paragraph},
Frame,
};
use throbber_widgets_tui::{Throbber, ThrobberState};
use crate::config::theme::{BORDER_STYLE, THEME};
use crate::tui::app::FocusedArea;
use crate::config::theme::{THEME, BORDER_STYLE};
use crate::tui::widgets::styled_title;
@@ -200,7 +200,8 @@ pub fn render(
};
if let Some(kb) = kb {
let lines = crate::tui::widgets::popups::keybind_lines_wrapped(kb, area.width.saturating_sub(2));
let lines =
crate::tui::widgets::popups::keybind_lines_wrapped(kb, area.width.saturating_sub(2));
for line in lines {
block = block.title_bottom(line);
}
@@ -285,7 +286,12 @@ pub fn render(
if logs_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
logs_state.start_load(instances_dir, &instance.name);
}
crate::tui::widgets::logs_viewer::render(frame, content_area, logs_state, is_focused);
crate::tui::widgets::logs_viewer::render(
frame,
content_area,
logs_state,
is_focused,
);
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
@@ -299,7 +305,12 @@ pub fn render(
if screenshots_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
screenshots_state.start_load(instances_dir, &instance.name);
}
crate::tui::widgets::screenshots_grid::render(frame, content_area, screenshots_state, is_focused);
crate::tui::widgets::screenshots_grid::render(
frame,
content_area,
screenshots_state,
is_focused,
);
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
@@ -362,8 +373,7 @@ pub fn title(
match instance {
None => {
frame.render_widget(
Paragraph::new("No instance selected")
.style(Style::default().fg(theme.text_dim())),
Paragraph::new("No instance selected").style(Style::default().fg(theme.text_dim())),
inner,
);
}
+3 -4
View File
@@ -2,16 +2,16 @@
// and provides keybinds to open config files in $EDITOR
use ratatui::{
Frame,
layout::Rect,
style::{Modifier, Style},
text::{Line, Span},
widgets::{Block, Borders, Paragraph},
Frame,
};
use crate::config::theme::{BORDER_STYLE, THEME};
use crate::instance::models::InstanceConfig;
use crate::tui::app::FocusedArea;
use crate::config::theme::{THEME, BORDER_STYLE};
use super::styled_title;
@@ -54,8 +54,7 @@ pub fn render(
let Some(inst) = instance else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(theme.text_dim())),
Paragraph::new("No instance selected.").style(Style::default().fg(theme.text_dim())),
inner,
);
return;
+14 -10
View File
@@ -2,22 +2,22 @@
// handles search/filter, scrollbar sync, and inline renaming.
// each row shows instance name + "last played" or current run state.
use crate::config::theme::{THEME, BORDER_STYLE};
use crate::config::theme::{BORDER_STYLE, THEME};
use crossterm::event::KeyCode;
use ratatui::{
Frame,
layout::Rect,
style::{Modifier, Style},
text::{Line, Span, Text},
widgets::{Block, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState},
Frame,
};
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
use crate::instance::models::InstanceConfig;
use crate::running::{get as get_run_state, RunState};
use crate::running::{RunState, get as get_run_state};
use crate::tui::app::FocusedArea;
use super::{search::SearchState, styled_title, WidgetKey};
use super::{WidgetKey, search::SearchState, styled_title};
// rough human-friendly time delta. not trying to be precise here,
// "2 months ago" is close enough when months are ~30 days
@@ -255,7 +255,9 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
let (name_style, meta_style, bg) = if context.is_selected {
(
Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD),
Style::default()
.fg(theme.accent())
.add_modifier(Modifier::BOLD),
Style::default().fg(theme.text_dim()),
stripe_bg,
)
@@ -300,14 +302,16 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
"Authenticating".to_string(),
Style::default().fg(theme.success()),
),
Some(RunState::Running) | Some(RunState::Starting) => (
"Playing".to_string(),
Style::default().fg(theme.success()),
),
Some(RunState::Running) | Some(RunState::Starting) => {
("Playing".to_string(), Style::default().fg(theme.success()))
}
_ => (format_last_played(instance.last_played), meta_style),
};
let meta_line = Line::from(vec![selector.clone(), Span::styled(meta_text, meta_text_style)]);
let meta_line = Line::from(vec![
selector.clone(),
Span::styled(meta_text, meta_text_style),
]);
let item = Text::from(vec![name_line, meta_line]).style(Style::default().bg(bg));
(item, 2)
+34 -25
View File
@@ -8,16 +8,16 @@ use std::sync::{Arc, Mutex};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use ratatui::{
Frame,
layout::{Constraint, Layout, Rect},
style::{Modifier, Style},
text::{Line, Span},
widgets::{Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
Frame,
};
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
use crate::instance::log_files::{read_log_file, scan_log_files, LogFileEntry};
use crate::config::theme::{THEME, BORDER_STYLE};
use crate::config::theme::{BORDER_STYLE, THEME};
use crate::instance::log_files::{LogFileEntry, read_log_file, scan_log_files};
type PendingLogs = Arc<Mutex<Option<(String, Vec<LogFileEntry>)>>>;
@@ -94,29 +94,31 @@ impl LogsState {
}
pub fn drain_pending(&mut self) {
let taken = match self.pending.lock() { Ok(mut slot) => {
slot.take()
} _ => {
None
}};
let taken = match self.pending.lock() {
Ok(mut slot) => slot.take(),
_ => None,
};
if let Some((instance_name, entries)) = taken
&& self.loaded_for.as_deref() == Some(&instance_name) {
let prev_selected = self.list_state.selected;
self.entries = entries;
self.loading = false;
&& self.loaded_for.as_deref() == Some(&instance_name)
{
let prev_selected = self.list_state.selected;
self.entries = entries;
self.loading = false;
let display_count = self.display_count();
let display_count = self.display_count();
if display_count > 0 && prev_selected.is_none() {
self.list_state.selected = Some(0);
self.load_selected_content();
} else if let Some(sel) = prev_selected
&& sel >= display_count && display_count > 0 {
self.list_state.selected = Some(display_count - 1);
}
self.update_scrollbar();
if display_count > 0 && prev_selected.is_none() {
self.list_state.selected = Some(0);
self.load_selected_content();
} else if let Some(sel) = prev_selected
&& sel >= display_count
&& display_count > 0
{
self.list_state.selected = Some(display_count - 1);
}
self.update_scrollbar();
}
}
// periodically re-scan log files in case new ones appeared while playing.
@@ -430,11 +432,15 @@ fn render_list(
let show_selected = list_focused && context.is_selected;
let style = if *is_live && show_selected {
Style::default().fg(theme.success()).add_modifier(Modifier::BOLD)
Style::default()
.fg(theme.success())
.add_modifier(Modifier::BOLD)
} else if *is_live {
Style::default().fg(theme.success())
} else if show_selected {
Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD)
Style::default()
.fg(theme.accent())
.add_modifier(Modifier::BOLD)
} else {
Style::default().fg(theme.text())
};
@@ -450,8 +456,11 @@ fn render_list(
} else {
Span::raw(" ")
};
let item = ratatui::text::Text::from(Line::from(vec![selector, Span::styled(name.clone(), style)]))
.style(Style::default().bg(bg));
let item = ratatui::text::Text::from(Line::from(vec![
selector,
Span::styled(name.clone(), style),
]))
.style(Style::default().bg(bg));
(item, 1)
});
+1 -1
View File
@@ -10,9 +10,9 @@ use ratatui::{
pub mod account;
pub mod content;
pub mod details;
pub mod instances;
pub mod logs_viewer;
pub mod popups;
pub mod instances;
pub mod screenshots_grid;
pub mod search;
pub mod status;
+2 -1
View File
@@ -14,7 +14,8 @@ use ratatui::{
use crate::config::theme::THEME;
static CONFIRM_STATE: LazyLock<Mutex<ConfirmState>> = LazyLock::new(|| Mutex::new(ConfirmState::default()));
static CONFIRM_STATE: LazyLock<Mutex<ConfirmState>> =
LazyLock::new(|| Mutex::new(ConfirmState::default()));
#[derive(Debug, Default)]
struct ConfirmState {
+1 -1
View File
@@ -12,8 +12,8 @@ use tracing::Level;
use super::base::PopupFrame;
use crate::config::SETTINGS;
use crate::tui::error_buffer::ErrorEvent;
use crate::config::theme::THEME;
use crate::tui::error_buffer::ErrorEvent;
pub struct ErrorPopup {
pub event: ErrorEvent,
+1 -1
View File
@@ -2,4 +2,4 @@ mod render;
mod state;
pub use render::{popup_rect, render};
pub use state::{handle_key, take_result, ImportResult, ImportStep, ImportWizardState};
pub use state::{ImportResult, ImportStep, ImportWizardState, handle_key, take_result};
+10 -27
View File
@@ -3,15 +3,15 @@
use super::super::base::PopupFrame;
use super::super::new_instance::LoadState;
use super::state::{ImportStep, ImportWizardState, IMPORT_STATE};
use crate::tui::app::FocusedArea;
use super::state::{IMPORT_STATE, ImportStep, ImportWizardState};
use crate::config::theme::THEME;
use crate::tui::app::FocusedArea;
use ratatui::{
Frame,
layout::{Constraint, Direction, Layout, Rect},
style::{Modifier, Style},
text::{Line, Span},
widgets::{List, ListItem, ListState, Paragraph, StatefulWidget, Widget, Wrap},
Frame,
};
pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
@@ -85,11 +85,7 @@ pub fn popup_rect(frame_area: Rect) -> Rect {
}
}
fn render_input_step(
state: &ImportWizardState,
area: Rect,
buf: &mut ratatui::buffer::Buffer,
) {
fn render_input_step(state: &ImportWizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
let theme = THEME.as_ref();
let chunks = Layout::default()
.direction(Direction::Vertical)
@@ -115,10 +111,7 @@ fn render_input_step(
])
} else {
Line::from(vec![
Span::styled(
state.input.clone(),
Style::default().fg(theme.text()),
),
Span::styled(state.input.clone(), Style::default().fg(theme.text())),
Span::styled(
"\u{2588}",
Style::default()
@@ -137,11 +130,7 @@ fn render_fetching_step(area: Rect, buf: &mut ratatui::buffer::Buffer) {
.render(area, buf);
}
fn render_version_step(
state: &ImportWizardState,
area: Rect,
buf: &mut ratatui::buffer::Buffer,
) {
fn render_version_step(state: &ImportWizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
let theme = THEME.as_ref();
match &state.versions {
LoadState::Idle | LoadState::Loading => {
@@ -182,11 +171,7 @@ fn render_version_step(
}
}
fn render_confirm_step(
state: &ImportWizardState,
area: Rect,
buf: &mut ratatui::buffer::Buffer,
) {
fn render_confirm_step(state: &ImportWizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
let theme = THEME.as_ref();
let summary = match &state.summary {
Some(s) => s,
@@ -247,11 +232,9 @@ fn step_keybinds(state: &ImportWizardState) -> Line<'static> {
match state.step {
ImportStep::Input => keybind_line(&[("Enter", " fetch")]),
ImportStep::Fetching => keybind_line(&[("Esc", " cancel")]),
ImportStep::Version => keybind_line(&[
("/", " search"),
("h", " back"),
("Enter", " select"),
]),
ImportStep::Version => {
keybind_line(&[("/", " search"), ("h", " back"), ("Enter", " select")])
}
ImportStep::Confirm => keybind_line(&[("h", " back"), ("Enter", " import")]),
}
}
+23 -27
View File
@@ -4,7 +4,7 @@
// local files skip straight to the confirm step.
use super::super::new_instance::LoadState;
use crate::instance::import::{parse_import_input, ImportInput, ImportSummary};
use crate::instance::import::{ImportInput, ImportSummary, parse_import_input};
use crate::net::modrinth::{self, VersionInfo};
use crate::tui::widgets::instances;
use crate::tui::widgets::search::SearchState;
@@ -309,21 +309,19 @@ async fn resolve_version_id(
}
match modrinth::download_mrpack(client, &version, &tmp_dir).await {
Ok(mrpack_path) => {
match crate::instance::import::build_summary(&mrpack_path) {
Ok(summary) => {
if let Ok(mut s) = state_arc.lock() {
s.summary = Some(summary);
s.step = ImportStep::Confirm;
}
Ok(mrpack_path) => match crate::instance::import::build_summary(&mrpack_path) {
Ok(summary) => {
if let Ok(mut s) = state_arc.lock() {
s.summary = Some(summary);
s.step = ImportStep::Confirm;
}
Err(e) => set_error_and_back(
&state_arc,
format!("Failed to build summary: {}", e),
ImportStep::Input,
),
}
}
Err(e) => set_error_and_back(
&state_arc,
format!("Failed to build summary: {}", e),
ImportStep::Input,
),
},
Err(e) => set_error_and_back(
&state_arc,
format!("Failed to download mrpack: {}", e),
@@ -383,21 +381,19 @@ fn start_version_download(state: &mut ImportWizardState) {
}
match modrinth::download_mrpack(&client, &version, &tmp_dir).await {
Ok(mrpack_path) => {
match crate::instance::import::build_summary(&mrpack_path) {
Ok(summary) => {
if let Ok(mut s) = state_arc.lock() {
s.summary = Some(summary);
s.step = ImportStep::Confirm;
}
Ok(mrpack_path) => match crate::instance::import::build_summary(&mrpack_path) {
Ok(summary) => {
if let Ok(mut s) = state_arc.lock() {
s.summary = Some(summary);
s.step = ImportStep::Confirm;
}
Err(e) => set_error_and_back(
&state_arc,
format!("Failed to build summary: {}", e),
ImportStep::Version,
),
}
}
Err(e) => set_error_and_back(
&state_arc,
format!("Failed to build summary: {}", e),
ImportStep::Version,
),
},
Err(e) => set_error_and_back(
&state_arc,
format!("Failed to download mrpack: {}", e),
+1 -1
View File
@@ -2,4 +2,4 @@ mod render;
mod state;
pub use render::{popup_rect, render};
pub use state::{handle_key, take_result, LoadState, WizardParams, WizardStep, WizardState};
pub use state::{LoadState, WizardParams, WizardState, WizardStep, handle_key, take_result};
@@ -2,21 +2,21 @@
// and the popup resizes itself based on which step is active.
use super::state::{
clamp_loader_version_index, clamp_version_index, ensure_loader_versions_loaded,
ensure_versions_loaded, visible_versions, LoadState, WizardState, WizardStep, WIZARD_STATE,
LoadState, WIZARD_STATE, WizardState, WizardStep, clamp_loader_version_index,
clamp_version_index, ensure_loader_versions_loaded, ensure_versions_loaded, visible_versions,
};
use crate::config::theme::THEME;
use crate::instance::models::ModLoader;
use crate::tui::app::FocusedArea;
use crate::config::theme::THEME;
use crate::tui::widgets::popups::base::PopupFrame;
use tui_prompts::State as PromptState;
use ratatui::{
Frame,
layout::{Constraint, Direction, Layout, Rect},
style::{Modifier, Style},
text::{Line, Span},
widgets::{List, ListItem, ListState, Paragraph, StatefulWidget, Widget, Wrap},
Frame,
};
use tui_prompts::State as PromptState;
pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
// grab the lock, kick off any lazy-loading, then clone and release.
@@ -140,10 +140,7 @@ fn render_name_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::
// \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()),
),
Span::styled("Instance name...", Style::default().fg(theme.text_dim())),
Span::styled(
"\u{2588}",
Style::default()
+32 -32
View File
@@ -8,16 +8,16 @@ use std::sync::{Arc, Mutex};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use ratatui::{
Frame,
layout::{Constraint, Layout, Rect},
style::{Modifier, Style},
text::Span,
widgets::{Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
Frame,
};
use ratatui_image::{protocol::StatefulProtocol, Resize, StatefulImage};
use ratatui_image::{Resize, StatefulImage, protocol::StatefulProtocol};
use crate::instance::screenshots::ScreenshotEntry;
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
@@ -97,27 +97,26 @@ impl ScreenshotsState {
}
pub fn drain_pending_entries(&mut self) {
let taken = match self.pending_entries.lock() { Ok(mut slot) => {
slot.take()
} _ => {
None
}};
let taken = match self.pending_entries.lock() {
Ok(mut slot) => slot.take(),
_ => None,
};
if let Some((instance_name, entries)) = taken
&& self.loaded_for.as_deref() == Some(&instance_name) {
self.entries = entries;
self.loading = false;
self.selected = 0;
self.scroll_row = 0;
}
&& self.loaded_for.as_deref() == Some(&instance_name)
{
self.entries = entries;
self.loading = false;
self.selected = 0;
self.scroll_row = 0;
}
}
pub fn take_pending_images(&mut self) -> Vec<(usize, image::DynamicImage)> {
match self.pending_images.lock() { Ok(mut slot) => {
std::mem::take(&mut *slot)
} _ => {
Vec::new()
}}
match self.pending_images.lock() {
Ok(mut slot) => std::mem::take(&mut *slot),
_ => Vec::new(),
}
}
pub fn set_protocol(&mut self, idx: usize, proto: StatefulProtocol) {
@@ -146,9 +145,10 @@ impl ScreenshotsState {
.unwrap_or(None);
if let Some(img) = img
&& let Ok(mut slot) = pending.lock() {
slot.push((idx, img));
}
&& let Ok(mut slot) = pending.lock()
{
slot.push((idx, img));
}
});
}
}
@@ -229,16 +229,18 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
KeyCode::Enter if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
if let Some(entry) = state.entries.get(state.selected)
&& let Some(dir) = entry.path.parent()
&& let Err(e) = open::that(dir) {
tracing::error!("Failed to open directory: {}", e);
}
&& let Err(e) = open::that(dir)
{
tracing::error!("Failed to open directory: {}", e);
}
true
}
KeyCode::Enter => {
if let Some(entry) = state.entries.get(state.selected)
&& let Err(e) = open::that(&entry.path) {
tracing::error!("Failed to open file: {}", e);
}
&& let Err(e) = open::that(&entry.path)
{
tracing::error!("Failed to open file: {}", e);
}
true
}
KeyCode::Char('L') | KeyCode::Right
@@ -276,8 +278,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
let theme = THEME.as_ref();
if state.loading {
frame.render_widget(
Paragraph::new("Loading screenshots...")
.style(Style::default().fg(theme.text_dim())),
Paragraph::new("Loading screenshots...").style(Style::default().fg(theme.text_dim())),
area,
);
return;
@@ -285,8 +286,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
if state.entries.is_empty() {
frame.render_widget(
Paragraph::new("No screenshots.")
.style(Style::default().fg(theme.text_dim())),
Paragraph::new("No screenshots.").style(Style::default().fg(theme.text_dim())),
area,
);
return;
+44
View File
@@ -109,3 +109,47 @@ impl SearchState {
Some(Line::from(spans).right_aligned())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn confirm_keeps_query_but_deactivates() {
let mut s = SearchState::default();
s.activate();
s.push('a');
s.push('b');
s.confirm();
assert!(!s.active);
assert_eq!(s.query, "ab");
// filter should still match
assert!(s.matches("abc"));
assert!(!s.matches("xyz"));
}
#[test]
fn deactivate_clears_query() {
let mut s = SearchState::default();
s.activate();
s.push('x');
s.deactivate();
assert!(!s.active);
assert!(s.query.is_empty());
// with empty query, everything matches
assert!(s.matches("anything"));
}
#[test]
fn confirm_then_reactivate_preserves_query() {
let mut s = SearchState::default();
s.activate();
s.push('t');
s.push('e');
s.confirm();
// user presses search key again to edit
s.activate();
assert!(s.active);
assert_eq!(s.query, "te");
}
}
+6 -12
View File
@@ -2,17 +2,17 @@
// shows a gauge when the total is known, or a spinner when it's not.
use ratatui::{
Frame,
layout::{Constraint, Layout, Rect},
style::{Modifier, Style},
text::Span,
widgets::{Block, Borders, Gauge, Paragraph},
Frame,
};
use throbber_widgets_tui::{Throbber, ThrobberState};
use crate::config::theme::{BORDER_STYLE, THEME};
use crate::tui::app::FocusedArea;
use crate::tui::progress::PROGRESS;
use crate::config::theme::{THEME, BORDER_STYLE};
use super::styled_title;
@@ -39,11 +39,8 @@ pub fn render(
Ok(s) => s.clone(),
Err(_) => {
frame.render_widget(
Paragraph::new(Span::styled(
"Ready",
Style::default().fg(theme.text_dim()),
))
.block(block),
Paragraph::new(Span::styled("Ready", Style::default().fg(theme.text_dim())))
.block(block),
area,
);
return;
@@ -52,11 +49,8 @@ pub fn render(
if state.current_action.is_none() {
frame.render_widget(
Paragraph::new(Span::styled(
"Ready",
Style::default().fg(theme.text_dim()),
))
.block(block),
Paragraph::new(Span::styled("Ready", Style::default().fg(theme.text_dim())))
.block(block),
area,
);
return;