68 lines
2.2 KiB
Rust
68 lines
2.2 KiB
Rust
// src/client/ui/handlers/ui.rs
|
|
|
|
use crossterm::event::{Event, KeyCode, KeyModifiers};
|
|
use crate::client::terminal::AppTerminal;
|
|
use crate::client::components1::{render_command_line, render_form, render_preview_card, render_status_line};
|
|
use crate::client::colors::Theme;
|
|
use crate::client::config::Config;
|
|
use ratatui::layout::{Constraint, Direction, Layout};
|
|
use std::env;
|
|
use crate::proto::multieko2::PostAdresarRequest;
|
|
|
|
use super::form::FormState;
|
|
use super::event::EventHandler;
|
|
use super::render::render_ui;
|
|
use super::state::AppState;
|
|
|
|
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|
let config = Config::load()?;
|
|
let mut app_terminal = AppTerminal::new().await?;
|
|
let theme = Theme::dark();
|
|
|
|
let mut form_state = FormState::new();
|
|
let mut event_handler = EventHandler::new();
|
|
let mut app_state = AppState::new()?;
|
|
|
|
// Fetch the total count of Adresar entries
|
|
let total_count = app_terminal.get_adresar_count().await?;
|
|
app_state.update_total_count(total_count);
|
|
app_state.update_current_position(total_count + 1);
|
|
|
|
loop {
|
|
// Fetch fresh total count on each iteration
|
|
let total_count = app_terminal.get_adresar_count().await?;
|
|
app_state.update_total_count(total_count);
|
|
|
|
app_terminal.draw(|f| {
|
|
render_ui(
|
|
f,
|
|
&mut form_state,
|
|
&theme,
|
|
event_handler.is_edit_mode,
|
|
app_state.total_count,
|
|
app_state.current_position,
|
|
&app_state.current_dir,
|
|
&event_handler.command_input,
|
|
event_handler.command_mode,
|
|
&event_handler.command_message,
|
|
);
|
|
})?;
|
|
|
|
if let Some(event) = app_terminal.read_event()? {
|
|
let (should_exit, message) = event_handler.handle_event(
|
|
event,
|
|
&config,
|
|
&mut app_terminal,
|
|
&mut form_state,
|
|
&mut app_state.is_saved,
|
|
app_state.total_count,
|
|
&mut app_state.current_position,
|
|
).await?;
|
|
event_handler.command_message = message;
|
|
if should_exit {
|
|
return Ok(());
|
|
}
|
|
}
|
|
}
|
|
}
|