69 lines
2.0 KiB
C++
69 lines
2.0 KiB
C++
#include <iostream>
|
|
#include <ostream>
|
|
|
|
#include "./../tui.hpp"
|
|
|
|
namespace ui
|
|
{
|
|
void Tui::push_msg_left(const std::string& msg)
|
|
{
|
|
if (!chat_history.empty() && !chat_history.back().left.has_value())
|
|
{
|
|
chat_history.back().left = msg;
|
|
}
|
|
else
|
|
{
|
|
msg_block block = {
|
|
.left = msg,
|
|
.right = std::nullopt
|
|
};
|
|
chat_history.push_back(block);
|
|
}
|
|
}
|
|
|
|
void Tui::push_msg_right(const std::string& msg)
|
|
{
|
|
if (!chat_history.empty() && !chat_history.back().right.has_value())
|
|
{
|
|
chat_history.back().right = msg;
|
|
}
|
|
else
|
|
{
|
|
msg_block block = {
|
|
.left = std::nullopt,
|
|
.right = msg,
|
|
};
|
|
chat_history.push_back(block);
|
|
}
|
|
}
|
|
|
|
void Tui::draw_msg()
|
|
{
|
|
const auto root = std::make_unique<SplitDesc>(SplitDesc::HORIZONTAL, 2);
|
|
|
|
int total_hg = chat_history.size() * 5;
|
|
|
|
int offsetY = 0;
|
|
for (int q = 0; q < chat_history.size(); q++)
|
|
{
|
|
int wh = std::max(3, static_cast<int>(chat_history[q].right.value_or("").length()));
|
|
draw_split_border(wh + 2, 5, border_clip, width - wh - 2, 2 + offsetY, root.get());
|
|
move_cursor(width - wh - 1, 3 + offsetY);
|
|
std::cout << "You" << std::flush;
|
|
move_cursor(width - wh - 1, 5 + offsetY);
|
|
std::cout << chat_history[q].right.value_or("") << std::flush;
|
|
offsetY += 5;
|
|
|
|
|
|
wh = std::max(22, static_cast<int>(chat_history[q].left.value_or("").length()));
|
|
draw_split_border(wh + 2, 5, border_clip, (width / 100) * 27 + 2, 2 + offsetY, root.get());
|
|
move_cursor((width / 100) * 27 + 3, 3 + offsetY);
|
|
std::cout << "Ai (Processing prompt█)" << std::flush;
|
|
move_cursor((width / 100) * 27 + 3, 5 + offsetY);
|
|
std::cout << chat_history[q].left.value_or("") << std::flush;
|
|
offsetY += 5;
|
|
}
|
|
|
|
}
|
|
}
|