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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//! # Shelgon
//!
//! A robust framework for building interactive REPL (Read-Eval-Print Loop) applications and custom shells in Rust.
//! Just as Shelgon evolves into the mighty Salamence, your REPL can evolve into a powerful shell.
//!
//! ## Overview
//!
//! Shelgon provides a flexible foundation for building terminal-based interactive applications with:
//!
//! - Type-safe command execution
//! - Beautiful terminal UI powered by `ratatui`
//! - Async runtime support via `tokio`
//! - Rich input handling and command history
//! - Tab completion support
//! - Custom context and state management
//!
//! ## Quick Start
//!
//! ```rust,ignore
//! use shelgon::{command, renderer};
//! use tokio::runtime::Runtime;
//!
//! // Define your command executor
//! struct EchoExecutor {}
//!
//! // Implement the core Execute trait
//! impl command::Execute for EchoExecutor {
//! type Context = ();
//!
//! fn prompt(&self, _: &Self::Context) -> String {
//! "$".to_string()
//! }
//!
//! fn prepare(&self, cmd: &str) -> command::Prepare {
//! command::Prepare {
//! command: cmd.to_string(),
//! stdin_required: false,
//! }
//! }
//!
//! fn execute(
//! &self,
//! _: &mut Self::Context,
//! input: command::CommandInput,
//! ) -> anyhow::Result<command::OutputAction> {
//! Ok(command::OutputAction::Command(command::CommandOutput {
//! prompt: input.prompt,
//! command: input.command.clone(),
//! stdin: Vec::new(),
//! stdout: vec![input.command],
//! stderr: Vec::new(),
//! }))
//! }
//! }
//!
//! // Optionally implement the New trait for convenient initialization
//! impl command::New for EchoExecutor {
//! fn new() -> anyhow::Result<(Self, Self::Context)> {
//! Ok((Self {}, ()))
//! }
//! }
//!
//! fn main() -> anyhow::Result<()> {
//! let rt = Runtime::new()?;
//! let app = renderer::App::<EchoExecutor>::new(rt)?;
//! app.execute()
//! }
//! ```
//!
//! ## Key Features
//!
//! ### Type-safe Command Execution
//!
//! Shelgon enforces type safety through its trait system:
//!
//! ```rust
//! # use shelgon::command::{self, Execute, CommandInput, OutputAction};
//! # struct MyExecutor {}
//! impl Execute for MyExecutor {
//! type Context = Vec<String>; // Your custom context type
//!
//! fn execute(
//! &self,
//! ctx: &mut Self::Context,
//! input: CommandInput,
//! ) -> anyhow::Result<OutputAction> {
//! // Your command logic here
//! # Ok(OutputAction::Exit)
//! }
//! // ... other required methods
//! # fn prompt(&self, _: &Self::Context) -> String { "$ ".to_string() }
//! # fn prepare(&self, cmd: &str) -> command::Prepare {
//! # command::Prepare { command: cmd.to_string(), stdin_required: false }
//! # }
//! }
//! ```
//!
//! ### Rich Terminal UI
//!
//! Built on `ratatui`, Shelgon provides:
//!
//! - Command history with color-coded output
//! - Interactive command editing
//! - Tab completion interface
//! - Multi-line input support
//! - Error highlighting
//!
//! ### Async Support
//!
//! Seamless integration with `tokio` for async operations:
//!
//! ```rust,ignore
//! # use shelgon::command::{self, Execute, CommandInput, OutputAction};
//! # use tokio::runtime::Runtime;
//! # struct AsyncExecutor {}
//! # impl Execute for AsyncExecutor {
//! # type Context = ();
//! # fn prompt(&self, _: &Self::Context) -> String { "$ ".to_string() }
//! # fn prepare(&self, cmd: &str) -> command::Prepare {
//! # command::Prepare { command: cmd.to_string(), stdin_required: false }
//! # }
//! async fn fetch_data() -> anyhow::Result<String> {
//! // Async operations
//! # Ok("data".to_string())
//! }
//!
//! impl Execute for AsyncExecutor {
//! // ...
//! fn execute(&self, _: &mut Self::Context, input: CommandInput) -> anyhow::Result<OutputAction> {
//! let result = input.runtime.block_on(fetch_data())?;
//! // Process result
//! # Ok(OutputAction::Exit)
//! }
//! }
//! # }
//! ```
//!
//! ## Core Modules
//!
//! - [`command`]: Core traits and types for command execution
//! - [`renderer`]: Terminal UI and application state management
//!
//! ## Features
//!
//! - `tokio`: Enables async runtime support (enabled by default)
//!
//! ## Shell Capabilities
//!
//! Shelgon shells support:
//!
//! - Command history
//! - Tab completion
//! - Multi-line input
//! - STDIN handling
//! - Color-coded output
//! - Error handling
//! - Screen clearing
//! - Custom prompt formatting
//!
//! ## Key Bindings
//!
//! - `Ctrl+L`: Clear screen
//! - `Ctrl+C/Ctrl+D`: Exit shell
//! - `Left/Right`: Move cursor
//! - `Tab`: Command completion
//! - `Enter`: Execute command or add STDIN line
//! - `Backspace`: Delete character
//!
//! ## License
//!
//! This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
pub use *;
pub use App;