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 "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-10-28 16:14:19 -04:00
|
|
|
#include "printtext.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
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
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
static void print_line(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-10-28 16:14:19 -04:00
|
|
|
static void get_mirc_color(const char **str, int *fg_ret, int *bg_ret)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-10-28 16:14:19 -04:00
|
|
|
int fg, bg;
|
|
|
|
|
|
|
|
fg = fg_ret == NULL ? -1 : *fg_ret;
|
|
|
|
bg = bg_ret == NULL ? -1 : *bg_ret;
|
|
|
|
|
|
|
|
if (!isdigit((int) **str) && **str != ',') {
|
|
|
|
fg = -1;
|
|
|
|
bg = -1;
|
|
|
|
} else {
|
|
|
|
/* foreground color */
|
|
|
|
if (**str != ',') {
|
|
|
|
fg = **str-'0';
|
|
|
|
(*str)++;
|
|
|
|
if (isdigit((int) **str)) {
|
|
|
|
fg = fg*10 + (**str-'0');
|
|
|
|
(*str)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (**str == ',') {
|
|
|
|
/* background color */
|
|
|
|
(*str)++;
|
|
|
|
if (!isdigit((int) **str))
|
|
|
|
bg = -1;
|
|
|
|
else {
|
|
|
|
bg = **str-'0';
|
|
|
|
(*str)++;
|
|
|
|
if (isdigit((int) **str)) {
|
|
|
|
bg = bg*10 + (**str-'0');
|
|
|
|
(*str)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
if (fg_ret) *fg_ret = fg;
|
|
|
|
if (bg_ret) *bg_ret = bg;
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
#define IS_COLOR_CODE(c) \
|
2000-05-15 04:25:45 -04:00
|
|
|
((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++;
|
|
|
|
|
|
|
|
/* mirc color */
|
2000-10-28 16:14:19 -04:00
|
|
|
get_mirc_color(&p, NULL, NULL);
|
2000-05-15 04:25:45 -04:00
|
|
|
p--;
|
|
|
|
continue;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
if (*p == 4 && p[1] != '\0') {
|
|
|
|
if (p[1] >= FORMAT_STYLE_SPECIAL) {
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
/* irssi color */
|
2000-10-28 16:14:19 -04:00
|
|
|
if (p[2] != '\0') {
|
|
|
|
p += 2;
|
|
|
|
continue;
|
|
|
|
}
|
2000-05-15 04:25:45 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
if (!IS_COLOR_CODE(*p))
|
2000-05-15 04:25:45 -04:00
|
|
|
*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-10-28 16:14:19 -04:00
|
|
|
static char *get_ansi_color(THEME_REC *theme, char *str,
|
|
|
|
int *fg_ret, int *bg_ret, int *flags_ret)
|
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;
|
2000-10-28 16:14:19 -04:00
|
|
|
int fg, bg, flags, 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-10-28 16:14:19 -04:00
|
|
|
fg = fg_ret == NULL || *fg_ret < 0 ? theme->default_color : *fg_ret;
|
|
|
|
bg = bg_ret == NULL || *bg_ret < 0 ? -1 : *bg_ret;
|
|
|
|
flags = flags_ret == NULL ? 0 : *flags_ret;
|
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-10-28 16:14:19 -04:00
|
|
|
flags &= ~(PRINTFLAG_BEEP|PRINTFLAG_INDENT);
|
2000-05-15 04:25:45 -04:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* hilight */
|
2000-10-28 16:14:19 -04:00
|
|
|
flags |= PRINTFLAG_BOLD;
|
2000-05-15 04:25:45 -04:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
/* blink */
|
2000-10-28 16:14:19 -04:00
|
|
|
flags |= PRINTFLAG_BLINK;
|
2000-05-15 04:25:45 -04:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
/* reverse */
|
2000-10-28 16:14:19 -04:00
|
|
|
flags |= PRINTFLAG_REVERSE;
|
2000-05-15 04:25:45 -04:00
|
|
|
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') {
|
2000-10-28 16:14:19 -04:00
|
|
|
if (fg_ret != NULL) *fg_ret = fg;
|
|
|
|
if (bg_ret != NULL) *bg_ret = bg;
|
|
|
|
if (flags_ret != NULL) *flags_ret = flags;
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
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-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;
|
2000-05-15 04:25:45 -04:00
|
|
|
TEXT_DEST_REC dest;
|
|
|
|
char *str;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
format_create_dest(&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-10-28 16:14:19 -04:00
|
|
|
str = format_get_text_theme_args(theme, module, &dest, formatnum, va);
|
|
|
|
if (*str != '\0') print_line(&dest, str);
|
2000-05-15 04:25:45 -04:00
|
|
|
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;
|
2000-05-15 04:25:45 -04:00
|
|
|
TEXT_DEST_REC dest;
|
|
|
|
char *str;
|
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
format_create_dest(&dest, NULL, NULL, level, window);
|
2000-07-31 17:16:09 -04:00
|
|
|
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);
|
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
str = format_get_text_theme_args(theme, module, &dest, formatnum, va);
|
|
|
|
if (*str != '\0') print_line(&dest, str);
|
2000-05-15 04:25:45 -04:00
|
|
|
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-10-28 16:14:19 -04:00
|
|
|
static void print_line(TEXT_DEST_REC *dest, const char *text)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-10-28 16:14:19 -04:00
|
|
|
void *levelp;
|
2000-05-15 04:25:45 -04:00
|
|
|
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-10-28 16:14:19 -04:00
|
|
|
tmp = format_get_line_start(current_theme, dest);
|
|
|
|
str = format_add_linestart(text, tmp);
|
2000-05-15 04:25:45 -04:00
|
|
|
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-10-28 16:14:19 -04:00
|
|
|
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 {
|
2000-10-28 16:14:19 -04:00
|
|
|
print_line(dest, out->str);
|
2000-06-11 18:58:17 -04:00
|
|
|
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:
|
2000-10-28 16:14:19 -04:00
|
|
|
if (!format_expand_styles(out, *str, dest)) {
|
2000-05-15 04:25:45 -04:00
|
|
|
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-28 16:14:19 -04:00
|
|
|
format_create_dest(&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);
|
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
print_line(&dest, str);
|
2000-05-15 04:25:45 -04:00
|
|
|
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-10-28 16:14:19 -04:00
|
|
|
format_create_dest(&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);
|
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
print_line(&dest, str);
|
2000-05-15 04:25:45 -04:00
|
|
|
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);
|
2000-10-28 16:14:19 -04:00
|
|
|
return format_get_text_theme(NULL, MODULE_NAME, dest, IRCTXT_TIMESTAMP,
|
|
|
|
tm->tm_year+1900,
|
|
|
|
tm->tm_mon+1, tm->tm_mday,
|
|
|
|
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-10-28 16:14:19 -04:00
|
|
|
return format_get_text_theme(NULL, MODULE_NAME, 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
static char *fix_line_start(TEXT_DEST_REC *dest, const char *text)
|
|
|
|
{
|
|
|
|
char *timestamp, *servertag;
|
|
|
|
char *linestart, *str;
|
|
|
|
|
|
|
|
timestamp = get_timestamp(dest);
|
|
|
|
servertag = get_server_tag(dest);
|
|
|
|
|
|
|
|
if (timestamp == NULL && servertag == NULL)
|
|
|
|
return g_strdup(text);
|
|
|
|
|
|
|
|
linestart = g_strconcat(timestamp != NULL ? timestamp : "",
|
|
|
|
servertag, NULL);
|
|
|
|
str = format_add_linestart(text, linestart);
|
|
|
|
g_free(linestart);
|
|
|
|
|
|
|
|
g_free_not_null(timestamp);
|
|
|
|
g_free_not_null(servertag);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2000-07-30 13:32:55 -04:00
|
|
|
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
|
|
|
{
|
2000-10-28 16:14:19 -04:00
|
|
|
TEXT_DEST_REC dest;
|
|
|
|
char *dup, *ptr, type, *str;
|
|
|
|
int fgcolor, bgcolor;
|
|
|
|
int flags;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
g_return_if_fail(text != NULL);
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
|
|
|
format_create_dest(&dest, server, target,
|
|
|
|
GPOINTER_TO_INT(level), window);
|
|
|
|
msg_beep_check(server, dest.level);
|
|
|
|
|
|
|
|
window->last_line = time(NULL);
|
|
|
|
newline(window);
|
|
|
|
|
|
|
|
dup = str = fix_line_start(&dest, text);
|
|
|
|
flags = 0; fgcolor = -1; bgcolor = -1; type = '\0';
|
|
|
|
while (*str != '\0') {
|
|
|
|
for (ptr = str; *ptr != '\0'; ptr++) {
|
|
|
|
if (IS_COLOR_CODE(*ptr)) {
|
|
|
|
type = *ptr;
|
|
|
|
*ptr++ = '\0';
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
*ptr = (char) translation_in[(int) (unsigned char) *ptr];
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
if (type == 7) {
|
|
|
|
/* bell */
|
|
|
|
if (settings_get_bool("bell_beeps"))
|
|
|
|
flags |= PRINTFLAG_BEEP;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2000-10-28 16:14:19 -04:00
|
|
|
if (*str != '\0' || flags & PRINTFLAG_BEEP) {
|
|
|
|
/* send the text to gui handler */
|
|
|
|
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)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-10-28 16:14:19 -04:00
|
|
|
case 2:
|
|
|
|
/* bold */
|
|
|
|
if (!hide_text_style)
|
|
|
|
flags ^= PRINTFLAG_BOLD;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
/* blink */
|
|
|
|
if (!hide_text_style)
|
|
|
|
flags ^= PRINTFLAG_BLINK;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
/* remove all styling */
|
|
|
|
flags &= PRINTFLAG_BEEP;
|
|
|
|
fgcolor = bgcolor = -1;
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
/* reverse */
|
|
|
|
if (!hide_text_style)
|
|
|
|
flags ^= PRINTFLAG_REVERSE;
|
|
|
|
break;
|
|
|
|
case 31:
|
|
|
|
/* underline */
|
|
|
|
if (!hide_text_style)
|
|
|
|
flags ^= PRINTFLAG_UNDERLINE;
|
|
|
|
case 27:
|
|
|
|
/* ansi color code */
|
|
|
|
ptr = get_ansi_color(window->theme == NULL ?
|
|
|
|
current_theme : window->theme,
|
|
|
|
ptr,
|
|
|
|
hide_text_style ? NULL : &fgcolor,
|
|
|
|
hide_text_style ? NULL : &bgcolor,
|
|
|
|
hide_text_style ? NULL : &flags);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
/* user specific colors */
|
|
|
|
flags &= ~PRINTFLAG_MIRC_COLOR;
|
|
|
|
switch (*ptr) {
|
|
|
|
case FORMAT_STYLE_UNDERLINE:
|
|
|
|
flags ^= PRINTFLAG_UNDERLINE;
|
|
|
|
break;
|
|
|
|
case FORMAT_STYLE_BOLD:
|
|
|
|
flags ^= PRINTFLAG_BOLD;
|
|
|
|
break;
|
|
|
|
case FORMAT_STYLE_REVERSE:
|
|
|
|
flags ^= PRINTFLAG_REVERSE;
|
|
|
|
break;
|
|
|
|
case FORMAT_STYLE_INDENT:
|
|
|
|
flags |= PRINTFLAG_INDENT;
|
|
|
|
break;
|
|
|
|
case FORMAT_STYLE_DEFAULTS:
|
|
|
|
fgcolor = bgcolor = -1;
|
|
|
|
flags &= PRINTFLAG_INDENT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*ptr != FORMAT_COLOR_NOCHANGE) {
|
|
|
|
fgcolor = (unsigned char) *ptr-'0';
|
|
|
|
if (fgcolor <= 7)
|
|
|
|
flags &= ~PRINTFLAG_BOLD;
|
|
|
|
else {
|
|
|
|
/* bold */
|
|
|
|
if (fgcolor != 8) fgcolor -= 8;
|
|
|
|
flags |= PRINTFLAG_BOLD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
if (*ptr != FORMAT_COLOR_NOCHANGE)
|
|
|
|
bgcolor = *ptr-'0';
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2000-10-28 16:14:19 -04:00
|
|
|
ptr++;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
/* MIRC color */
|
|
|
|
get_mirc_color((const char **) &ptr,
|
|
|
|
hide_text_style ? NULL : &fgcolor,
|
|
|
|
hide_text_style ? NULL : &bgcolor);
|
|
|
|
if (!hide_text_style)
|
|
|
|
flags |= PRINTFLAG_MIRC_COLOR;
|
|
|
|
break;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-10-28 16:14:19 -04:00
|
|
|
str = ptr;
|
|
|
|
}
|
|
|
|
g_free(dup);
|
|
|
|
signal_emit_id(signal_print_text_finished, 1, window);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-10-28 16:14:19 -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
|
|
|
}
|