1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//! TEA (The Elm Architecture) application framework.
//!
//! This module provides a structured way to build TUI applications using
//! the Elm-inspired unidirectional data flow pattern:
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────┐
//! │ Application │
//! │ │
//! │ ┌─────────┐ ┌────────┐ ┌──────────────────┐ │
//! │ │ State │────▶│ View │────▶│ Terminal/Frame │ │
//! │ └─────────┘ └────────┘ └──────────────────┘ │
//! │ ▲ │
//! │ │ │
//! │ ┌─────────┐ ┌────────────────────┐ │
//! │ │ Update │◀────│ Message/Events │ │
//! │ └─────────┘ └────────────────────┘ │
//! │ │ ▲ │
//! │ ▼ │ │
//! │ ┌─────────┐ ┌────────────────────┐ │
//! │ │ Effects │────▶│ Effect Handler │ │
//! │ └─────────┘ └────────────────────┘ │
//! └─────────────────────────────────────────────────────────┘
//! ```
//!
//! # Core Concepts
//!
//! - **State**: The complete application state (should be serializable)
//! - **Message**: Discrete events that can change state
//! - **Update**: Pure function: `(state, message) → (state, effects)`
//! - **View**: Pure function: `state → UI`
//! - **Effect**: Side effects to execute (IO, commands, etc.)
//!
//! # State Initialization
//!
//! There are two ways to provide the initial state:
//!
//! - **Standard pattern**: Use [`Runtime::terminal_builder()`] or
//! [`Runtime::virtual_builder()`]. These call [`App::init()`] to create
//! the initial state and any startup commands.
//!
//! - **External state pattern**: Use the builder's `.state()` method
//! (e.g., `Runtime::virtual_builder(80, 24).state(s, cmd).build()?`).
//! This accepts a pre-built state directly and **does not call**
//! [`App::init()`]. Useful when initial state comes from CLI arguments,
//! config files, databases, or test fixtures.
//!
//! Even when using `.state()`, [`App::init()`] must still be implemented
//! because it is a required trait method. A simple stub returning default
//! values is sufficient.
//!
//! [`Runtime::terminal_builder()`]: Runtime::terminal_builder
//! [`Runtime::virtual_builder()`]: Runtime::virtual_builder
//!
//! # Example
//!
//! ```rust
//! use envision::app::{App, Command, Update};
//! use envision::input::Event;
//! use ratatui::Frame;
//!
//! // Define your state
//! #[derive(Default, Clone)]
//! struct CounterState {
//! count: i32,
//! }
//!
//! // Define your messages
//! #[derive(Clone)]
//! enum CounterMsg {
//! Increment,
//! Decrement,
//! Reset,
//! }
//!
//! // Implement the App trait
//! struct CounterApp;
//!
//! impl App for CounterApp {
//! type State = CounterState;
//! type Message = CounterMsg;
//!
//! fn init() -> (Self::State, Command<Self::Message>) {
//! (CounterState::default(), Command::none())
//! }
//!
//! fn update(state: &mut Self::State, msg: Self::Message) -> Command<Self::Message> {
//! match msg {
//! CounterMsg::Increment => state.count += 1,
//! CounterMsg::Decrement => state.count -= 1,
//! CounterMsg::Reset => state.count = 0,
//! }
//! Command::none()
//! }
//!
//! fn view(state: &Self::State, frame: &mut Frame) {
//! // Render the UI based on state
//! }
//! }
//! ```
pub use ;
pub use App;
pub use load_state;
pub use restore_terminal;
pub use ;
pub use ;
pub use ;