pub struct AppState { /* private fields */ }Expand description
Dashboard state.
AppState is a pure value: every public method is a function of
(state, input) -> state', so the whole UI can be exercised in
unit tests without ever touching a terminal. The runtime
(crate::run_tui) is the only piece that performs I/O.
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct an empty state with no rows loaded yet.
Call Self::refresh before rendering for the first time to
populate the dashboard. Until then Self::selected_index
returns None (rather than Some(0) pointing at non-existent
row 0) so callers cannot accidentally index into an empty
buffer.
Sourcepub fn refresh<P: VarProvider + ?Sized>(
&mut self,
provider: &P,
) -> Result<(), ProviderError>
pub fn refresh<P: VarProvider + ?Sized>( &mut self, provider: &P, ) -> Result<(), ProviderError>
Re-read rows from provider and re-anchor the selection.
On success the dashboard’s row buffer is replaced. The cursor
is clamped to [0, rows.len()): if the previously-selected
index is still in range it survives; if the new row count is
smaller the cursor pins to the last surviving row; if the
dashboard is now empty the cursor is cleared to None.
On failure the previous rows are preserved and the error is returned unchanged — the runtime decides whether to display it as a toast.
Note: re-anchoring is by index, not by evault_core::model::VarId.
In phase 1 the dashboard is read-only, so external mutation
during a refresh can silently shift the user’s selection by one
row. Phase 2 will track the selected VarId and re-anchor by
identity once CRUD is wired.
§Errors
Propagates whatever ProviderError the provider returns.
Sourcepub fn dispatch_key(&mut self, key: KeyEvent) -> DispatchOutcome
pub fn dispatch_key(&mut self, key: KeyEvent) -> DispatchOutcome
Dispatch a raw key event.
When the filter input is active, characters and Backspace edit
the needle, Enter accepts (filter stays applied but the input
is closed), and Esc cancels the filter entirely. Navigation
keys (Up / Down / PageUp / PageDown) and Ctrl-C remain bound
so the user can scroll through results and quit even while
typing.
When the filter input is not active, the key is translated
via Action::from_key and dispatched to Self::apply.
Returns DispatchOutcome::RefreshRequested when the user
pressed r (or otherwise triggered Action::Refresh); the
runtime is responsible for the actual provider call.
Sourcepub const fn is_run_form_visible(&self) -> bool
pub const fn is_run_form_visible(&self) -> bool
Whether the run-in-project form modal is currently focused.
Sourcepub fn show_value_modal(&mut self, name: String, value: SecretString)
pub fn show_value_modal(&mut self, name: String, value: SecretString)
Show the value modal. Runtime calls this after fetching the
secret material via crate::VarProvider::get_value.
Sourcepub fn show_error_modal(
&mut self,
title: impl Into<String>,
message: impl Into<String>,
hint: Option<String>,
)
pub fn show_error_modal( &mut self, title: impl Into<String>, message: impl Into<String>, hint: Option<String>, )
Raise a focused error modal so the user has to acknowledge
an action failure before continuing. Preferred over
Self::set_error_toast when the user just initiated the
failing action (create / edit / delete / link) — the toast
is too easy to miss.
Sourcepub const fn is_error_modal_visible(&self) -> bool
pub const fn is_error_modal_visible(&self) -> bool
Whether the error modal is currently focused.
Sourcepub const fn is_link_form_visible(&self) -> bool
pub const fn is_link_form_visible(&self) -> bool
Whether the link form modal is currently focused.
Sourcepub const fn is_view_value_visible(&self) -> bool
pub const fn is_view_value_visible(&self) -> bool
Whether the view-value modal is currently focused.
Sourcepub fn apply(&mut self, action: Action)
pub fn apply(&mut self, action: Action)
Apply one Action to the state.
Side-effect-free: only mutates self. The runtime drives this
in a tight loop with each translated key event.
Toast lifecycle: info toasts auto-dismiss on any non-Noop
interaction so they do not pile up; error toasts are sticky
and only cleared by Action::Dismiss or Action::Refresh
so a user typing fast cannot lose a failure notice they never
had a chance to read.
Sourcepub fn open_filter(&mut self)
pub fn open_filter(&mut self)
Open the fuzzy filter overlay. If a filter is already active the input box is re-opened so the user can keep typing without losing the existing needle. Open the fuzzy filter overlay.
If a filter is already applied, the input box is re-opened so the user can continue editing the existing needle. The cursor position is preserved in both first-open and re-open paths so the user’s mental “what is selected” pointer survives a roundtrip through the input.
Sourcepub fn close_filter(&mut self)
pub fn close_filter(&mut self)
Clear the filter and restore the full row set.
Sourcepub fn open_detail(&mut self)
pub fn open_detail(&mut self)
Switch to View::Detail for the currently-selected row.
The selected row’s VarId is snapshotted into
detail_target so the Detail screen looks
up its data by identity rather than index — this prevents the
pane from silently re-pointing at a different row when a
concurrent refresh reshuffles the row buffer.
If no row is selected, the call is a no-op aside from a brief
"no row selected" info toast. A pre-existing error toast is
never clobbered (errors are sticky for a reason; an
accidental Enter must not erase a refresh-failure notice the
user has not yet read).
Sourcepub const fn return_to_dashboard(&mut self)
pub const fn return_to_dashboard(&mut self)
Return to the dashboard from any other view. Clears the Detail target so a subsequent re-entry re-snapshots fresh.
Sourcepub fn splice_out_row(&mut self, id: VarId)
pub fn splice_out_row(&mut self, id: VarId)
Splice the given variable id out of the row buffer locally without going through the provider.
Used by the runtime when a delete succeeded but the
subsequent refresh failed: keeping the deleted row visible
would let the user press d a second time on a ghost entry,
producing a confusing NotFound error or a “deleted twice”
success. Splicing locally restores the user’s mental model.
No-op if the id is not in the buffer. Re-ranks any active filter and clamps the selection cursor.
Sourcepub const fn is_form_visible(&self) -> bool
pub const fn is_form_visible(&self) -> bool
Whether the editor form modal is currently focused.
Sourcepub const fn is_confirm_visible(&self) -> bool
pub const fn is_confirm_visible(&self) -> bool
Whether a confirmation modal is currently focused.
Sourcepub fn dismiss_confirm(&mut self) -> bool
pub fn dismiss_confirm(&mut self) -> bool
Programmatic dismissal of a focused modal. Returns true if a
modal was actually cleared. Used by the runtime to flush state
after the user-initiated delete it triggered has completed.
Sourcepub fn detail_row(&self) -> Option<&VarSummary>
pub fn detail_row(&self) -> Option<&VarSummary>
The variable currently displayed by the Detail view, looked up by identity rather than by selection index.
Returns None when no Detail view is active, or when the
inspected variable has been removed from the row buffer
between Detail entry and the current frame.
Sourcepub fn set_info_toast(&mut self, msg: impl Into<String>)
pub fn set_info_toast(&mut self, msg: impl Into<String>)
Set an informational toast (auto-dismissed on the next action).
Sourcepub fn set_error_toast(&mut self, msg: impl Into<String>)
pub fn set_error_toast(&mut self, msg: impl Into<String>)
Set an error toast (rendered in the error palette).
Sourcepub const fn quit_requested(&self) -> bool
pub const fn quit_requested(&self) -> bool
true if the runtime should exit after the current frame.
Sourcepub fn rows(&self) -> &[VarSummary]
pub fn rows(&self) -> &[VarSummary]
Read-only access to the full row buffer (filter-independent).
Use Self::visible_row_indices / Self::visible_rows when
you need the rows currently rendered by the dashboard.
Sourcepub fn visible_row_indices(&self) -> Vec<usize>
pub fn visible_row_indices(&self) -> Vec<usize>
Indices into Self::rows of the rows currently rendered.
When a filter is applied the indices are in match-score order
(best score first). Without a filter they are simply
0..rows.len().
Sourcepub fn visible_rows(&self) -> impl Iterator<Item = &VarSummary>
pub fn visible_rows(&self) -> impl Iterator<Item = &VarSummary>
Iterator over the rows currently rendered by the dashboard.
Sourcepub fn is_filter_input_active(&self) -> bool
pub fn is_filter_input_active(&self) -> bool
Whether the fuzzy-filter input box is currently capturing
keystrokes. While true characters edit the needle instead of
firing actions.
Sourcepub const fn is_filter_active(&self) -> bool
pub const fn is_filter_active(&self) -> bool
Whether a filter is currently applied (regardless of whether the input box is still open).
Sourcepub fn filter_needle(&self) -> Option<&str>
pub fn filter_needle(&self) -> Option<&str>
The current filter needle, if any. Empty string when the user has opened the filter but not typed anything yet.
Sourcepub const fn selected_index(&self) -> Option<usize>
pub const fn selected_index(&self) -> Option<usize>
Visible-row index of the currently-selected row, if any. This
is the index inside Self::visible_rows, not into
Self::rows. Use Self::selected_row to dereference to
the underlying VarSummary.
Sourcepub fn selected_row(&self) -> Option<&VarSummary>
pub fn selected_row(&self) -> Option<&VarSummary>
The currently selected VarSummary, if any, resolved through
the active filter.
Sourcepub const fn table_state(&self) -> &TableState
pub const fn table_state(&self) -> &TableState
Read-only access to the TableState. Useful for tests that
want to inspect the cursor without rendering.
Sourcepub const fn table_state_mut(&mut self) -> &mut TableState
pub const fn table_state_mut(&mut self) -> &mut TableState
Mutable access to the TableState. The dashboard view
uses this when calling render_stateful_widget.
Sourcepub const fn help_visible(&self) -> bool
pub const fn help_visible(&self) -> bool
Whether the help overlay is currently visible.
Sourcepub const fn secrets_visible(&self) -> bool
pub const fn secrets_visible(&self) -> bool
Whether secret values should be rendered (otherwise masked).
Sourcepub const fn current_view(&self) -> View
pub const fn current_view(&self) -> View
Top-level view currently displayed.
Sourcepub fn toast_text(&self) -> Option<&str>
pub fn toast_text(&self) -> Option<&str>
The currently-displayed toast text, if any.
Sourcepub fn toast_is_error(&self) -> bool
pub fn toast_is_error(&self) -> bool
Whether the current toast is an error (vs informational).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AppState
impl RefUnwindSafe for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
impl UnwindSafe for AppState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more