summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-02-21 04:21:15 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-02-21 04:21:15 +0000
commit4718edf055c33ea1d52197ac9b0d7233dc7d77ca (patch)
tree8ad31b78825ac92c0f62e4eac7a5d762c0115e56 /src
parentc8893c61eebf363354ecfab926fb09e5b973deaf (diff)
downloadirssi-4718edf055c33ea1d52197ac9b0d7233dc7d77ca.zip
added format_get_length() for getting length of text part in a format
string. gui_printtext() now works like printtext_string() so %s won't accidentally crash it. /SET prompt can now have %formats. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1273 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r--src/fe-common/core/formats.c28
-rw-r--r--src/fe-common/core/formats.h3
-rw-r--r--src/fe-common/core/printtext.c13
-rw-r--r--src/fe-common/core/printtext.h3
-rw-r--r--src/fe-text/gui-entry.c10
-rw-r--r--src/fe-text/gui-printtext.c8
-rw-r--r--src/fe-text/gui-printtext.h2
-rw-r--r--src/fe-text/statusbar-items.c4
8 files changed, 44 insertions, 27 deletions
diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c
index 1799e812..107bc497 100644
--- a/src/fe-common/core/formats.c
+++ b/src/fe-common/core/formats.c
@@ -216,6 +216,34 @@ void format_create_dest(TEXT_DEST_REC *dest,
dest->hilight_bg_color = 0;
}
+int format_get_length(const char *str)
+{
+ GString *tmp;
+ int len;
+
+ tmp = g_string_new(NULL);
+ len = 0;
+ while (*str != '\0') {
+ if (*str == '%' && str[1] != '\0') {
+ str++;
+ if (*str != '%' && format_expand_styles(tmp, *str)) {
+ str++;
+ continue;
+ }
+
+ /* %% or unknown %code, written as-is */
+ if (*str != '%')
+ len++;
+ }
+
+ len++;
+ str++;
+ }
+
+ g_string_free(tmp, TRUE);
+ return len;
+}
+
static char *format_get_text_args(TEXT_DEST_REC *dest,
const char *text, char **arglist)
{
diff --git a/src/fe-common/core/formats.h b/src/fe-common/core/formats.h
index 2e2d6cff..5d136d2f 100644
--- a/src/fe-common/core/formats.h
+++ b/src/fe-common/core/formats.h
@@ -43,6 +43,9 @@ typedef struct {
int format_find_tag(const char *module, const char *tag);
+/* Return length of text part in string (ie. without % codes) */
+int format_get_length(const char *str);
+
char *format_get_text(const char *module, WINDOW_REC *window,
void *server, const char *target,
int formatnum, ...);
diff --git a/src/fe-common/core/printtext.c b/src/fe-common/core/printtext.c
index f1c4d397..7b85e2c7 100644
--- a/src/fe-common/core/printtext.c
+++ b/src/fe-common/core/printtext.c
@@ -348,7 +348,7 @@ void printtext_window(WINDOW_REC *window, int level, const char *text, ...)
va_end(va);
}
-void printtext_gui_args(const char *text, va_list va)
+void printtext_gui(const char *text)
{
TEXT_DEST_REC dest;
char *str;
@@ -357,20 +357,11 @@ void printtext_gui_args(const char *text, va_list va)
memset(&dest, 0, sizeof(dest));
- str = printtext_get_args(&dest, text, va);
+ str = printtext_expand_formats(text);
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 &&
diff --git a/src/fe-common/core/printtext.h b/src/fe-common/core/printtext.h
index 5133fa57..125b6f72 100644
--- a/src/fe-common/core/printtext.h
+++ b/src/fe-common/core/printtext.h
@@ -17,8 +17,7 @@ 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 printtext_gui(const char *text);
void printformat_module_gui(const char *module, int formatnum, ...);
void printformat_module_gui_args(const char *module, int formatnum, va_list va);
diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c
index 07990351..257a173c 100644
--- a/src/fe-text/gui-entry.c
+++ b/src/fe-text/gui-entry.c
@@ -19,7 +19,9 @@
*/
#include "module.h"
+#include "formats.h"
+#include "gui-printtext.h"
#include "screen.h"
static GString *entry;
@@ -78,11 +80,11 @@ void gui_entry_set_prompt(const char *str)
g_free_not_null(prompt);
prompt = g_strdup(str);
- promptlen = strlen(prompt);
+ promptlen = format_get_length(prompt);
}
- set_color(stdscr, 0);
- mvaddstr(LINES-1, 0, prompt);
+ if (prompt != NULL)
+ gui_printtext(0, LINES-1, prompt);
entry_screenpos();
entry_update();
@@ -94,7 +96,7 @@ void gui_entry_set_perm_prompt(const char *str)
g_free_not_null(prompt);
prompt = g_strdup(str);
- promptlen = strlen(prompt);
+ promptlen = format_get_length(prompt);
permanent_prompt = TRUE;
gui_entry_set_prompt(NULL);
diff --git a/src/fe-text/gui-printtext.c b/src/fe-text/gui-printtext.c
index 6d339404..9fbf14b1 100644
--- a/src/fe-text/gui-printtext.c
+++ b/src/fe-text/gui-printtext.c
@@ -239,16 +239,12 @@ void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line, int redraw)
gui_window_redraw(window);
}
-void gui_printtext(int xpos, int ypos, const char *str, ...)
+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);
+ printtext_gui(str);
next_xpos = next_ypos = -1;
}
diff --git a/src/fe-text/gui-printtext.h b/src/fe-text/gui-printtext.h
index 468e46a7..6f0b46fe 100644
--- a/src/fe-text/gui-printtext.h
+++ b/src/fe-text/gui-printtext.h
@@ -33,6 +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, int redraw);
void gui_window_line_text_free(GUI_WINDOW_REC *gui, LINE_REC *line);
-void gui_printtext(int xpos, int ypos, const char *str, ...);
+void gui_printtext(int xpos, int ypos, const char *str);
#endif
diff --git a/src/fe-text/statusbar-items.c b/src/fe-text/statusbar-items.c
index 035c77e1..7d0c092e 100644
--- a/src/fe-text/statusbar-items.c
+++ b/src/fe-text/statusbar-items.c
@@ -517,9 +517,7 @@ static void sig_statusbar_more_check_remove(WINDOW_REC *window)
static void sig_statusbar_more_check(WINDOW_REC *window)
{
- g_return_if_fail(window != NULL);
-
- if (!is_window_visible(window))
+ if (window == NULL || !is_window_visible(window))
return;
if (!WINDOW_GUI(window)->bottom) {