tui-chat

Crates.iotui-chat
lib.rstui-chat
version0.2.1
created_at2025-09-30 23:43:42.045336+00
updated_at2025-10-03 10:44:07.927799+00
descriptionTerminal chat widgets for ratatui applications
homepage
repositoryhttps://github.com/emincangencer/tui-chat
max_upload_size
id1861857
size58,610
Emincan Gençer (emincangencer)

documentation

README

Tui-chat

A Rust crate providing terminal chat widgets for ratatui applications. Includes ChatArea for displaying messages and InputArea for multiline text input, along with a complete ChatApp for quick prototyping.

Features

  • Multiline Input: Type messages with line breaks using Shift+Enter.
  • Clipboard Paste Support: Paste multiline text from clipboard with proper line ending normalization.
  • Scrollable Chat History: Navigate through messages with Page Up/Down or mouse wheel.
  • Simulated AI Responses: Automatically responds to user messages for demonstration.
  • Keyboard Navigation: Full cursor movement support in input area (arrow keys, etc.).
  • Cross-Platform: Works on Windows, macOS, and Linux.

Installation

Add the crate to your project:

cargo add tui-chat

Or manually add to your Cargo.toml:

[dependencies]
tui-chat = "0.2.0"

This will automatically include all required dependencies (ratatui, crossterm, textwrap, arboard).

Prerequisites

  • Rust 1.70 or later
  • Cargo package manager

Usage

As a Library

use tui_chat::{ChatArea, InputArea, ChatMessage};

let mut chat_area = ChatArea::new();
let mut input_area = InputArea::new();

// Add a message
chat_area.add_message(ChatMessage {
    sender: "User".to_string(),
    content: "Hello!".to_string(),
});

// In your render loop
chat_area.render(frame, chat_rect);
input_area.render(frame, input_rect);

Running the Example

To see a full chat application, run the included example:

cargo run --example chat_app

Keybindings (for ChatApp example)

  • Enter: Send message
  • Ctrl+Enter, Ctrl+J, Shift+Enter: New line in input (depends on the OS and terminal. With WSL, and likely macOS and Linux, it's Ctrl+Enter or Ctrl+J; with PowerShell (pwsh), it's Shift+Enter and Ctrl+J)
  • Ctrl+V: Paste from clipboard
  • Page Up/Down: Scroll chat history
  • Mouse Wheel: Scroll chat history (when cursor is over chat area)
  • Arrow Keys: Navigate cursor in input area
  • Backspace: Delete character
  • Ctrl+C or Esc: Quit application

Dependencies

  • crossterm: Cross-platform terminal manipulation
  • ratatui: Terminal UI framework

License

This project is licensed under the MIT License.

Commit count: 0

cargo fmt