Show timestamps in RunView, with custom values

This makes it so RunView's built-in timestamps are used― but requires
that a time_t be sent with each newly-appended line. This allows for lines to
be backdated or forward-dated.
This commit is contained in:
Jaidyn Ann 2021-06-14 14:42:38 -05:00
parent 6c43311982
commit 577cfd1ae0
3 changed files with 60 additions and 37 deletions

View File

@ -8,14 +8,17 @@
CayaRenderView::CayaRenderView(const char *name, const char* smileyConfig) CayaRenderView::CayaRenderView(const char *name, const char* smileyConfig)
: :
RunView(BRect(0, 0, 1, 1), name, fTheme = new Theme(name, COL_MAX_COLORS + 1, COL_MAX_COLORS + 1, MAX_RENDERS + 1), B_FOLLOW_ALL, B_WILL_DRAW ) RunView(BRect(0, 0, 1, 1), name,
fTheme = new Theme(name, COL_MAX_COLORS + 1, COL_MAX_COLORS + 1,
MAX_RENDERS + 1),
B_FOLLOW_ALL, B_WILL_DRAW)
{ {
if (smileyConfig) if (smileyConfig)
Emoticor::Get()->LoadConfig(smileyConfig); Emoticor::Get()->LoadConfig(smileyConfig);
PrepareTheme(fTheme); PrepareTheme(fTheme);
SetTimeStampFormat(NULL); SetTimeStampFormat("[%H:%M]");
if ( IsHidden() ) if ( IsHidden() )
Show(); Show();
ScrollToBottom(); ScrollToBottom();
@ -29,7 +32,7 @@ CayaRenderView::AppendMessage(const char* nick, const char* message,
rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color fg = ui_color(B_PANEL_TEXT_COLOR); rgb_color fg = ui_color(B_PANEL_TEXT_COLOR);
Append("<", nameColor, bg, nameColor); Append("<", nameColor, bg, nameColor, time(NULL));
Append(nick, fg, bg, fg); Append(nick, fg, bg, fg);
Append("> ", nameColor, bg, nameColor); Append("> ", nameColor, bg, nameColor);
// AddEmoticText(message, fg, bg); // AddEmoticText(message, fg, bg);
@ -45,7 +48,7 @@ CayaRenderView::AppendGenericMessage(const char* message)
rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color fg = ui_color(B_PANEL_TEXT_COLOR); rgb_color fg = ui_color(B_PANEL_TEXT_COLOR);
Append(message, fg, bg, fg); Append(message, fg, bg, fg, time(NULL));
ScrollToSelection(); ScrollToSelection();
} }

View File

@ -129,7 +129,8 @@ struct Line {
int fSoftie_used; int fSoftie_used;
Line(const char* buffer, int fLength, float top, float width, Theme* fTheme, Line(const char* buffer, int fLength, float top, float width, Theme* fTheme,
const char* fStamp_format, rgb_color fore, rgb_color back, rgb_color font); const char* fStamp_format, time_t fStamp, rgb_color fore, rgb_color back,
rgb_color font);
~Line (); ~Line ();
@ -1237,15 +1238,15 @@ RunView::RecalcScrollBar(bool constrain)
void void
RunView::Append(const char* buffer, rgb_color fore, rgb_color back, RunView::Append(const char* buffer, rgb_color fore, rgb_color back,
rgb_color font) rgb_color font, time_t time)
{ {
Append(buffer, strlen(buffer), fore, back, font); Append(buffer, strlen(buffer), fore, back, font, time);
} }
void void
RunView::Append(const char* buffer, int32 len, rgb_color fore, rgb_color back, RunView::Append(const char* buffer, int32 len, rgb_color fore, rgb_color back,
rgb_color font) rgb_color font, time_t time)
{ {
if (buffer == NULL) if (buffer == NULL)
return; return;
@ -1290,9 +1291,8 @@ RunView::Append(const char* buffer, int32 len, rgb_color fore, rgb_color back,
if (fLine_count > 0) if (fLine_count > 0)
top = fLines[fLine_count - 1]->fBottom + (float) 1.0; top = fLines[fLine_count - 1]->fBottom + (float) 1.0;
//HERE
fWorking = new Line(buffer + place, 0, top, width, fTheme, fWorking = new Line(buffer + place, 0, top, width, fTheme,
fStamp_format, fore, back, font); fStamp_format, time, fore, back, font);
URLCrunch crunch(buffer + place, end - place); URLCrunch crunch(buffer + place, end - place);
BString temp; BString temp;
@ -1745,10 +1745,11 @@ void RunView::ScrollToSelection()
Line::Line(const char* buffer, int len, float top, float width, Theme* theme, Line::Line(const char* buffer, int len, float top, float width, Theme* theme,
const char* stamp_format, rgb_color fore, rgb_color back, rgb_color font) const char* stamp_format, time_t stamp_time, rgb_color fore,
rgb_color back, rgb_color font)
: :
fText(NULL), fText(NULL),
fStamp(time(NULL)), fStamp(stamp_time),
fUrls(NULL), fUrls(NULL),
fSpaces(NULL), fSpaces(NULL),
fEdges(NULL), fEdges(NULL),
@ -2265,14 +2266,27 @@ Line::SetStamp(const char* format, bool was_on)
struct tm curTime; struct tm curTime;
localtime_r(&fStamp, &curTime); localtime_r(&fStamp, &curTime);
// If no time specified, subsitute times with "x"
if (fStamp == 0) {
curTime.tm_hour, curTime.tm_min, curTime.tm_sec = 0;
BString newFormat(format);
newFormat.ReplaceAll("%H", "xx");
size = strftime(buffer, 1023, newFormat.String(), &curTime);
const char* newBuffer = BString(buffer).ReplaceAll("0", "x").String();
memcpy(buffer, newBuffer, size);
}
else
size = strftime (buffer, 1023, format, &curTime); size = strftime (buffer, 1023, format, &curTime);
if (fUrls) { if (fUrls) {
for (i = 0; i < fUrls->CountItems(); i++) for (i = 0; i < fUrls->CountItems(); i++)
fUrls->ItemAt(i)->fOffset += size; fUrls->ItemAt(i)->fOffset += size;
} }
char* new_fText; char* new_fText;
new_fText = new char[fLength + size + 2]; new_fText = new char[fLength + size + 2];
memcpy(new_fText, buffer, size); memcpy(new_fText, buffer, size);
new_fText[size++] = ' '; new_fText[size++] = ' ';
@ -2300,22 +2314,28 @@ Line::SetStamp(const char* format, bool was_on)
fFc_count += 6; fFc_count += 6;
fFcs[0].fWhich = FORE_WHICH; fFcs[0].fWhich = FORE_WHICH;
fFcs[0].fColor = ui_color(B_LINK_HOVER_COLOR);
fFcs[0].fIndex = Theme::TimestampFore; fFcs[0].fIndex = Theme::TimestampFore;
fFcs[0].fOffset = 0; fFcs[0].fOffset = 0;
fFcs[1].fWhich = BACK_WHICH; fFcs[1].fWhich = BACK_WHICH;
fFcs[1].fColor = ui_color(B_PANEL_BACKGROUND_COLOR);
fFcs[1].fIndex = Theme::TimestampBack; fFcs[1].fIndex = Theme::TimestampBack;
fFcs[1].fOffset = 0; fFcs[1].fOffset = 0;
fFcs[2].fWhich = FONT_WHICH; fFcs[2].fWhich = FONT_WHICH;
fFcs[2].fColor = ui_color(B_PANEL_BACKGROUND_COLOR);
fFcs[2].fIndex = Theme::TimestampFont; fFcs[2].fIndex = Theme::TimestampFont;
fFcs[2].fOffset = 0; fFcs[2].fOffset = 0;
fFcs[3].fWhich = FORE_WHICH; fFcs[3].fWhich = FORE_WHICH;
fFcs[0].fColor = ui_color(B_LINK_HOVER_COLOR);
fFcs[3].fIndex = Theme::TimespaceFore; fFcs[3].fIndex = Theme::TimespaceFore;
fFcs[3].fOffset = size - 1; fFcs[3].fOffset = size - 1;
fFcs[4].fWhich = BACK_WHICH; fFcs[4].fWhich = BACK_WHICH;
fFcs[4].fColor = ui_color(B_PANEL_BACKGROUND_COLOR);
fFcs[4].fIndex = Theme::TimespaceBack; fFcs[4].fIndex = Theme::TimespaceBack;
fFcs[4].fOffset = size - 1; fFcs[4].fOffset = size - 1;
fFcs[5].fWhich = FONT_WHICH; fFcs[5].fWhich = FONT_WHICH;
fFcs[5].fColor = ui_color(B_PANEL_BACKGROUND_COLOR);
fFcs[5].fIndex = Theme::TimespaceFont; fFcs[5].fIndex = Theme::TimespaceFont;
fFcs[5].fOffset = size - 1; fFcs[5].fOffset = size - 1;

View File

@ -158,8 +158,8 @@ public:
virtual void MouseUp (BPoint); virtual void MouseUp (BPoint);
void Append (const char*, int32, rgb_color, rgb_color, rgb_color); void Append (const char*, int32, rgb_color, rgb_color, rgb_color, time_t = 0);
void Append (const char*, rgb_color, rgb_color, rgb_color); void Append (const char*, rgb_color, rgb_color, rgb_color, time_t = 0);
void Clear (void); void Clear (void);