Compare commits

...

2 Commits

Author SHA1 Message Date
mrbesen e4040c14fe
flushing log 2023-11-21 19:47:08 +01:00
mrbesen dc94dbcb23
improve chatview 2023-11-21 19:46:57 +01:00
5 changed files with 37 additions and 6 deletions

View File

@ -18,6 +18,8 @@ INCFS = $(shell find $(INCF) -type d)
LOGF = ./thirdparty/Log/
LOGO = $(LOGF)Log.o
export LOG_USEMUTEX = 1
export LOG_ENABLEFLUSH = 1
TDLIBF = ./thirdparty/td/tdlib/
TDLIBAF = $(TDLIBF)lib/

View File

@ -1,9 +1,13 @@
#pragma once
#include <string>
class TgTUI;
class View {
public:
static std::string FormatTime(time_t t);
View(TgTUI& tgtui);
virtual ~View();

View File

@ -1,5 +1,13 @@
#include "view.h"
#include <ctime>
std::string View::FormatTime(time_t t) {
char timeBuf[20];
std::size_t len = std::strftime(timeBuf, 20, "%Y-%m-%d %H:%M:%S", std::localtime(&t));
return std::string(timeBuf, len);
}
View::View(TgTUI& tgtui) : tgtui(tgtui) {}
View::~View() {}

View File

@ -22,20 +22,37 @@ int64_t ViewChat::getChat() const {
}
void ViewChat::paint() {
static const size_t FormatLen = 45;
getmaxyx(stdscr, maxRows, maxCols);
::printw("Chat: %s (%li)\n", chat->name.c_str(), chat->chatId);
Log::info << "messages: " << messages.size() << " maxRows: " << maxRows;
for(int row = 0; row < maxRows-1 && row < messages.size(); ++row) {
Log::debug << "print msg at: " << row;
for(uint32_t row = 0; row < maxRows-1 && row < messages.size(); ++row) {
std::shared_ptr<Message> msg = messages.at(row);
const char direction = ( msg->isOutgoing ? '>' : '<' );
const std::string timeStr = FormatTime(msg->sendDate);
std::string msgText = msg->text;
::mvprintw(maxRows - row, 0, "[%lu] %c (%li) %*s\n", msg->sendDate, direction, msg->sender, std::min<int>(msg->text.size(), maxCols), msg->text.c_str());
// find and remove first \n
std::size_t nPos = msgText.find('\n');
if(nPos != std::string::npos) {
msgText.resize(nPos);
}
if(MessageType::TEXT != msg->type) {
msgText = '<' + convertMessageType(msg->type) + '>';
}
uint32_t colLimit = std::min<int>(msgText.size(), maxCols - (FormatLen + 3));
if(msgText.size() > colLimit) {
msgText.resize(colLimit);
msgText.append("...");
}
::mvprintw(maxRows - row -1, 0, "[%s] %c (% 17li) %s", timeStr.c_str(), direction, msg->sender, msgText.c_str());
}
}

2
thirdparty/Log vendored

@ -1 +1 @@
Subproject commit c5274a56b8a306fd184e80bd023824e623c56c27
Subproject commit feac7be1913a883f15258a0b1ed865b7fba25234