[ekg2-commit] ekg2: main.c (HEAD) mouse.c (HEAD) old.c (HEAD) old.h (HEAD) [peres]
CVS commit
cvs w toxygen.net
Sob, 6 Paź 2007, 20:25:43 CEST
Module name: ekg2
Changes by: peres 2007-10-06 20:25:41
Modified files:
main.c mouse.c old.c old.h
Log message:
* WARNING: very experimental *
Adding prompt_real & prompt_real_len in ncurses_window_t. It would be
already converted to wchar_t, counted as chars (instead of bytes) and
(in near future) cut to match 2/3 of screen width (needed, because too
long prompts cause ekg2 to segv).
Index: main.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/ncurses/main.c,v
diff -d -u -r1.100 -r1.101
--- main.c 31 Aug 2007 23:49:14 -0000 1.100
+++ main.c 6 Oct 2007 18:25:40 -0000 1.101
@@ -254,6 +254,8 @@
n->prompt = tmp;
n->prompt_len = xstrlen(tmp);
+ ncurses_update_real_prompt(n);
+
update_statusbar(1);
return 0;
@@ -310,6 +312,8 @@
xfree(n->prompt);
n->prompt = format_string(format_find("ncurses_prompt_query"), w->target);
n->prompt_len = xstrlen(n->prompt);
+
+ ncurses_update_real_prompt(n);
}
list_destroy(sorted_all_cache, 1);
@@ -374,6 +378,7 @@
w->target = xstrdup(newname);
n->prompt = format_string(format_find("ncurses_prompt_query"), newname);
n->prompt_len = xstrlen(n->prompt);
+ ncurses_update_real_prompt(n);
}
}
Index: mouse.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/ncurses/mouse.c,v
diff -d -u -r1.29 -r1.30
--- mouse.c 8 Sep 2007 23:26:15 -0000 1.29
+++ mouse.c 6 Oct 2007 18:25:40 -0000 1.30
@@ -168,10 +168,9 @@
else if (mouse_flag == EKG_BUTTON1_CLICKED) {
/* the plugin already calculates offset incorrectly,
* so we shall follow it */
- const int promptlen = ncurses_current ? xstrlen(ncurses_current->prompt) : 0;
+ const int promptlen = ncurses_current ? ncurses_current->prompt_real_len : 0;
const int linelen = xwcslen(ncurses_line);
- debug("ZZZ: %d, %d\n", promptlen, x);
line_index = x - promptlen;
if (line_index < 0)
Index: old.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/ncurses/old.c,v
diff -d -u -r1.154 -r1.155
--- old.c 6 Oct 2007 17:25:34 -0000 1.154
+++ old.c 6 Oct 2007 18:25:40 -0000 1.155
@@ -231,6 +231,21 @@
return 0;
}
+/* cut prompt to given width and recalculate its' width */
+void ncurses_update_real_prompt(ncurses_window_t *n) {
+ xfree(n->prompt_real);
+#ifdef USE_UNICODE
+ n->prompt_real = normal_to_wcs(n->prompt);
+#else
+ n->prompt_real = xstrdup(n->prompt);
+#endif
+ n->prompt_real_len = xwcslen(n->prompt_real);
+
+ if (n->prompt_real_len > ncurses_screen_width * 2 / 3) { /* need to cut it */
+ /* XXX: cut, cut, cut */
+ }
+}
+
/*
* ncurses_spellcheck_init()
*
@@ -1559,6 +1574,8 @@
xfree(n->prompt);
// n->prompt = NULL;
+ xfree(n->prompt_real);
+// n->prompt_real = NULL;
delwin(n->window);
// n->window = NULL;
xfree(n);
@@ -1774,7 +1791,7 @@
*/
void ncurses_line_adjust()
{
- int prompt_len = (ncurses_lines) ? 0 : ncurses_current->prompt_len;
+ const int prompt_len = (ncurses_lines) ? 0 : ncurses_current->prompt_real_len;
line_index = xwcslen(ncurses_line);
if (line_index < input->_maxx - 9 - prompt_len)
@@ -2123,10 +2140,10 @@
char *aspell_line = NULL;
int mispelling = 0; /* zmienna pomocnicza */
#endif
- if (line_index - line_start > input->_maxx - 9 - ncurses_current->prompt_len)
- line_start += input->_maxx - 19 - ncurses_current->prompt_len;
+ if (line_index - line_start > input->_maxx - 9 - ncurses_current->prompt_real_len)
+ line_start += input->_maxx - 19 - ncurses_current->prompt_real_len;
if (line_index - line_start < 10) {
- line_start -= input->_maxx - 19 - ncurses_current->prompt_len;
+ line_start -= input->_maxx - 19 - ncurses_current->prompt_real_len;
if (line_start < 0)
line_start = 0;
}
@@ -2180,13 +2197,17 @@
}
} else {
int i;
- /* const */size_t linelen = xwcslen(ncurses_line);
+ /* const */size_t linelen = xwcslen(ncurses_line);
if (ncurses_current->prompt)
- mvwaddstr(input, 0, 0, ncurses_current->prompt);
+#ifdef USE_UNICODE /* XXX: should we check config_use_unicode here? */
+ mvwaddwstr(input, 0, 0, ncurses_current->prompt_real);
+#else
+ mvwaddstr(input, 0, 0, ncurses_current->prompt_real);
+#endif
if (ncurses_noecho) {
- const int x = xmbslen(ncurses_current->prompt) + 1;
+ const int x = ncurses_current->prompt_real_len + 1;
static char *funnything = ncurses_funnything;
mvwaddch(input, 0, x, *funnything);
@@ -2205,13 +2226,13 @@
spellcheck(ncurses_line, aspell_line);
}
#endif
- for (i = 0; i < input->_maxx + 1 - ncurses_current->prompt_len && i < linelen - line_start; i++) {
+ for (i = 0; i < input->_maxx + 1 - ncurses_current->prompt_real_len && i < linelen - line_start; i++) {
#ifdef WITH_ASPELL
if (spell_checker && aspell_line[line_start + i] == ASPELLCHAR && ncurses_line[line_start + i] != ' ') /* jesli błędny to wyświetlamy podkreślony */
- print_char(input, 0, i + ncurses_current->prompt_len, ncurses_line[line_start + i], A_UNDERLINE);
+ print_char(input, 0, i + ncurses_current->prompt_real_len, ncurses_line[line_start + i], A_UNDERLINE);
else /* jesli jest wszystko okey to wyswietlamy normalny */
#endif /* lub gdy nie mamy aspella */
- print_char(input, 0, i + ncurses_current->prompt_len, ncurses_line[line_start + i], A_NORMAL);
+ print_char(input, 0, i + ncurses_current->prompt_real_len, ncurses_line[line_start + i], A_NORMAL);
}
#ifdef WITH_ASPELL
xfree(aspell_line);
@@ -2220,11 +2241,11 @@
if (ch == 3) ncurses_commit();
wattrset(input, color_pair(COLOR_BLACK, 1, COLOR_BLACK));
if (line_start > 0)
- mvwaddch(input, 0, ncurses_current->prompt_len, '<');
- if (linelen - line_start > input->_maxx + 1 - ncurses_current->prompt_len)
+ mvwaddch(input, 0, ncurses_current->prompt_real_len, '<');
+ if (linelen - line_start > input->_maxx + 1 - ncurses_current->prompt_real_len)
mvwaddch(input, 0, input->_maxx, '>');
wattrset(input, color_pair(COLOR_WHITE, 0, COLOR_BLACK));
- wmove(input, 0, line_index - line_start + xmbslen(ncurses_current->prompt));
+ wmove(input, 0, line_index - line_start + ncurses_current->prompt_real_len);
}
}
@@ -2710,12 +2731,16 @@
n->prompt = format_string(f, w->target);
n->prompt_len = xstrlen(n->prompt);
+
+ ncurses_update_real_prompt(n);
} else {
const char *f = format_find("ncurses_prompt_none");
if (xstrcmp(f, "")) {
n->prompt = format_string(f);
n->prompt_len = xstrlen(n->prompt);
+
+ ncurses_update_real_prompt(n);
}
}
Index: old.h
===================================================================
RCS file: /home/cvs/ekg2/plugins/ncurses/old.h,v
diff -d -u -r1.36 -r1.37
--- old.h 1 Sep 2007 21:38:12 -0000 1.36
+++ old.h 6 Oct 2007 18:25:40 -0000 1.37
@@ -75,6 +75,9 @@
/* obsługa przerysowania zawartości okna */
void (*handle_mouse)(int x, int y, int state);
+
+ CHAR_T *prompt_real; /* prompt shortened to 2/3 of window width & converted to real chartype */
+ int prompt_real_len; /* real prompt length, including cutting, in chars instead of bytes */
} ncurses_window_t;
struct format_data {
@@ -88,6 +91,7 @@
TIMER(ncurses_typing);
void ncurses_main_window_mouse_handler(int x, int y, int mouse_state);
+void ncurses_update_real_prompt(ncurses_window_t *n);
void ncurses_resize();
int ncurses_backlog_add(window_t *w, fstring_t *str);
int ncurses_backlog_split(window_t *w, int full, int removed);
Więcej informacji o liście dyskusyjnej ekg2-commit