working blocked constant redraws

This commit is contained in:
filipriec
2025-04-18 21:43:54 +02:00
parent a0467d17a8
commit f357d6f0ee

View File

@@ -63,6 +63,7 @@ pub async fn run_ui() -> Result<()> {
// --- FPS Calculation State ---
let mut last_frame_time = Instant::now();
let mut current_fps = 0.0;
let mut needs_redraw = true;
loop {
// --- Synchronize UI View from Active Buffer ---
@@ -96,29 +97,32 @@ pub async fn run_ui() -> Result<()> {
// Draw the current state *first*. This ensures the loading dialog
// set in the *previous* iteration gets rendered before the pending
// action check below.
terminal.draw(|f| {
render_ui(
f,
&mut form_state,
&mut auth_state,
&login_state,
&register_state,
&intro_state,
&mut admin_state,
&buffer_state,
&theme,
event_handler.is_edit_mode, // Use event_handler's state
&event_handler.highlight_state,
app_state.total_count,
app_state.current_position,
&app_state.current_dir,
&event_handler.command_input,
event_handler.command_mode,
&event_handler.command_message,
current_fps,
&app_state,
);
}).context("Terminal draw call failed")?;
if needs_redraw {
terminal.draw(|f| {
render_ui(
f,
&mut form_state,
&mut auth_state,
&login_state,
&register_state,
&intro_state,
&mut admin_state,
&buffer_state,
&theme,
event_handler.is_edit_mode, // Use event_handler's state
&event_handler.highlight_state,
app_state.total_count,
app_state.current_position,
&app_state.current_dir,
&event_handler.command_input,
event_handler.command_mode,
&event_handler.command_message,
current_fps,
&app_state,
);
}).context("Terminal draw call failed")?;
needs_redraw = false;
}
// --- Cursor Visibility Logic ---
// (Keep existing cursor logic here - depends on state drawn above)
@@ -167,6 +171,7 @@ pub async fn run_ui() -> Result<()> {
&mut current_position,
)
.await;
needs_redraw = true;
}
// Update position based on handler's modification
@@ -222,6 +227,7 @@ pub async fn run_ui() -> Result<()> {
login_state.password.clear();
login_state.set_has_unsaved_changes(false);
login_state.current_cursor_pos = 0;
needs_redraw = true;
}
Err(mpsc::error::TryRecvError::Empty) => { /* No message waiting */ }
Err(mpsc::error::TryRecvError::Disconnected) => {
@@ -275,6 +281,7 @@ pub async fn run_ui() -> Result<()> {
// --- Position Change Handling (after outcome processing and pending actions) ---
let position_changed = app_state.current_position != position_before_event;
let current_total_count = app_state.total_count;
let mut position_logic_needs_redraw = false;
if app_state.ui.show_form {
if position_changed && !event_handler.is_edit_mode {
let current_input = form_state.get_current_input();
@@ -285,6 +292,7 @@ pub async fn run_ui() -> Result<()> {
};
form_state.current_cursor_pos =
event_handler.ideal_cursor_column.min(max_cursor_pos);
position_logic_needs_redraw = true;
// Ensure position never exceeds total_count + 1
if app_state.current_position > current_total_count + 1 {
@@ -353,6 +361,7 @@ pub async fn run_ui() -> Result<()> {
0
};
register_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
position_logic_needs_redraw = true;
}
} else if app_state.ui.show_login {
if !event_handler.is_edit_mode {
@@ -363,8 +372,12 @@ pub async fn run_ui() -> Result<()> {
0
};
login_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
position_logic_needs_redraw = true;
}
}
if position_logic_needs_redraw {
needs_redraw = true;
}
// --- End Position Change Handling ---
// Check exit condition *after* all processing for the iteration