mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Added gui_printtext() function for printing text in printtext() format
to screen in specified position. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1182 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
e9b48e8942
commit
e2acaaa067
@ -55,7 +55,7 @@ int format_find_tag(const char *module, const char *tag)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int format_expand_styles(GString *out, char format, TEXT_DEST_REC *dest)
|
||||
int format_expand_styles(GString *out, char format)
|
||||
{
|
||||
static const char *backs = "04261537";
|
||||
static const char *fores = "kbgcrmyw";
|
||||
@ -228,7 +228,7 @@ static char *format_get_text_args(TEXT_DEST_REC *dest,
|
||||
while (*text != '\0') {
|
||||
if (code == '%') {
|
||||
/* color code */
|
||||
if (!format_expand_styles(out, *text, dest)) {
|
||||
if (!format_expand_styles(out, *text)) {
|
||||
g_string_append_c(out, '%');
|
||||
g_string_append_c(out, '%');
|
||||
g_string_append_c(out, *text);
|
||||
@ -465,6 +465,8 @@ char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest, time_t t)
|
||||
|
||||
void format_newline(WINDOW_REC *window)
|
||||
{
|
||||
g_return_if_fail(window != NULL);
|
||||
|
||||
window->lines++;
|
||||
if (window->lines != 1) {
|
||||
signal_emit_id(signal_gui_print_text, 6, window,
|
||||
@ -789,7 +791,7 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text)
|
||||
break;
|
||||
case 27:
|
||||
/* ansi color code */
|
||||
ptr = get_ansi_color(dest->window->theme == NULL ?
|
||||
ptr = get_ansi_color(dest->window == NULL || dest->window->theme == NULL ?
|
||||
current_theme : dest->window->theme,
|
||||
ptr,
|
||||
hide_text_style ? NULL : &fgcolor,
|
||||
|
@ -98,7 +98,7 @@ void format_send_to_gui(TEXT_DEST_REC *dest, const char *text);
|
||||
#define FORMAT_STYLE_REVERSE (0x03 + FORMAT_STYLE_SPECIAL)
|
||||
#define FORMAT_STYLE_INDENT (0x04 + FORMAT_STYLE_SPECIAL)
|
||||
#define FORMAT_STYLE_DEFAULTS (0x05 + FORMAT_STYLE_SPECIAL)
|
||||
int format_expand_styles(GString *out, char format, TEXT_DEST_REC *dest);
|
||||
int format_expand_styles(GString *out, char format);
|
||||
|
||||
void formats_init(void);
|
||||
void formats_deinit(void);
|
||||
|
@ -77,7 +77,8 @@ static void printformat_module_dest(const char *module, TEXT_DEST_REC *dest,
|
||||
signal_emit_id(signal_print_format, 5, theme, module,
|
||||
dest, GINT_TO_POINTER(formatnum), arglist);
|
||||
|
||||
str = format_get_text_theme_charargs(theme, module, dest, formatnum, arglist);
|
||||
str = format_get_text_theme_charargs(theme, module, dest,
|
||||
formatnum, arglist);
|
||||
if (*str != '\0') print_line(dest, str);
|
||||
g_free(str);
|
||||
}
|
||||
@ -92,7 +93,8 @@ void printformat_module_args(const char *module, void *server,
|
||||
printformat_module_dest(module, &dest, formatnum, va);
|
||||
}
|
||||
|
||||
void printformat_module(const char *module, void *server, const char *target, int level, int formatnum, ...)
|
||||
void printformat_module(const char *module, void *server, const char *target,
|
||||
int level, int formatnum, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
@ -120,6 +122,38 @@ void printformat_module_window(const char *module, WINDOW_REC *window,
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void printformat_module_gui_args(const char *module, int formatnum, va_list va)
|
||||
{
|
||||
TEXT_DEST_REC dest;
|
||||
char *arglist[MAX_FORMAT_PARAMS];
|
||||
char buffer[DEFAULT_FORMAT_ARGLIST_SIZE];
|
||||
FORMAT_REC *formats;
|
||||
char *str;
|
||||
|
||||
g_return_if_fail(module != NULL);
|
||||
|
||||
memset(&dest, 0, sizeof(dest));
|
||||
|
||||
formats = g_hash_table_lookup(default_formats, module);
|
||||
format_read_arglist(va, &formats[formatnum],
|
||||
arglist, sizeof(arglist)/sizeof(char *),
|
||||
buffer, sizeof(buffer));
|
||||
|
||||
str = format_get_text_theme_charargs(current_theme, module, &dest,
|
||||
formatnum, arglist);
|
||||
if (*str != '\0') format_send_to_gui(&dest, str);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
void printformat_module_gui(const char *module, int formatnum, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
va_start(va, formatnum);
|
||||
printformat_module_gui_args(module, formatnum, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
static void print_line(TEXT_DEST_REC *dest, const char *text)
|
||||
{
|
||||
char *str, *tmp;
|
||||
@ -141,7 +175,8 @@ static void print_line(TEXT_DEST_REC *dest, const char *text)
|
||||
}
|
||||
|
||||
/* append string to `out', expand newlines. */
|
||||
static void printtext_append_str(TEXT_DEST_REC *dest, GString *out, const char *str)
|
||||
static void printtext_append_str(TEXT_DEST_REC *dest, GString *out,
|
||||
const char *str)
|
||||
{
|
||||
while (*str != '\0') {
|
||||
if (*str != '\n')
|
||||
@ -154,7 +189,8 @@ static void printtext_append_str(TEXT_DEST_REC *dest, GString *out, const char *
|
||||
}
|
||||
}
|
||||
|
||||
static char *printtext_get_args(TEXT_DEST_REC *dest, const char *str, va_list va)
|
||||
static char *printtext_get_args(TEXT_DEST_REC *dest, const char *str,
|
||||
va_list va)
|
||||
{
|
||||
GString *out;
|
||||
char *ret;
|
||||
@ -187,7 +223,8 @@ static char *printtext_get_args(TEXT_DEST_REC *dest, const char *str, va_list va
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
unsigned int d = (unsigned int) va_arg(va, unsigned int);
|
||||
unsigned int d =
|
||||
(unsigned int) va_arg(va, unsigned int);
|
||||
g_string_sprintfa(out, "%u", d);
|
||||
break;
|
||||
}
|
||||
@ -206,7 +243,7 @@ static char *printtext_get_args(TEXT_DEST_REC *dest, const char *str, va_list va
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (!format_expand_styles(out, *str, dest)) {
|
||||
if (!format_expand_styles(out, *str)) {
|
||||
g_string_append_c(out, '%');
|
||||
g_string_append_c(out, *str);
|
||||
}
|
||||
@ -219,7 +256,7 @@ static char *printtext_get_args(TEXT_DEST_REC *dest, const char *str, va_list va
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *printtext_expand_formats(TEXT_DEST_REC *dest, const char *str)
|
||||
static char *printtext_expand_formats(const char *str)
|
||||
{
|
||||
GString *out;
|
||||
char *ret;
|
||||
@ -234,7 +271,7 @@ static char *printtext_expand_formats(TEXT_DEST_REC *dest, const char *str)
|
||||
if (*++str == '\0')
|
||||
break;
|
||||
|
||||
if (!format_expand_styles(out, *str, dest)) {
|
||||
if (!format_expand_styles(out, *str)) {
|
||||
g_string_append_c(out, '%');
|
||||
g_string_append_c(out, *str);
|
||||
}
|
||||
@ -291,7 +328,7 @@ void printtext_string(void *server, const char *target, int level, const char *t
|
||||
sending_print_starting = FALSE;
|
||||
}
|
||||
|
||||
str = printtext_expand_formats(&dest, text);
|
||||
str = printtext_expand_formats(text);
|
||||
print_line(&dest, str);
|
||||
g_free(str);
|
||||
}
|
||||
@ -311,6 +348,29 @@ void printtext_window(WINDOW_REC *window, int level, const char *text, ...)
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void printtext_gui_args(const char *text, va_list va)
|
||||
{
|
||||
TEXT_DEST_REC dest;
|
||||
char *str;
|
||||
|
||||
g_return_if_fail(text != NULL);
|
||||
|
||||
memset(&dest, 0, sizeof(dest));
|
||||
|
||||
str = printtext_get_args(&dest, text, va);
|
||||
format_send_to_gui(&dest, str);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
void printtext_gui(const char *text, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
va_start(va, text);
|
||||
printtext_gui_args(text, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
static void msg_beep_check(SERVER_REC *server, int level)
|
||||
{
|
||||
if (level != 0 && (level & MSGLEVEL_NOHILIGHT) == 0 &&
|
||||
|
@ -15,6 +15,13 @@ void printtext_window(WINDOW_REC *window, int level, const char *text, ...);
|
||||
void printtext_multiline(void *server, const char *target, int level, const char *format, const char *text);
|
||||
void printbeep(void);
|
||||
|
||||
/* only GUI should call these - used for printing text to somewhere else
|
||||
than windows */
|
||||
void printtext_gui(const char *text, ...);
|
||||
void printtext_gui_args(const char *text, va_list va);
|
||||
void printformat_module_gui(const char *module, int formatnum, ...);
|
||||
void printformat_module_gui_args(const char *module, int formatnum, va_list va);
|
||||
|
||||
void printtext_init(void);
|
||||
void printtext_deinit(void);
|
||||
|
||||
@ -30,12 +37,16 @@ void printtext_deinit(void);
|
||||
printformat_module(MODULE_NAME, server, target, level, ##formatnum)
|
||||
# define printformat_window(window, level, formatnum...) \
|
||||
printformat_module_window(MODULE_NAME, window, level, ##formatnum)
|
||||
# define printformat_gui(formatnum...) \
|
||||
printformat_module_gui(MODULE_NAME, ##formatnum)
|
||||
#elif defined (_ISOC99_SOURCE)
|
||||
/* C99 */
|
||||
# define printformat(server, target, level, formatnum, ...) \
|
||||
printformat_module(MODULE_NAME, server, target, level, formatnum, __VA_ARGS__)
|
||||
# define printformat_window(window, level, formatnum, ...) \
|
||||
printformat_module_window(MODULE_NAME, window, level, formatnum, __VA_ARGS__)
|
||||
# define printformat_gui(formatnum, ...) \
|
||||
printformat_module_gui(MODULE_NAME, formatnum, __VA_ARGS__)
|
||||
#else
|
||||
/* inline/static */
|
||||
#ifdef G_CAN_INLINE
|
||||
@ -65,6 +76,20 @@ void printformat_window(WINDOW_REC *window, int level, int formatnum, ...)
|
||||
printformat_module_window_args(MODULE_NAME, window, level, formatnum, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
#ifdef G_CAN_INLINE
|
||||
G_INLINE_FUNC
|
||||
#else
|
||||
static
|
||||
#endif
|
||||
void printformat_gui(int formatnum, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
va_start(va, formatnum);
|
||||
printformat_module_gui_args(MODULE_NAME, formatnum, va);
|
||||
va_end(va);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -39,6 +39,8 @@ static int scrollback_lines, scrollback_hours;
|
||||
static int scrollback_save_formats;
|
||||
static GString *format;
|
||||
|
||||
static int next_xpos, next_ypos;
|
||||
|
||||
#define mark_temp_eol(text) \
|
||||
memcpy((text)->buffer + (text)->pos, "\0\200", 2);
|
||||
|
||||
@ -222,6 +224,20 @@ void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line)
|
||||
gui_window_redraw(window);
|
||||
}
|
||||
|
||||
void gui_printtext(int xpos, int ypos, const char *str, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
next_xpos = xpos;
|
||||
next_ypos = ypos;
|
||||
|
||||
va_start(va, str);
|
||||
printtext_gui_args(str, va);
|
||||
va_end(va);
|
||||
|
||||
next_xpos = next_ypos = -1;
|
||||
}
|
||||
|
||||
static void remove_old_lines(WINDOW_REC *window)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
@ -345,28 +361,38 @@ static void line_add_colors(GUI_WINDOW_REC *gui, int fg, int bg, int flags)
|
||||
gui->last_color = fg | (bg << 4);
|
||||
}
|
||||
|
||||
static void gui_printtext(WINDOW_REC *window, void *fgcolor, void *bgcolor,
|
||||
void *pflags, char *str, void *level)
|
||||
static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
|
||||
void *bgcolor, void *pflags,
|
||||
char *str, void *level)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
LINE_REC *line;
|
||||
int fg, bg, flags, new_lines, n, visible, ypos, subline;
|
||||
|
||||
g_return_if_fail(window != NULL);
|
||||
|
||||
remove_old_lines(window);
|
||||
|
||||
gui = WINDOW_GUI(window);
|
||||
visible = is_window_visible(window) && gui->bottom;
|
||||
flags = GPOINTER_TO_INT(pflags);
|
||||
fg = GPOINTER_TO_INT(fgcolor);
|
||||
bg = GPOINTER_TO_INT(bgcolor);
|
||||
get_colors(flags, &fg, &bg);
|
||||
|
||||
if (window == NULL && next_xpos != -1) {
|
||||
wmove(stdscr, next_ypos, next_xpos);
|
||||
set_color(stdscr, fg | (bg << 4));
|
||||
addstr(str);
|
||||
next_xpos += strlen(str);
|
||||
return;
|
||||
}
|
||||
|
||||
g_return_if_fail(window != NULL);
|
||||
|
||||
gui = WINDOW_GUI(window);
|
||||
visible = is_window_visible(window) && gui->bottom;
|
||||
|
||||
if (gui->cur_text == NULL)
|
||||
create_text_chunk(gui);
|
||||
|
||||
/* newline can be only at the start of the line.. */
|
||||
if (flags & PRINTFLAG_NEWLINE) {
|
||||
remove_old_lines(window);
|
||||
if (!gui->eol_marked) {
|
||||
if (format->len > 0 || gui->temp_line != NULL) {
|
||||
/* mark format continuing to next line */
|
||||
@ -389,7 +415,6 @@ static void gui_printtext(WINDOW_REC *window, void *fgcolor, void *bgcolor,
|
||||
if (line->level == 0) line->level = GPOINTER_TO_INT(level);
|
||||
}
|
||||
|
||||
get_colors(flags, &fg, &bg);
|
||||
line_add_colors(gui, fg, bg, flags);
|
||||
linebuf_add(gui, str, strlen(str));
|
||||
mark_temp_eol(gui->cur_text);
|
||||
@ -554,13 +579,14 @@ static void read_settings(void)
|
||||
|
||||
void gui_printtext_init(void)
|
||||
{
|
||||
next_xpos = next_ypos = -1;
|
||||
format = g_string_new(NULL);
|
||||
|
||||
settings_add_int("history", "scrollback_lines", 500);
|
||||
settings_add_int("history", "scrollback_hours", 24);
|
||||
settings_add_bool("history", "scrollback_save_formats", FALSE);
|
||||
|
||||
signal_add("gui print text", (SIGNAL_FUNC) gui_printtext);
|
||||
signal_add("gui print text", (SIGNAL_FUNC) sig_gui_print_text);
|
||||
signal_add("print text finished", (SIGNAL_FUNC) sig_printtext_finished);
|
||||
signal_add("print format", (SIGNAL_FUNC) sig_print_format);
|
||||
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
@ -574,7 +600,7 @@ void gui_printtext_deinit(void)
|
||||
{
|
||||
g_string_free(format, TRUE);
|
||||
|
||||
signal_remove("gui print text", (SIGNAL_FUNC) gui_printtext);
|
||||
signal_remove("gui print text", (SIGNAL_FUNC) sig_gui_print_text);
|
||||
signal_remove("print text finished", (SIGNAL_FUNC) sig_printtext_finished);
|
||||
signal_remove("print format", (SIGNAL_FUNC) sig_print_format);
|
||||
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
|
@ -33,4 +33,6 @@ void gui_window_line_append(GUI_WINDOW_REC *gui, const char *str, int len);
|
||||
void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line);
|
||||
void gui_window_line_text_free(GUI_WINDOW_REC *gui, LINE_REC *line);
|
||||
|
||||
void gui_printtext(int xpos, int ypos, const char *str, ...);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user