2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
printtext.c : irssi
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "module-formats.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "commands.h"
|
|
|
|
#include "special-vars.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
#include "levels.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "servers.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
#include "translation.h"
|
|
|
|
#include "themes.h"
|
|
|
|
#include "windows.h"
|
|
|
|
|
2000-07-30 13:32:55 -04:00
|
|
|
static int beep_msg_level, beep_when_away;
|
2000-05-15 04:25:45 -04:00
|
|
|
static int timestamps, msgs_timestamps, hide_text_style;
|
|
|
|
static int timestamp_timeout;
|
|
|
|
|
|
|
|
static int signal_gui_print_text;
|
|
|
|
static int signal_print_text_stripped;
|
|
|
|
static int signal_print_text;
|
|
|
|
static int signal_print_text_finished;
|
2000-10-27 23:01:11 -04:00
|
|
|
static int signal_print_format;
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
static void print_string(TEXT_DEST_REC *dest, const char *text);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
void printbeep(void)
|
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
signal_emit_id(signal_gui_print_text, 6, active_win, NULL, NULL,
|
|
|
|
GINT_TO_POINTER(PRINTFLAG_BEEP), "", MSGLEVEL_NEVER);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
static void skip_mirc_color(char **str)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
if (!isdigit((int) **str))
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* foreground */
|
|
|
|
(*str)++;
|
|
|
|
if (isdigit((int) **str)) (*str)++;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
if (**str != ',' || !isdigit((int) (*str)[1])) return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* background */
|
|
|
|
(*str) += 2;
|
|
|
|
if (isdigit((int) **str)) (*str)++;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
#define is_color_code(c) \
|
|
|
|
((c) == 2 || (c) == 3 || (c) == 4 || (c) == 6 || (c) == 7 || \
|
|
|
|
(c) == 15 || (c) == 22 || (c) == 27 || (c) == 31)
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
char *strip_codes(const char *input)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
char *str, *out;
|
|
|
|
|
|
|
|
out = str = g_strdup(input);
|
|
|
|
for (p = input; *p != '\0'; p++) {
|
|
|
|
if (*p == 3) {
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if (*p < 17 && *p > 0) {
|
|
|
|
/* irssi color */
|
|
|
|
if (p[1] < 17 && p[1] > 0) p++;
|
|
|
|
continue;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* mirc color */
|
|
|
|
skip_mirc_color((char **) &p);
|
|
|
|
p--;
|
|
|
|
continue;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
if (*p == 4 && p[1] != '\0' && p[2] != '\0') {
|
|
|
|
/* irssi color */
|
|
|
|
p += 2;
|
|
|
|
continue;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
if (!is_color_code(*p))
|
|
|
|
*out++ = *p;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
*out = '\0';
|
|
|
|
return str;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* parse ANSI color string */
|
2000-07-31 17:16:09 -04:00
|
|
|
static char *convert_ansi(THEME_REC *theme, char *str,
|
|
|
|
int *fgcolor, int *bgcolor, int *flags)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
static char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
|
|
|
|
char *start;
|
|
|
|
int fg, bg, fl, num;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
if (*str != '[')
|
|
|
|
return str;
|
|
|
|
start = str++;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-07-31 17:16:09 -04:00
|
|
|
fg = *fgcolor < 0 ? theme->default_color : *fgcolor;
|
2000-05-15 04:25:45 -04:00
|
|
|
bg = *bgcolor < 0 ? -1 : *bgcolor;
|
|
|
|
fl = *flags;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
num = 0;
|
|
|
|
for (;; str++) {
|
|
|
|
if (*str == '\0') return start;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
if (isdigit((int) *str)) {
|
|
|
|
num = num*10 + (*str-'0');
|
|
|
|
continue;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
if (*str != ';' && *str != 'm')
|
|
|
|
return start;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
switch (num) {
|
|
|
|
case 0:
|
|
|
|
/* reset colors back to default */
|
2000-07-31 17:16:09 -04:00
|
|
|
fg = theme->default_color;
|
2000-05-15 04:25:45 -04:00
|
|
|
bg = -1;
|
2000-06-09 12:58:52 -04:00
|
|
|
fl &= ~(PRINTFLAG_BEEP|PRINTFLAG_INDENT);
|
2000-05-15 04:25:45 -04:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* hilight */
|
2000-06-09 12:58:52 -04:00
|
|
|
fl |= PRINTFLAG_BOLD;
|
2000-05-15 04:25:45 -04:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
/* blink */
|
2000-06-09 12:58:52 -04:00
|
|
|
fl |= PRINTFLAG_BLINK;
|
2000-05-15 04:25:45 -04:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
/* reverse */
|
|
|
|
fl |= PRINTFLAG_REVERSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (num >= 30 && num <= 37)
|
|
|
|
fg = (fg & 0xf8) + ansitab[num-30];
|
|
|
|
if (num >= 40 && num <= 47) {
|
|
|
|
if (bg == -1) bg = 0;
|
|
|
|
bg = (bg & 0xf8) + ansitab[num-40];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
num = 0;
|
|
|
|
|
|
|
|
if (*str == 'm') {
|
|
|
|
if (!hide_text_style) {
|
|
|
|
*fgcolor = fg;
|
2000-06-09 12:58:52 -04:00
|
|
|
*bgcolor = bg;
|
2000-05-15 04:25:45 -04:00
|
|
|
*flags = fl;
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
return str;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
static int expand_styles(GString *out, char format, TEXT_DEST_REC *dest)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
static const char *backs = "04261537";
|
|
|
|
static const char *fores = "kbgcrmyw";
|
|
|
|
static const char *boldfores = "KBGCRMYW";
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case 'U':
|
|
|
|
/* Underline on/off */
|
|
|
|
g_string_append_c(out, 4);
|
|
|
|
g_string_append_c(out, -1);
|
|
|
|
g_string_append_c(out, 2);
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
case '9':
|
|
|
|
case '_':
|
2000-05-15 04:25:45 -04:00
|
|
|
/* bold on/off */
|
|
|
|
g_string_append_c(out, 4);
|
|
|
|
g_string_append_c(out, -1);
|
|
|
|
g_string_append_c(out, 1);
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
case '8':
|
2000-05-15 04:25:45 -04:00
|
|
|
/* reverse */
|
|
|
|
g_string_append_c(out, 4);
|
|
|
|
g_string_append_c(out, -1);
|
|
|
|
g_string_append_c(out, 3);
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
case '%':
|
2000-05-15 04:25:45 -04:00
|
|
|
g_string_append_c(out, '%');
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
case ':':
|
2000-05-15 04:25:45 -04:00
|
|
|
/* Newline */
|
|
|
|
print_string(dest, out->str);
|
|
|
|
g_string_truncate(out, 0);
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
case '|':
|
2000-05-15 04:25:45 -04:00
|
|
|
/* Indent here */
|
|
|
|
g_string_append_c(out, 4);
|
|
|
|
g_string_append_c(out, -1);
|
|
|
|
g_string_append_c(out, 4);
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
case 'F':
|
2000-05-15 04:25:45 -04:00
|
|
|
/* flashing - ignore */
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
case 'N':
|
2000-05-15 04:25:45 -04:00
|
|
|
/* don't put clear-color tag at the end of the output - ignore */
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
case 'n':
|
2000-05-15 04:25:45 -04:00
|
|
|
/* default color */
|
2000-04-26 04:03:38 -04:00
|
|
|
g_string_append_c(out, 4);
|
2000-05-15 04:25:45 -04:00
|
|
|
g_string_append_c(out, -1);
|
|
|
|
g_string_append_c(out, -1);
|
2000-04-26 04:03:38 -04:00
|
|
|
break;
|
2000-05-15 04:25:45 -04:00
|
|
|
default:
|
|
|
|
/* check if it's a background color */
|
|
|
|
p = strchr(backs, format);
|
|
|
|
if (p != NULL) {
|
|
|
|
g_string_append_c(out, 4);
|
|
|
|
g_string_append_c(out, -2);
|
|
|
|
g_string_append_c(out, (int) (p-backs)+1);
|
|
|
|
break;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* check if it's a foreground color */
|
|
|
|
if (format == 'p') format = 'm';
|
|
|
|
p = strchr(fores, format);
|
|
|
|
if (p != NULL) {
|
|
|
|
g_string_append_c(out, 4);
|
|
|
|
g_string_append_c(out, (int) (p-fores)+1);
|
|
|
|
g_string_append_c(out, -2);
|
|
|
|
break;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* check if it's a bold foreground color */
|
|
|
|
if (format == 'P') format = 'M';
|
|
|
|
p = strchr(boldfores, format);
|
|
|
|
if (p != NULL) {
|
|
|
|
g_string_append_c(out, 4);
|
|
|
|
g_string_append_c(out, 8+(int) (p-boldfores)+1);
|
|
|
|
g_string_append_c(out, -2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
return TRUE;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void read_arglist(va_list va, FORMAT_REC *format,
|
|
|
|
char **arglist, int arglist_size,
|
|
|
|
char *buffer, int buffer_size)
|
|
|
|
{
|
|
|
|
int num, len, bufpos;
|
|
|
|
|
|
|
|
bufpos = 0;
|
2000-05-15 04:25:45 -04:00
|
|
|
arglist[format->params] = NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
for (num = 0; num < format->params && num < arglist_size; num++) {
|
|
|
|
switch (format->paramtypes[num]) {
|
|
|
|
case FORMAT_STRING:
|
|
|
|
arglist[num] = (char *) va_arg(va, char *);
|
|
|
|
if (arglist[num] == NULL) {
|
2000-05-15 04:25:45 -04:00
|
|
|
g_warning("read_arglist() : parameter %d is NULL", num);
|
2000-04-26 04:03:38 -04:00
|
|
|
arglist[num] = "";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FORMAT_INT: {
|
|
|
|
int d = (int) va_arg(va, int);
|
|
|
|
|
|
|
|
if (bufpos >= buffer_size) {
|
|
|
|
arglist[num] = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
arglist[num] = buffer+bufpos;
|
|
|
|
len = g_snprintf(buffer+bufpos, buffer_size-bufpos,
|
|
|
|
"%d", d);
|
|
|
|
bufpos += len+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FORMAT_LONG: {
|
|
|
|
long l = (long) va_arg(va, long);
|
|
|
|
|
|
|
|
if (bufpos >= buffer_size) {
|
|
|
|
arglist[num] = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
arglist[num] = buffer+bufpos;
|
|
|
|
len = g_snprintf(buffer+bufpos, buffer_size-bufpos,
|
|
|
|
"%ld", l);
|
|
|
|
bufpos += len+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FORMAT_FLOAT: {
|
|
|
|
double f = (double) va_arg(va, double);
|
|
|
|
|
|
|
|
if (bufpos >= buffer_size) {
|
|
|
|
arglist[num] = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
arglist[num] = buffer+bufpos;
|
|
|
|
len = g_snprintf(buffer+bufpos, buffer_size-bufpos,
|
|
|
|
"%0.2f", f);
|
|
|
|
bufpos += len+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-31 17:16:09 -04:00
|
|
|
static void create_dest_rec(TEXT_DEST_REC *dest,
|
2000-10-27 23:01:11 -04:00
|
|
|
void *server, const char *target,
|
2000-07-31 17:16:09 -04:00
|
|
|
int level, WINDOW_REC *window)
|
|
|
|
{
|
|
|
|
dest->server = server;
|
2000-10-27 23:01:11 -04:00
|
|
|
dest->target = target;
|
2000-07-31 17:16:09 -04:00
|
|
|
dest->level = level;
|
|
|
|
dest->window = window != NULL ? window :
|
2000-10-27 23:01:11 -04:00
|
|
|
window_find_closest(server, target, level);
|
2000-07-31 17:16:09 -04:00
|
|
|
}
|
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
char *output_format_text_args(TEXT_DEST_REC *dest, FORMAT_REC *format,
|
|
|
|
const char *text, va_list va)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
GString *out;
|
2000-04-26 04:03:38 -04:00
|
|
|
char *arglist[10];
|
|
|
|
char buffer[200]; /* should be enough? (won't overflow even if it isn't) */
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
char code, *ret;
|
2000-04-26 04:03:38 -04:00
|
|
|
int need_free;
|
|
|
|
|
|
|
|
/* read all optional arguments to arglist[] list
|
|
|
|
so they can be used in any order.. */
|
2000-07-31 18:01:32 -04:00
|
|
|
read_arglist(va, format,
|
2000-04-26 04:03:38 -04:00
|
|
|
arglist, sizeof(arglist)/sizeof(void*),
|
|
|
|
buffer, sizeof(buffer));
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
out = g_string_new(NULL);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
code = 0;
|
2000-10-27 21:52:16 -04:00
|
|
|
while (*text != '\0') {
|
2000-04-26 04:03:38 -04:00
|
|
|
if (code == '%') {
|
|
|
|
/* color code */
|
2000-10-27 21:52:16 -04:00
|
|
|
if (!expand_styles(out, *text, dest)) {
|
2000-04-26 04:03:38 -04:00
|
|
|
g_string_append_c(out, '%');
|
|
|
|
g_string_append_c(out, '%');
|
2000-10-27 21:52:16 -04:00
|
|
|
g_string_append_c(out, *text);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
code = 0;
|
|
|
|
} else if (code == '$') {
|
|
|
|
/* argument */
|
|
|
|
char *ret;
|
|
|
|
|
2000-10-27 21:52:16 -04:00
|
|
|
ret = parse_special((char **) &text, active_win->active_server,
|
2000-05-15 04:25:45 -04:00
|
|
|
active_win->active, arglist, &need_free, NULL);
|
2000-09-26 18:02:19 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
if (ret != NULL) {
|
2000-09-26 18:02:19 -04:00
|
|
|
/* string shouldn't end with \003 or it could
|
|
|
|
mess up the next one or two characters */
|
|
|
|
int diff;
|
|
|
|
int len = strlen(ret);
|
|
|
|
while (len > 0 && ret[len-1] == 3) len--;
|
|
|
|
diff = strlen(ret)-len;
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
g_string_append(out, ret);
|
2000-09-26 18:02:19 -04:00
|
|
|
if (diff > 0)
|
|
|
|
g_string_truncate(out, out->len-diff);
|
2000-04-26 04:03:38 -04:00
|
|
|
if (need_free) g_free(ret);
|
|
|
|
}
|
|
|
|
code = 0;
|
|
|
|
} else {
|
2000-10-27 21:52:16 -04:00
|
|
|
if (*text == '%' || *text == '$')
|
|
|
|
code = *text;
|
2000-04-26 04:03:38 -04:00
|
|
|
else
|
2000-10-27 21:52:16 -04:00
|
|
|
g_string_append_c(out, *text);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-10-27 21:52:16 -04:00
|
|
|
text++;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
ret = out->str;
|
|
|
|
g_string_free(out, FALSE);
|
|
|
|
return ret;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-07-31 18:01:32 -04:00
|
|
|
char *output_format_get_text(const char *module, WINDOW_REC *window,
|
2000-10-27 23:01:11 -04:00
|
|
|
void *server, const char *target,
|
2000-07-31 18:01:32 -04:00
|
|
|
int formatnum, ...)
|
|
|
|
{
|
|
|
|
TEXT_DEST_REC dest;
|
|
|
|
THEME_REC *theme;
|
|
|
|
MODULE_THEME_REC *module_theme;
|
|
|
|
FORMAT_REC *formats;
|
|
|
|
va_list va;
|
|
|
|
char *ret;
|
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
create_dest_rec(&dest, server, target, 0, window);
|
2000-07-31 18:01:32 -04:00
|
|
|
theme = dest.window->theme == NULL ? current_theme :
|
|
|
|
dest.window->theme;
|
|
|
|
|
|
|
|
module_theme = g_hash_table_lookup(theme->modules, module);
|
|
|
|
formats = g_hash_table_lookup(default_formats, module);
|
|
|
|
|
|
|
|
va_start(va, formatnum);
|
|
|
|
ret = output_format_text_args(&dest, &formats[formatnum],
|
2000-10-27 19:06:26 -04:00
|
|
|
module_theme->expanded_formats[formatnum], va);
|
2000-07-31 18:01:32 -04:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
static char *output_format_text(TEXT_DEST_REC *dest, int formatnum, ...)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-07-31 17:16:09 -04:00
|
|
|
THEME_REC *theme;
|
|
|
|
MODULE_THEME_REC *module_theme;
|
2000-07-31 18:01:32 -04:00
|
|
|
va_list va;
|
2000-05-15 04:25:45 -04:00
|
|
|
char *ret;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-07-31 17:16:09 -04:00
|
|
|
theme = dest->window->theme == NULL ? current_theme :
|
|
|
|
dest->window->theme;
|
|
|
|
module_theme = g_hash_table_lookup(theme->modules, MODULE_NAME);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-07-31 18:01:32 -04:00
|
|
|
va_start(va, formatnum);
|
2000-05-15 04:25:45 -04:00
|
|
|
ret = output_format_text_args(dest, &fecommon_core_formats[formatnum],
|
2000-10-27 19:06:26 -04:00
|
|
|
module_theme->expanded_formats[formatnum], va);
|
2000-07-31 18:01:32 -04:00
|
|
|
va_end(va);
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
return ret;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-07-31 17:16:09 -04:00
|
|
|
void printformat_module_args(const char *module, void *server,
|
2000-10-27 23:01:11 -04:00
|
|
|
const char *target, int level,
|
2000-07-31 17:16:09 -04:00
|
|
|
int formatnum, va_list va)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-07-31 17:16:09 -04:00
|
|
|
THEME_REC *theme;
|
|
|
|
MODULE_THEME_REC *module_theme;
|
2000-05-15 04:25:45 -04:00
|
|
|
TEXT_DEST_REC dest;
|
|
|
|
FORMAT_REC *formats;
|
|
|
|
char *str;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
create_dest_rec(&dest, server, target, level, NULL);
|
2000-07-31 17:16:09 -04:00
|
|
|
theme = dest.window->theme == NULL ? current_theme :
|
|
|
|
dest.window->theme;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
signal_emit_id(signal_print_format, 5, theme, module,
|
|
|
|
&dest, GINT_TO_POINTER(formatnum), va);
|
|
|
|
|
2000-07-31 17:16:09 -04:00
|
|
|
module_theme = g_hash_table_lookup(theme->modules, module);
|
2000-05-15 04:25:45 -04:00
|
|
|
formats = g_hash_table_lookup(default_formats, module);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
str = output_format_text_args(&dest, &formats[formatnum],
|
2000-10-27 19:06:26 -04:00
|
|
|
module_theme->expanded_formats[formatnum], va);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (*str != '\0') print_string(&dest, str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
void printformat_module(const char *module, void *server, const char *target, int level, int formatnum, ...)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
|
|
|
va_list va;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
va_start(va, formatnum);
|
2000-10-27 23:01:11 -04:00
|
|
|
printformat_module_args(module, server, target, level, formatnum, va);
|
2000-05-15 04:25:45 -04:00
|
|
|
va_end(va);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
void printformat_module_window_args(const char *module, WINDOW_REC *window,
|
|
|
|
int level, int formatnum, va_list va)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-07-31 17:16:09 -04:00
|
|
|
THEME_REC *theme;
|
|
|
|
MODULE_THEME_REC *module_theme;
|
2000-05-15 04:25:45 -04:00
|
|
|
TEXT_DEST_REC dest;
|
|
|
|
FORMAT_REC *formats;
|
|
|
|
char *str;
|
|
|
|
|
2000-07-31 17:16:09 -04:00
|
|
|
create_dest_rec(&dest, NULL, NULL, level, window);
|
|
|
|
theme = window->theme == NULL ? current_theme :
|
|
|
|
window->theme;
|
2000-05-15 04:25:45 -04:00
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
signal_emit_id(signal_print_format, 5, theme, module,
|
|
|
|
&dest, GINT_TO_POINTER(formatnum), va);
|
|
|
|
|
|
|
|
module_theme = g_hash_table_lookup(theme->modules, module);
|
2000-05-15 04:25:45 -04:00
|
|
|
formats = g_hash_table_lookup(default_formats, module);
|
2000-10-27 23:01:11 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
str = output_format_text_args(&dest, &formats[formatnum],
|
2000-10-27 19:06:26 -04:00
|
|
|
module_theme->expanded_formats[formatnum], va);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (*str != '\0') print_string(&dest, str);
|
|
|
|
g_free(str);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
void printformat_module_window(const char *module, WINDOW_REC *window,
|
|
|
|
int level, int formatnum, ...)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, formatnum);
|
|
|
|
printformat_module_window_args(module, window, level, formatnum, va);
|
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
2000-07-15 16:04:44 -04:00
|
|
|
#define LINE_START_IRSSI_LEVEL \
|
|
|
|
(MSGLEVEL_CLIENTERROR | MSGLEVEL_CLIENTNOTICE)
|
|
|
|
|
|
|
|
#define NOT_LINE_START_LEVEL \
|
2000-10-14 10:34:40 -04:00
|
|
|
(MSGLEVEL_NEVER | MSGLEVEL_LASTLOG | MSGLEVEL_CLIENTCRAP | \
|
|
|
|
MSGLEVEL_MSGS | MSGLEVEL_PUBLIC | MSGLEVEL_DCC | MSGLEVEL_DCCMSGS | \
|
2000-07-15 16:04:44 -04:00
|
|
|
MSGLEVEL_ACTIONS | MSGLEVEL_NOTICES | MSGLEVEL_SNOTES | MSGLEVEL_CTCPS)
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* return the "-!- " text at the start of the line */
|
2000-10-27 23:01:11 -04:00
|
|
|
char *get_line_start_text(TEXT_DEST_REC *dest)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-07-15 16:04:44 -04:00
|
|
|
if (dest->level & LINE_START_IRSSI_LEVEL)
|
2000-05-15 04:25:45 -04:00
|
|
|
return output_format_text(dest, IRCTXT_LINE_START_IRSSI);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-07-15 16:04:44 -04:00
|
|
|
if ((dest->level & NOT_LINE_START_LEVEL) == 0)
|
2000-05-15 04:25:45 -04:00
|
|
|
return output_format_text(dest, IRCTXT_LINE_START);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
static void print_string(TEXT_DEST_REC *dest, const char *text)
|
|
|
|
{
|
|
|
|
gpointer levelp;
|
|
|
|
char *str, *tmp;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
g_return_if_fail(dest != NULL);
|
|
|
|
g_return_if_fail(text != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
tmp = get_line_start_text(dest);
|
|
|
|
str = tmp == NULL ? (char *) text :
|
|
|
|
g_strconcat(tmp, text, NULL);
|
|
|
|
g_free_not_null(tmp);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
levelp = GINT_TO_POINTER(dest->level);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* send the plain text version for logging etc.. */
|
|
|
|
tmp = strip_codes(str);
|
2000-10-27 23:01:11 -04:00
|
|
|
signal_emit_id(signal_print_text_stripped, 5, dest->window, dest->server, dest->target, levelp, tmp);
|
2000-05-15 04:25:45 -04:00
|
|
|
g_free(tmp);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
signal_emit_id(signal_print_text, 5, dest->window, dest->server, dest->target, levelp, str);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (str != text) g_free(str);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-11 18:58:17 -04:00
|
|
|
/* append string to `out', expand newlines. */
|
|
|
|
static void printtext_append_str(TEXT_DEST_REC *dest, GString *out, const char *str)
|
|
|
|
{
|
|
|
|
while (*str != '\0') {
|
|
|
|
if (*str != '\n')
|
|
|
|
g_string_append_c(out, *str);
|
|
|
|
else {
|
|
|
|
print_string(dest, out->str);
|
|
|
|
g_string_truncate(out, 0);
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
static char *printtext_get_args(TEXT_DEST_REC *dest, const char *str, va_list va)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
GString *out;
|
2000-05-15 04:25:45 -04:00
|
|
|
char *ret;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
out = g_string_new(NULL);
|
2000-05-15 04:25:45 -04:00
|
|
|
for (; *str != '\0'; str++) {
|
|
|
|
if (*str != '%') {
|
|
|
|
g_string_append_c(out, *str);
|
|
|
|
continue;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
if (*++str == '\0')
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* standard parameters */
|
|
|
|
switch (*str) {
|
|
|
|
case 's': {
|
|
|
|
char *s = (char *) va_arg(va, char *);
|
2000-06-11 18:58:17 -04:00
|
|
|
if (s && *s) printtext_append_str(dest, out, s);
|
2000-05-15 04:25:45 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'd': {
|
|
|
|
int d = (int) va_arg(va, int);
|
|
|
|
g_string_sprintfa(out, "%d", d);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'f': {
|
|
|
|
double f = (double) va_arg(va, double);
|
|
|
|
g_string_sprintfa(out, "%0.2f", f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'u': {
|
|
|
|
unsigned int d = (unsigned int) va_arg(va, unsigned int);
|
|
|
|
g_string_sprintfa(out, "%u", d);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'l': {
|
|
|
|
long d = (long) va_arg(va, long);
|
|
|
|
|
|
|
|
if (*++str != 'd' && *str != 'u') {
|
|
|
|
g_string_sprintfa(out, "%ld", d);
|
|
|
|
str--;
|
|
|
|
} else {
|
|
|
|
if (*str == 'd')
|
|
|
|
g_string_sprintfa(out, "%ld", d);
|
|
|
|
else
|
|
|
|
g_string_sprintfa(out, "%lu", d);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
if (!expand_styles(out, *str, dest)) {
|
|
|
|
g_string_append_c(out, '%');
|
|
|
|
g_string_append_c(out, *str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
ret = out->str;
|
|
|
|
g_string_free(out, FALSE);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
/* Write text to target - convert color codes */
|
|
|
|
void printtext(void *server, const char *target, int level, const char *text, ...)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
|
|
|
TEXT_DEST_REC dest;
|
|
|
|
char *str;
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
g_return_if_fail(text != NULL);
|
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
create_dest_rec(&dest, server, target, level, NULL);
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
va_start(va, text);
|
|
|
|
str = printtext_get_args(&dest, text, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
print_string(&dest, str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void printtext_window(WINDOW_REC *window, int level, const char *text, ...)
|
|
|
|
{
|
|
|
|
TEXT_DEST_REC dest;
|
|
|
|
char *str;
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
g_return_if_fail(text != NULL);
|
|
|
|
|
2000-07-31 17:16:09 -04:00
|
|
|
create_dest_rec(&dest, NULL, NULL, level,
|
|
|
|
window != NULL ? window : active_win);
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
va_start(va, text);
|
|
|
|
str = printtext_get_args(&dest, text, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
print_string(&dest, str);
|
|
|
|
g_free(str);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void newline(WINDOW_REC *window)
|
|
|
|
{
|
|
|
|
window->lines++;
|
|
|
|
if (window->lines != 1) {
|
|
|
|
signal_emit_id(signal_gui_print_text, 6, window,
|
|
|
|
GINT_TO_POINTER(-1), GINT_TO_POINTER(-1),
|
|
|
|
GINT_TO_POINTER(0), "\n", GINT_TO_POINTER(-1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
#define show_timestamp(level) \
|
2000-10-13 18:17:37 -04:00
|
|
|
((level & (MSGLEVEL_NEVER|MSGLEVEL_LASTLOG)) == 0 && \
|
2000-05-15 04:25:45 -04:00
|
|
|
(timestamps || (msgs_timestamps && ((level) & MSGLEVEL_MSGS))))
|
|
|
|
|
|
|
|
static char *get_timestamp(TEXT_DEST_REC *dest)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
struct tm *tm;
|
|
|
|
time_t t;
|
|
|
|
int diff;
|
|
|
|
|
|
|
|
if (!show_timestamp(dest->level))
|
|
|
|
return NULL;
|
|
|
|
|
2000-06-15 06:39:24 -04:00
|
|
|
t = time(NULL);
|
2000-05-15 04:25:45 -04:00
|
|
|
|
2000-06-15 06:39:24 -04:00
|
|
|
if (timestamp_timeout > 0) {
|
2000-06-14 18:31:59 -04:00
|
|
|
diff = t - dest->window->last_timestamp;
|
|
|
|
dest->window->last_timestamp = t;
|
|
|
|
if (diff < timestamp_timeout)
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
tm = localtime(&t);
|
|
|
|
return output_format_text(dest, IRCTXT_TIMESTAMP,
|
|
|
|
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
|
2000-07-01 17:15:53 -04:00
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2000-06-30 15:49:12 -04:00
|
|
|
static char *get_server_tag(TEXT_DEST_REC *dest)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
2000-06-30 15:49:12 -04:00
|
|
|
SERVER_REC *server;
|
|
|
|
|
|
|
|
server = dest->server;
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
if (server == NULL || servers == NULL || servers->next == NULL ||
|
2000-06-30 15:49:12 -04:00
|
|
|
(dest->window->active != NULL && dest->window->active->server == server))
|
2000-05-15 04:25:45 -04:00
|
|
|
return NULL;
|
|
|
|
|
2000-06-30 15:49:12 -04:00
|
|
|
return output_format_text(dest, IRCTXT_SERVERTAG, server->tag);
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
|
|
|
|
2000-07-30 13:32:55 -04:00
|
|
|
static void msg_beep_check(SERVER_REC *server, int level)
|
|
|
|
{
|
2000-07-31 11:36:40 -04:00
|
|
|
if (level != 0 && (level & MSGLEVEL_NOHILIGHT) == 0 &&
|
|
|
|
(beep_msg_level & level) &&
|
2000-07-30 13:32:55 -04:00
|
|
|
(beep_when_away || (server != NULL && !server->usermode_away))) {
|
|
|
|
printbeep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_print_text(WINDOW_REC *window, SERVER_REC *server,
|
|
|
|
const char *target, gpointer level,
|
|
|
|
const char *text)
|
2000-05-15 04:25:45 -04:00
|
|
|
{
|
|
|
|
TEXT_DEST_REC dest;
|
2000-07-30 13:32:55 -04:00
|
|
|
char *dup, *ptr, type, *str, *timestamp, *servertag;
|
|
|
|
int fgcolor, bgcolor;
|
|
|
|
int flags;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_return_if_fail(text != NULL);
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
2000-07-31 17:16:09 -04:00
|
|
|
create_dest_rec(&dest, server, target, GPOINTER_TO_INT(level), window);
|
2000-07-30 13:32:55 -04:00
|
|
|
msg_beep_check(server, dest.level);
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
flags = 0; fgcolor = -1; bgcolor = -1; type = '\0';
|
2000-05-04 06:32:42 -04:00
|
|
|
window->last_line = time(NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
newline(window);
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
timestamp = get_timestamp(&dest);
|
2000-06-30 15:49:12 -04:00
|
|
|
servertag = get_server_tag(&dest);
|
2000-05-15 04:25:45 -04:00
|
|
|
str = g_strconcat(timestamp != NULL ? timestamp : "",
|
|
|
|
servertag != NULL ? servertag : "",
|
|
|
|
text, NULL);
|
|
|
|
g_free_not_null(timestamp);
|
|
|
|
g_free_not_null(servertag);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
dup = str;
|
2000-04-26 04:03:38 -04:00
|
|
|
while (*str != '\0')
|
|
|
|
{
|
|
|
|
for (ptr = str; *ptr != '\0'; ptr++)
|
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
if (is_color_code(*ptr))
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
type = *ptr;
|
|
|
|
*ptr++ = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-07-30 13:32:55 -04:00
|
|
|
*ptr = (char) translation_in[(gint) (guchar) *ptr];
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type == 7)
|
|
|
|
{
|
|
|
|
/* bell */
|
2000-05-04 06:32:42 -04:00
|
|
|
if (settings_get_bool("bell_beeps"))
|
2000-04-26 04:03:38 -04:00
|
|
|
flags |= PRINTFLAG_BEEP;
|
|
|
|
}
|
|
|
|
if (*str != '\0' || flags & PRINTFLAG_BEEP)
|
|
|
|
{
|
|
|
|
signal_emit_id(signal_gui_print_text, 6, window,
|
|
|
|
GINT_TO_POINTER(fgcolor), GINT_TO_POINTER(bgcolor),
|
|
|
|
GINT_TO_POINTER(flags), str, level);
|
|
|
|
flags &= ~(PRINTFLAG_BEEP|PRINTFLAG_INDENT);
|
|
|
|
}
|
|
|
|
if (*ptr == '\0') break;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
/* bold */
|
2000-05-04 06:32:42 -04:00
|
|
|
if (!hide_text_style)
|
2000-04-26 04:03:38 -04:00
|
|
|
flags ^= PRINTFLAG_BOLD;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
/* blink */
|
2000-05-04 06:32:42 -04:00
|
|
|
if (!hide_text_style)
|
2000-04-26 04:03:38 -04:00
|
|
|
flags ^= PRINTFLAG_BLINK;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
/* remove all styling */
|
|
|
|
flags &= PRINTFLAG_BEEP;
|
|
|
|
fgcolor = bgcolor = -1;
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
/* reverse */
|
2000-05-04 06:32:42 -04:00
|
|
|
if (!hide_text_style)
|
2000-04-26 04:03:38 -04:00
|
|
|
flags ^= PRINTFLAG_REVERSE;
|
|
|
|
break;
|
|
|
|
case 31:
|
|
|
|
/* underline */
|
2000-05-04 06:32:42 -04:00
|
|
|
if (!hide_text_style)
|
2000-04-26 04:03:38 -04:00
|
|
|
flags ^= PRINTFLAG_UNDERLINE;
|
|
|
|
case 27:
|
|
|
|
/* ansi color code */
|
2000-07-31 17:16:09 -04:00
|
|
|
ptr = convert_ansi(window->theme == NULL ? current_theme :
|
|
|
|
window->theme, ptr, &fgcolor, &bgcolor, &flags);
|
2000-04-26 04:03:38 -04:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
/* user specific colors */
|
|
|
|
flags &= ~PRINTFLAG_MIRC_COLOR;
|
|
|
|
if ((signed char) *ptr == -1)
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
if ((signed char) *ptr == -1)
|
|
|
|
{
|
|
|
|
fgcolor = bgcolor = -1;
|
|
|
|
flags &= PRINTFLAG_INDENT;
|
|
|
|
}
|
|
|
|
else if (*ptr == 1)
|
|
|
|
flags ^= PRINTFLAG_BOLD;
|
|
|
|
else if (*ptr == 2)
|
|
|
|
flags ^= PRINTFLAG_UNDERLINE;
|
|
|
|
else if (*ptr == 3)
|
|
|
|
flags ^= PRINTFLAG_REVERSE;
|
|
|
|
else if (*ptr == 4)
|
|
|
|
flags |= PRINTFLAG_INDENT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((signed char) *ptr != -2)
|
|
|
|
{
|
|
|
|
fgcolor = (guchar) *ptr-1;
|
|
|
|
if (fgcolor <= 7)
|
|
|
|
flags &= ~PRINTFLAG_BOLD;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* bold */
|
|
|
|
if (fgcolor != 8) fgcolor -= 8;
|
|
|
|
flags |= PRINTFLAG_BOLD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
if ((signed char) *ptr != -2)
|
|
|
|
bgcolor = (signed char) *ptr == -1 ? -1 : *ptr-1;
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (*ptr < 17)
|
|
|
|
{
|
|
|
|
/* mostly just for irssi's internal use.. */
|
|
|
|
fgcolor = (*ptr++)-1;
|
|
|
|
if (*ptr == 0 || *ptr >= 17)
|
|
|
|
bgcolor = -1;
|
|
|
|
else
|
|
|
|
bgcolor = (*ptr++)-1;
|
|
|
|
if (fgcolor & 8)
|
|
|
|
flags |= PRINTFLAG_BOLD;
|
|
|
|
else
|
|
|
|
flags &= ~PRINTFLAG_BOLD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MIRC color */
|
2000-05-04 06:32:42 -04:00
|
|
|
if (hide_text_style)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
/* don't show them. */
|
2000-05-15 04:25:45 -04:00
|
|
|
skip_mirc_color(&ptr);
|
2000-04-26 04:03:38 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags |= PRINTFLAG_MIRC_COLOR;
|
|
|
|
if (!isdigit((gint) *ptr) && *ptr != ',')
|
|
|
|
{
|
|
|
|
fgcolor = -1;
|
|
|
|
bgcolor = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* foreground color */
|
|
|
|
if (*ptr != ',')
|
|
|
|
{
|
|
|
|
fgcolor = *ptr++-'0';
|
|
|
|
if (isdigit((gint) *ptr))
|
|
|
|
fgcolor = fgcolor*10 + (*ptr++-'0');
|
|
|
|
}
|
|
|
|
if (*ptr == ',')
|
|
|
|
{
|
|
|
|
/* back color */
|
|
|
|
bgcolor = 0;
|
|
|
|
if (!isdigit((gint) *++ptr))
|
|
|
|
bgcolor = -1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bgcolor = *ptr++-'0';
|
|
|
|
if (isdigit((gint) *ptr))
|
|
|
|
bgcolor = bgcolor*10 + (*ptr++-'0');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
str = ptr;
|
|
|
|
}
|
|
|
|
g_free(dup);
|
|
|
|
signal_emit_id(signal_print_text_finished, 1, window);
|
|
|
|
}
|
|
|
|
|
2000-10-27 23:01:11 -04:00
|
|
|
void printtext_multiline(void *server, const char *target, int level, const char *format, const char *text)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
char **lines, **tmp;
|
|
|
|
|
2000-09-29 19:57:30 -04:00
|
|
|
g_return_if_fail(format != NULL);
|
|
|
|
g_return_if_fail(text != NULL);
|
|
|
|
|
2000-04-28 04:07:42 -04:00
|
|
|
lines = g_strsplit(text, "\n", -1);
|
|
|
|
for (tmp = lines; *tmp != NULL; tmp++)
|
|
|
|
printtext(NULL, NULL, MSGLEVEL_NEVER, format, *tmp);
|
|
|
|
g_strfreev(lines);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_gui_dialog(const char *type, const char *text)
|
|
|
|
{
|
|
|
|
char *format;
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
if (g_strcasecmp(type, "warning") == 0)
|
2000-04-28 04:07:42 -04:00
|
|
|
format = _("%_Warning:%_ %s");
|
2000-04-26 04:03:38 -04:00
|
|
|
else if (g_strcasecmp(type, "error") == 0)
|
2000-04-28 04:07:42 -04:00
|
|
|
format = _("%_Error:%_ %s");
|
2000-04-26 04:03:38 -04:00
|
|
|
else
|
2000-04-28 04:07:42 -04:00
|
|
|
format = "%s";
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-04-28 04:07:42 -04:00
|
|
|
printtext_multiline(NULL, NULL, MSGLEVEL_NEVER, format, text);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void read_settings(void)
|
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
timestamps = settings_get_bool("timestamps");
|
2000-05-19 05:17:53 -04:00
|
|
|
timestamp_timeout = settings_get_int("timestamp_timeout");
|
2000-05-15 04:25:45 -04:00
|
|
|
msgs_timestamps = settings_get_bool("msgs_timestamps");
|
|
|
|
hide_text_style = settings_get_bool("hide_text_style");
|
2000-07-30 13:32:55 -04:00
|
|
|
beep_msg_level = level2bits(settings_get_str("beep_on_msg"));
|
|
|
|
beep_when_away = settings_get_bool("beep_when_away");
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void printtext_init(void)
|
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
settings_add_int("misc", "timestamp_timeout", 0);
|
|
|
|
|
2000-06-25 19:39:23 -04:00
|
|
|
signal_gui_print_text = signal_get_uniq_id("gui print text");
|
|
|
|
signal_print_text_stripped = signal_get_uniq_id("print text stripped");
|
|
|
|
signal_print_text = signal_get_uniq_id("print text");
|
|
|
|
signal_print_text_finished = signal_get_uniq_id("print text finished");
|
2000-10-27 23:01:11 -04:00
|
|
|
signal_print_format = signal_get_uniq_id("print format");
|
2000-05-15 04:25:45 -04:00
|
|
|
|
|
|
|
read_settings();
|
|
|
|
signal_add("print text", (SIGNAL_FUNC) sig_print_text);
|
|
|
|
signal_add("gui dialog", (SIGNAL_FUNC) sig_gui_dialog);
|
|
|
|
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void printtext_deinit(void)
|
|
|
|
{
|
2000-05-15 04:25:45 -04:00
|
|
|
signal_remove("print text", (SIGNAL_FUNC) sig_print_text);
|
|
|
|
signal_remove("gui dialog", (SIGNAL_FUNC) sig_gui_dialog);
|
|
|
|
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|