RenderView.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
  3. * All rights reserved. Distributed under the terms of the MIT license.
  4. */
  5. #include "RenderView.h"
  6. #include <InterfaceDefs.h>
  7. RenderView::RenderView(const char* name)
  8. :
  9. RunView(name),
  10. fLastDay(364),
  11. fLastYear(64)
  12. {
  13. }
  14. void
  15. RenderView::AppendGeneric(const char* message)
  16. {
  17. if (BString(message).IsEmpty() == true) return;
  18. AppendTimestamp(time(NULL));
  19. Append(message, ui_color(B_PANEL_TEXT_COLOR), B_BOLD_FACE);
  20. if (BString(message).EndsWith("\n") == false) Append("\n");
  21. }
  22. void
  23. RenderView::AppendUserstamp(const char* nick, rgb_color nameColor)
  24. {
  25. Append("<", nameColor, B_BOLD_FACE);
  26. Append(nick, nameColor, B_BOLD_FACE);
  27. Append("> ", nameColor, B_BOLD_FACE);
  28. }
  29. void
  30. RenderView::AppendTimestamp(time_t time)
  31. {
  32. tm* tm = localtime(&time);
  33. // If day changed, print date divider
  34. if (fLastDay < tm->tm_yday || fLastYear < tm->tm_year) {
  35. char datestamp[11] = { '\0' };
  36. strftime(datestamp, 10, "%Y-%m-%d", tm);
  37. BString stamp("――― %date% ―――\n");
  38. stamp.ReplaceAll("%date%", datestamp);
  39. Append(stamp.String(), ui_color(B_PANEL_TEXT_COLOR),
  40. B_ITALIC_FACE | B_BOLD_FACE);
  41. fLastDay = tm->tm_yday;
  42. fLastYear = tm->tm_year;
  43. }
  44. if (time == 0) {
  45. Append("[xx:xx] ", ui_color(B_LINK_HOVER_COLOR), B_BOLD_FACE);
  46. return;
  47. }
  48. char timestamp[9] = { '\0' };
  49. strftime(timestamp, 8, "[%H:%M] ", tm);
  50. Append(timestamp, ui_color(B_LINK_HOVER_COLOR), B_BOLD_FACE);
  51. }