fix(tui): remove source step, add keybind hints

This commit is contained in:
objz committed 2026-03-15 15:24:18 +01:00
1 parent f0c0051a1f
commit dcadf1b1cc
2 files changed
+10 -61

No files matched your search

+3 -61
View File
@@ -30,7 +30,6 @@ pub struct ImportResult {
#[derive(Debug, Default, Clone, PartialEq)] #[derive(Debug, Default, Clone, PartialEq)]
pub enum ImportStep { pub enum ImportStep {
#[default] #[default]
Source,
Input, Input,
Fetching, Fetching,
Version, Version,
@@ -40,7 +39,6 @@ pub enum ImportStep {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ImportWizardState { pub struct ImportWizardState {
pub step: ImportStep, pub step: ImportStep,
pub source_idx: usize,
pub input: String, pub input: String,
pub error: Option<String>, pub error: Option<String>,
pub project_title: Option<String>, pub project_title: Option<String>,
@@ -53,8 +51,7 @@ pub struct ImportWizardState {
impl Default for ImportWizardState { impl Default for ImportWizardState {
fn default() -> Self { fn default() -> Self {
Self { Self {
step: ImportStep::Source, step: ImportStep::Input,
source_idx: 0,
input: String::new(), input: String::new(),
error: None, error: None,
project_title: None, project_title: None,
@@ -104,7 +101,6 @@ pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
.split(popup_area); .split(popup_area);
match snapshot.step { match snapshot.step {
ImportStep::Source => render_source_step(&snapshot, chunks[0], buf),
ImportStep::Input => render_input_step(&snapshot, chunks[0], buf), ImportStep::Input => render_input_step(&snapshot, chunks[0], buf),
ImportStep::Fetching => render_fetching_step(chunks[0], buf), ImportStep::Fetching => render_fetching_step(chunks[0], buf),
ImportStep::Version => render_version_step(&snapshot, chunks[0], buf), ImportStep::Version => render_version_step(&snapshot, chunks[0], buf),
@@ -120,14 +116,10 @@ pub fn popup_rect(frame_area: Rect) -> Rect {
let w = Constraint::Percentage(50); let w = Constraint::Percentage(50);
let step = match IMPORT_STATE.lock() { let step = match IMPORT_STATE.lock() {
Ok(s) => s.step.clone(), Ok(s) => s.step.clone(),
Err(_) => ImportStep::Source, Err(_) => ImportStep::Input,
}; };
match step { match step {
ImportStep::Source => {
let h = 5u16.min(frame_area.height.saturating_sub(4));
frame_area.centered(w, Constraint::Length(h))
}
ImportStep::Input => { ImportStep::Input => {
let h = 8u16.min(frame_area.height.saturating_sub(4)); let h = 8u16.min(frame_area.height.saturating_sub(4));
frame_area.centered(w, Constraint::Length(h)) frame_area.centered(w, Constraint::Length(h))
@@ -160,7 +152,6 @@ pub fn handle_key(key_event: &KeyEvent, profiles_state: &mut profiles::State) {
}; };
match state.step { match state.step {
ImportStep::Source => handle_source_key(&mut state, key_event, profiles_state),
ImportStep::Input => handle_input_key(&mut state, key_event, profiles_state), ImportStep::Input => handle_input_key(&mut state, key_event, profiles_state),
ImportStep::Fetching => handle_fetching_key(&mut state, key_event, profiles_state), ImportStep::Fetching => handle_fetching_key(&mut state, key_event, profiles_state),
ImportStep::Version => handle_version_key(&mut state, key_event, profiles_state), ImportStep::Version => handle_version_key(&mut state, key_event, profiles_state),
@@ -177,28 +168,6 @@ pub fn take_result() -> Option<ImportResult> {
// --- Step handlers --- // --- Step handlers ---
fn handle_source_key(
state: &mut ImportWizardState,
key_event: &KeyEvent,
profiles_state: &mut profiles::State,
) {
// Only one source for now (Modrinth), so j/k navigate but stay at 0
match key_event.code {
KeyCode::Esc => close_popup(state, profiles_state),
KeyCode::Char('j') | KeyCode::Down => {
// Only 1 source for now
state.source_idx = 0;
}
KeyCode::Char('k') | KeyCode::Up => {
state.source_idx = 0;
}
KeyCode::Enter => {
state.step = ImportStep::Input;
}
_ => {}
}
}
fn handle_input_key( fn handle_input_key(
state: &mut ImportWizardState, state: &mut ImportWizardState,
key_event: &KeyEvent, key_event: &KeyEvent,
@@ -206,10 +175,6 @@ fn handle_input_key(
) { ) {
match key_event.code { match key_event.code {
KeyCode::Esc => close_popup(state, profiles_state), KeyCode::Esc => close_popup(state, profiles_state),
KeyCode::Left | KeyCode::Char('h') if state.input.is_empty() => {
state.step = ImportStep::Source;
state.error = None;
}
KeyCode::Backspace => { KeyCode::Backspace => {
state.input.pop(); state.input.pop();
} }
@@ -557,28 +522,6 @@ fn start_version_download(state: &mut ImportWizardState) {
// --- Render helpers --- // --- Render helpers ---
fn render_source_step(
state: &ImportWizardState,
area: Rect,
buf: &mut ratatui::buffer::Buffer,
) {
let items: Vec<ListItem> = vec![ListItem::new(Line::from(Span::styled(
"Modrinth",
Style::default().fg(THEME.popup_new_instance.text_fg),
)))];
let list = List::new(items)
.highlight_style(
Style::default()
.fg(THEME.popup_new_instance.accent_fg)
.add_modifier(Modifier::BOLD),
)
.highlight_symbol("\u{25b6} ");
let mut list_state = ListState::default().with_selected(Some(state.source_idx));
StatefulWidget::render(list, area, buf, &mut list_state);
}
fn render_input_step( fn render_input_step(
state: &ImportWizardState, state: &ImportWizardState,
area: Rect, area: Rect,
@@ -759,8 +702,7 @@ fn wizard_title(_state: &ImportWizardState) -> Line<'static> {
fn step_keybinds(state: &ImportWizardState) -> Line<'static> { fn step_keybinds(state: &ImportWizardState) -> Line<'static> {
use super::keybind_line; use super::keybind_line;
match state.step { match state.step {
ImportStep::Source => keybind_line(&[("Enter", " select")]), ImportStep::Input => keybind_line(&[("Enter", " fetch")]),
ImportStep::Input => keybind_line(&[("h", " back"), ("Enter", " submit")]),
ImportStep::Fetching => keybind_line(&[("Esc", " cancel")]), ImportStep::Fetching => keybind_line(&[("Esc", " cancel")]),
ImportStep::Version => keybind_line(&[ ImportStep::Version => keybind_line(&[
("/", " search"), ("/", " search"),
+7
View File
@@ -208,8 +208,15 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
THEME.profiles.border_unfocused_fg THEME.profiles.border_unfocused_fg
}; };
let keybind_line = super::popups::keybind_line(&[
("a", " new"),
("i", " import"),
("d", " del"),
]);
let mut block = Block::default() let mut block = Block::default()
.title(styled_title("Profiles", true)) .title(styled_title("Profiles", true))
.title_bottom(keybind_line.right_aligned())
.borders(Borders::ALL) .borders(Borders::ALL)
.border_type(THEME.general.border_type.to_border_type()) .border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(color)); .border_style(Style::default().fg(color));