Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/d-holguin/chat-tea
ChatTea: A Rust-based chat app with an async server-client setup using Tokio, using a Terminal User Interface built with ratatui. It employs a non-blocking async TUI render loop and is structured similar to Elm
https://github.com/d-holguin/chat-tea
asynchronous ratatui rust terminal-user-interface tui
Last synced: about 2 months ago
JSON representation
ChatTea: A Rust-based chat app with an async server-client setup using Tokio, using a Terminal User Interface built with ratatui. It employs a non-blocking async TUI render loop and is structured similar to Elm
- Host: GitHub
- URL: https://github.com/d-holguin/chat-tea
- Owner: d-holguin
- License: mit
- Created: 2023-11-15T07:06:39.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-16T05:35:10.000Z (4 months ago)
- Last Synced: 2024-09-16T06:51:23.419Z (4 months ago)
- Topics: asynchronous, ratatui, rust, terminal-user-interface, tui
- Language: Rust
- Homepage:
- Size: 237 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ChatTea
![Usage Example](https://github.com/d-holguin/chat_tea/blob/main/example_images/chat_tea_demo.gif)
ChatTea is primarily a learning project for Rust, Tokio, and concurrent programming.
This project is a Rust-based, asynchronous chat application with a Terminal User Interface (TUI), leveraging Tokio for efficient async operations and [ratatui](https://github.com/ratatui-org/ratatui) for the Terminal User Interface.
This project uses an Elm-like architecture, centralizing application logic around a single `Model` and processing events through an update-view cycle, inspired by [ELM](https://guide.elm-lang.org/architecture/).
## Asynchronous Rendering
The core of ChatTea's UI lies in its non-blocking asynchronous render loop. This design ensures that the UI remains responsive and doesn't freeze during network operations or other processes.
## See https://github.com/d-holguin/async-ratatui for a simplier, cleaner structure.
## Elm-like Architecture
### The Message Enum
```rust
#[derive(Clone, Debug)]
pub enum Message {
Quit,
Error,
Tick,
Render,
Key(KeyEvent),
ReceivedNetworkMessage(String),
SendNetworkMessage(String),
Log(ListItem<'static>),
RegisterUser(String),
}
```
Each user interaction and system event is represented by the Message enum, allowing for clear and structured handling of all possible events in the application.### Model
The Model represents the state of the application, encompassing everything from UI state to network management. It acts as the central source of truth within the application, evolving over time in response to the messages processed in the update function.
```rust
pub struct Model<'a> {
pub message_tx: tokio::sync::mpsc::UnboundedSender,
pub fps_counter: FpsCounter,
pub input: Input,
pub input_mode: InputMode,
pub messages: Vec,
pub network_manager: NetworkManager,
pub active_tab: ActiveTab,
pub logs: Vec>,
pub is_user_registered: bool,
}
```
### Update FunctionThe update function processes messages and updates the state of the Model. This function is where the logic of the application responds to user events.
```rust
pub fn update(model: &mut Model, message: Message) {
// ... existing code ...
}
```### View Function
The view function is responsible for rendering the UI based on the current state of the Model. This clear separation of concerns makes the code more maintainable and easier to understand.
```rust
pub fn view(frame: &mut Frame<'_>, model: &Model) {
// ... existing code ...
}
```