Lines
94.12 %
Functions
75 %
Branches
100 %
//! View dispatch types and traits.
pub mod console;
pub mod list;
pub mod reports;
pub mod select_list;
#[cfg(test)]
mod tests;
use crate::hits::Hits;
use tvui::{FrameState, Theme};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ViewId {
Accounts = 0,
Transactions = 1,
Commodities = 2,
Reports = 3,
Config = 4,
SshKeys = 5,
Tags = 6,
Templates = 7,
Console = 8,
Scripts = 9,
/// Not among [`ViewId::ALL`]: a viewer opens for what it shows, never blank.
Viewer = 10,
}
impl ViewId {
pub const ALL: [ViewId; 10] = [
ViewId::Accounts,
ViewId::Transactions,
ViewId::Commodities,
ViewId::Reports,
ViewId::Config,
ViewId::SshKeys,
ViewId::Tags,
ViewId::Templates,
ViewId::Console,
ViewId::Scripts,
];
pub fn index(self) -> usize {
self as usize
pub fn label(self) -> &'static str {
match self {
ViewId::Accounts => "Accounts",
ViewId::Transactions => "Transactions",
ViewId::Commodities => "Commodities",
ViewId::Reports => "Reports",
ViewId::Config => "Config",
ViewId::SshKeys => "SSH keys",
ViewId::Tags => "Tags",
ViewId::Templates => "Templates",
ViewId::Scripts => "Scripts",
ViewId::Console => "Console",
ViewId::Viewer => "Viewer",
/// `Tab` is an alias so existing `Tab::Accounts`, `Tab::ALL`, etc. keep compiling.
pub type Tab = ViewId;
pub struct DrawCtx<'a> {
/// True when the view currently holds keyboard focus (e.g. console input active).
pub is_active: bool,
/// What the window's frame shows; passive for a rear window and under a modal.
pub frame: FrameState,
/// The window's frame title, from [`crate::window::View::title`].
pub title: String,
pub theme: &'a Theme,
/// The areas the view draws that a click can land on.
pub hits: &'a mut Hits,
pub enum Handled {
Consumed(Vec<Cmd>),
Ignored,
pub enum Cmd {
Status(String),
SwitchView(ViewId),