3#include <ftxui/component/component.hpp>
4#include <ftxui/component/screen_interactive.hpp>
5#include <ftxui/dom/elements.hpp>
7#include "absl/strings/str_cat.h"
8#include "absl/strings/str_format.h"
16 : rom_context_(rom_context) {
56 if (message.empty())
return;
76 auto send_button = Button(
"Send", [
this] {
80 auto clear_button = Button(
"Clear", [
this] {
84 auto container = Container::Horizontal({
94 return Renderer([
this] {
100 auto container = Container::Vertical({
105 return Renderer(container, [
this] {
107 text(
"🤖 AI Chat") | bold | center,
113 text(
"Commands: /help, /exit, /clear, /rom_info, /status") | dim | center
119 if (event == Event::Return) {
126 if (event == Event::Character(
'q')) {
135 if (event == Event::ArrowUp) {
142 if (event == Event::ArrowDown) {
154 if (message ==
"/exit") {
159 if (message ==
"/clear") {
164 if (message ==
"/help") {
166 "Available commands: /help, /exit, /clear, /rom_info, /status");
170 if (message ==
"/rom_info") {
173 absl::StrFormat(
"ROM: %s | Size: %d bytes",
181 if (message ==
"/status") {
183 absl::StrFormat(
"Chat Status: %d messages, %s",
185 focused_ ?
"Focused" :
"Not focused"));
200 absl::StrCat(
"Error: ", response.status().message()));
225 if (sender ==
"You") {
226 sender_color = Color::Yellow;
227 }
else if (sender ==
"Agent") {
228 sender_color = Color::Green;
230 sender_color = Color::Cyan;
234 text(sender) | bold | color(sender_color),
242 text(
"You: ") | bold,
250 text(
"No messages yet. Start chatting!") | dim | center
254 std::vector<Element> messages;
259 return vbox(messages) | flex;
The Rom class is used to load, save, and modify Rom data.
void RegisterCommand(const std::string &cmd, const std::string &desc, const std::vector< std::string > &examples={})
void SendMessage(const std::string &message)
ftxui::Component history_component_
ftxui::Element RenderChatMessage(const std::string &sender, const std::string &message)
bool HandleHistoryEvents(const ftxui::Event &event)
ftxui::Component GetComponent()
void ProcessMessage(const std::string &message)
std::string input_message_
ftxui::Element RenderInputArea()
void AddMessageToHistory(const std::string &sender, const std::string &message)
void UpdateHistoryDisplay()
int selected_history_index_
agent::ConversationalAgentService agent_service_
bool HandleInputEvents(const ftxui::Event &event)
ftxui::Component CreateInputComponent()
std::function< bool(const ftxui::Event &)> input_event_handler_
ftxui::Component chat_container_
void SetRomContext(Rom *rom_context)
ftxui::Element RenderHistoryArea()
AutocompleteEngine autocomplete_engine_
std::vector< std::pair< std::string, std::string > > chat_history_
std::function< bool(const ftxui::Event &)> history_event_handler_
ftxui::Component CreateHistoryComponent()
EnhancedChatComponent(Rom *rom_context=nullptr)
ftxui::Component CreateChatContainer()
ftxui::Component input_component_
absl::StatusOr< ChatMessage > SendMessage(const std::string &message)
void SetRomContext(Rom *rom)
Main namespace for the application.