Skip to main content

AppState

Struct AppState 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub const fn is_run_form_visible(&self) -> bool

Whether the run-in-project form modal is currently focused.

Source

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.

Source

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.

Source

pub const fn is_error_modal_visible(&self) -> bool

Whether the error modal is currently focused.

Whether the link form modal is currently focused.

Source

pub const fn is_view_value_visible(&self) -> bool

Whether the view-value modal is currently focused.

Source

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.

Source

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.

Source

pub fn close_filter(&mut self)

Clear the filter and restore the full row set.

Source

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).

Source

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.

Source

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.

Source

pub const fn is_form_visible(&self) -> bool

Whether the editor form modal is currently focused.

Source

pub const fn is_confirm_visible(&self) -> bool

Whether a confirmation modal is currently focused.

Source

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.

Source

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.

Source

pub fn set_info_toast(&mut self, msg: impl Into<String>)

Set an informational toast (auto-dismissed on the next action).

Source

pub fn set_error_toast(&mut self, msg: impl Into<String>)

Set an error toast (rendered in the error palette).

Source

pub const fn quit_requested(&self) -> bool

true if the runtime should exit after the current frame.

Source

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.

Source

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().

Source

pub fn visible_rows(&self) -> impl Iterator<Item = &VarSummary>

Iterator over the rows currently rendered by the dashboard.

Source

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.

Source

pub const fn is_filter_active(&self) -> bool

Whether a filter is currently applied (regardless of whether the input box is still open).

Source

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.

Source

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.

Source

pub fn selected_row(&self) -> Option<&VarSummary>

The currently selected VarSummary, if any, resolved through the active filter.

Source

pub const fn table_state(&self) -> &TableState

Read-only access to the TableState. Useful for tests that want to inspect the cursor without rendering.

Source

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.

Source

pub const fn help_visible(&self) -> bool

Whether the help overlay is currently visible.

Source

pub const fn secrets_visible(&self) -> bool

Whether secret values should be rendered (otherwise masked).

Source

pub const fn current_view(&self) -> View

Top-level view currently displayed.

Source

pub fn toast_text(&self) -> Option<&str>

The currently-displayed toast text, if any.

Source

pub fn toast_is_error(&self) -> bool

Whether the current toast is an error (vs informational).

Trait Implementations§

Source§

impl Debug for AppState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AppState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.