about summary refs log tree commit diff stats
path: root/src/ui/core.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-08 22:35:47 +0000
committerJames Booth <boothj5@gmail.com>2014-11-08 22:35:47 +0000
commitbcfbc9f7b33a9d2b4a1c454ea89d2d409c80cda0 (patch)
treed30d9de284eb9cf9d301ca7d7794615b7805e8b6 /src/ui/core.c
parentda376b26d6e9ea688ce3ad575151011b16c75ac4 (diff)
downloadprofani-tty-bcfbc9f7b33a9d2b4a1c454ea89d2d409c80cda0.tar.gz
Added time to xmlconsole, handle newlines in messages
Diffstat (limited to 'src/ui/core.c')
-rw-r--r--src/ui/core.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index e959e94e..07434e2f 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -246,13 +246,13 @@ _ui_handle_stanza(const char * const msg)
         ProfWin *xmlconsole = wins_get_xmlconsole();
 
         if (g_str_has_prefix(msg, "SENT:")) {
-            win_save_print(xmlconsole, '-', NULL, NO_DATE, 0, "", "SENT:");
-            win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_ONLINE, "", &msg[6]);
-            win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_ONLINE, "", "");
+            win_save_print(xmlconsole, '-', NULL, 0, 0, "", "SENT:");
+            win_save_print(xmlconsole, '-', NULL, 0, COLOUR_ONLINE, "", &msg[6]);
+            win_save_print(xmlconsole, '-', NULL, 0, COLOUR_ONLINE, "", "");
         } else if (g_str_has_prefix(msg, "RECV:")) {
-            win_save_print(xmlconsole, '-', NULL, NO_DATE, 0, "", "RECV:");
-            win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_AWAY, "", &msg[6]);
-            win_save_print(xmlconsole, '-', NULL, NO_DATE, COLOUR_AWAY, "", "");
+            win_save_print(xmlconsole, '-', NULL, 0, 0, "", "RECV:");
+            win_save_print(xmlconsole, '-', NULL, 0, COLOUR_AWAY, "", &msg[6]);
+            win_save_print(xmlconsole, '-', NULL, 0, COLOUR_AWAY, "", "");
         }
     }
 }
@@ -3216,4 +3216,3 @@ ui_init_module(void)
     ui_room_occupant_role_and_affiliation_change = _ui_room_occupant_role_and_affiliation_change;
     ui_redraw_all_room_rosters = _ui_redraw_all_room_rosters;
 }
-
or: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
struct bytebuffer {
  char *buf;
  int len;
  int cap;
};

static void bytebuffer_reserve(struct bytebuffer *b, int cap) {
  if (b->cap >= cap) {
    return;
  }

  // prefer doubling capacity
  if (b->cap * 2 >= cap) {
    cap = b->cap * 2;
  }

  char *newbuf = malloc(cap);
  if (b->len > 0) {
    // copy what was there, b->len > 0 assumes b->buf != null
    memcpy(newbuf, b->buf, b->len);
  }
  if (b->buf) {
    // in case there was an allocated buffer, free it
    free(b->buf);
  }
  b->buf = newbuf;
  b->cap = cap;
}

static void bytebuffer_init(struct bytebuffer *b, int cap) {
  b->cap = 0;
  b->len = 0;
  b->buf = 0;

  if (cap > 0) {
    b->cap = cap;
    b->buf = malloc(cap); // just assume malloc works always
  }
}

static void bytebuffer_free(struct bytebuffer *b) {
  if (b->buf)
    free(b->buf);
}

static void bytebuffer_clear(struct bytebuffer *b) {
  b->len = 0;
}

static void bytebuffer_append(struct bytebuffer *b, const char *data, int len) {
  bytebuffer_reserve(b, b->len + len);
  memcpy(b->buf + b->len, data, len);
  b->len += len;
}

static void bytebuffer_puts(struct bytebuffer *b, const char *str) {
  bytebuffer_append(b, str, strlen(str));
}

static void bytebuffer_resize(struct bytebuffer *b, int len) {
  bytebuffer_reserve(b, len);
  b->len = len;
}

static void bytebuffer_flush(struct bytebuffer *b, int fd) {
  int yyy = write(fd, b->buf, b->len);
  (void) yyy;
  bytebuffer_clear(b);
}

static void bytebuffer_truncate(struct bytebuffer *b, int n) {
  if (n <= 0)
    return;
  if (n > b->len)
    n = b->len;
  const int nmove = b->len - n;
  memmove(b->buf, b->buf+n, nmove);
  b->len -= n;
}