[ekg2-commit] ekg2: old.c (HEAD) [peres]
CVS commit
cvs w toxygen.net
Sob, 6 Paź 2007, 22:08:51 CEST
Module name: ekg2
Changes by: peres 2007-10-06 22:08:49
Modified files:
old.c
Log message:
Shrink prompt when it exceeds 1/3 of screen width, using part of its' head
and tail, separated using horrizontal ellipsis. When running in UTF-8 mode,
use Unicode codepoint for it (SZPAN^TM); else use three ASCII dots. Also
enable input redraw on current window redraw (i.e. redraw input on terminal
resize).
Index: old.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/ncurses/old.c,v
diff -d -u -r1.155 -r1.156
--- old.c 6 Oct 2007 18:25:40 -0000 1.155
+++ old.c 6 Oct 2007 20:08:49 -0000 1.156
@@ -233,16 +233,46 @@
/* cut prompt to given width and recalculate its' width */
void ncurses_update_real_prompt(ncurses_window_t *n) {
+ if (!n)
+ return;
+
+ const int maxlen = (n->window && n->window->_maxx ? n->window->_maxx : 80) / 3;
xfree(n->prompt_real);
+
+ if (maxlen <= 6) /* we assume the terminal is too narrow to display any input with prompt */
+ n->prompt_real = NULL;
+ else {
#ifdef USE_UNICODE
- n->prompt_real = normal_to_wcs(n->prompt);
+ n->prompt_real = normal_to_wcs(n->prompt);
#else
- n->prompt_real = xstrdup(n->prompt);
+ n->prompt_real = xstrdup(n->prompt);
#endif
- n->prompt_real_len = xwcslen(n->prompt_real);
+ }
+ 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 */
+ if (n->prompt_real_len > maxlen) { /* need to cut it */
+ const CHAR_T *dots = TEXT("...");
+#ifdef USE_UNICODE
+ const wchar_t udots[2] = { 0x2026, 0 };
+ if (config_use_unicode) /* use unicode hellip, if using utf8 */
+ dots = udots;
+#endif
+
+ {
+ const int dotslen = xwcslen(dots);
+ const int taillen = (maxlen - dotslen) / 2; /* rounded down */
+ const int headlen = (maxlen - dotslen) - taillen; /* rounded up */
+
+ CHAR_T *tmp = xmalloc(sizeof(CHAR_T) * (maxlen + 1));
+
+ xwcslcpy(tmp, n->prompt_real, headlen + 1);
+ xwcslcpy(tmp + headlen, dots, dotslen + 1);
+ xwcslcpy(tmp + headlen + dotslen, n->prompt_real + n->prompt_real_len - taillen, taillen + 1);
+
+ xfree(n->prompt_real);
+ n->prompt_real = tmp;
+ n->prompt_real_len = maxlen;
+ }
}
}
@@ -785,6 +815,7 @@
n->start = 0;
}
+ ncurses_update_real_prompt(n);
n->redraw = 1;
}
@@ -972,6 +1003,9 @@
}
n->redraw = 0;
+
+ if (w == window_current)
+ ncurses_redraw_input(0);
}
/*
Więcej informacji o liście dyskusyjnej ekg2-commit