Compare commits
2 Commits
80f1df6c6d
...
e4040c14fe
Author | SHA1 | Date |
---|---|---|
mrbesen | e4040c14fe | |
mrbesen | dc94dbcb23 |
2
Makefile
2
Makefile
|
@ -18,6 +18,8 @@ INCFS = $(shell find $(INCF) -type d)
|
||||||
|
|
||||||
LOGF = ./thirdparty/Log/
|
LOGF = ./thirdparty/Log/
|
||||||
LOGO = $(LOGF)Log.o
|
LOGO = $(LOGF)Log.o
|
||||||
|
export LOG_USEMUTEX = 1
|
||||||
|
export LOG_ENABLEFLUSH = 1
|
||||||
|
|
||||||
TDLIBF = ./thirdparty/td/tdlib/
|
TDLIBF = ./thirdparty/td/tdlib/
|
||||||
TDLIBAF = $(TDLIBF)lib/
|
TDLIBAF = $(TDLIBF)lib/
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class TgTUI;
|
class TgTUI;
|
||||||
|
|
||||||
class View {
|
class View {
|
||||||
public:
|
public:
|
||||||
|
static std::string FormatTime(time_t t);
|
||||||
|
|
||||||
View(TgTUI& tgtui);
|
View(TgTUI& tgtui);
|
||||||
virtual ~View();
|
virtual ~View();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
#include "view.h"
|
#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(TgTUI& tgtui) : tgtui(tgtui) {}
|
||||||
|
|
||||||
View::~View() {}
|
View::~View() {}
|
||||||
|
|
|
@ -22,20 +22,37 @@ int64_t ViewChat::getChat() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewChat::paint() {
|
void ViewChat::paint() {
|
||||||
|
static const size_t FormatLen = 45;
|
||||||
|
|
||||||
getmaxyx(stdscr, maxRows, maxCols);
|
getmaxyx(stdscr, maxRows, maxCols);
|
||||||
|
|
||||||
::printw("Chat: %s (%li)\n", chat->name.c_str(), chat->chatId);
|
::printw("Chat: %s (%li)\n", chat->name.c_str(), chat->chatId);
|
||||||
|
|
||||||
Log::info << "messages: " << messages.size() << " maxRows: " << maxRows;
|
Log::info << "messages: " << messages.size() << " maxRows: " << maxRows;
|
||||||
|
|
||||||
for(int row = 0; row < maxRows-1 && row < messages.size(); ++row) {
|
for(uint32_t row = 0; row < maxRows-1 && row < messages.size(); ++row) {
|
||||||
|
|
||||||
|
|
||||||
Log::debug << "print msg at: " << row;
|
|
||||||
std::shared_ptr<Message> msg = messages.at(row);
|
std::shared_ptr<Message> msg = messages.at(row);
|
||||||
const char direction = ( msg->isOutgoing ? '>' : '<' );
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit c5274a56b8a306fd184e80bd023824e623c56c27
|
Subproject commit feac7be1913a883f15258a0b1ed865b7fba25234
|
Loading…
Reference in New Issue