mruby-tui-chat provides a conversation widget for mruby-tui, optimized for AI chat interfaces. It supports word-wrapped text, role-prefixed messages, segmented rendering with colours, markdown AST content, and scroll.
chat = TUI::Chat.new
chat.add(:user, "Hello")
chat.add(:assistant, "Hi there!")chat = TUI::Chat.new
chat.replace_last(:assistant, "")
chat.append(:assistant, "Hello")
chat.append(:assistant, " world")ast = Markdown.new("# Hello\n\n**world**").ast
chat.replace_last(:assistant, ast)chat = TUI::Chat.new(show_roles: false)
chat.add(:user, "just the message")TUI::Chat.new
Creates a chat widget with configurable foreground colours
for user, assistant, and text, plus a background colour.
TUI::Chat#add
Appends a new message with the given role and text.
TUI::Chat#append
Appends text to the last message for the given role, or
creates one if no matching message exists. Used for
streaming output where content arrives incrementally.
TUI::Chat#replace_last
Replaces the last message for the given role. Used for
updating a streaming response in place. Messages may be plain strings,
segment arrays, or markdown AST hashes from mruby-markdown. Pass
follow: true to scroll to the newest message while replacing
the message.
TUI::Chat#scroll_up
Scrolls the view upward by one rendered row.
TUI::Chat#scroll_down
Scrolls the view downward by one rendered row.
TUI::Chat#append and TUI::Chat#replace_last
Both methods preserve the current visible viewport by default. Pass
follow: true when an update should pull the viewport to the bottom.
TUI::Chat#follow!
Returns the viewport to the newest message. This is useful after manual
scrolling when new input or streamed output should resume following the bottom
of the conversation.
Add to your mruby build config:
MRuby::Build.new("app") do |conf|
conf.toolchain
conf.gembox "default"
conf.gem github: "mrbgemz/mruby-tui-chat", branch: "main"
endDependencies are declared in mrbgem.rake:
| Dependency | Purpose |
|---|---|
| mruby-tui | Widget base class, TUI.print, Utils |
BSD Zero Clause
See LICENSE