Example #1
0
/* cut prompt to given width and recalculate its' width */
void ncurses_update_real_prompt(ncurses_window_t *n) {
	g_assert(n);

#if 0 /* XXX: shortening */

	const int _maxlen = n->window && n->window->_maxx ? n->window->_maxx : 80;
	const int maxlen = ncurses_noecho ? _maxlen - 3 : _maxlen / 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);
#else
		n->prompt_real		= (CHAR_T *) xstrdup(n->prompt);
#endif
	}
	n->prompt_real_len		= xwcslen(n->prompt_real);

	if (n->prompt_real_len > maxlen) { /* need to cut it */
		const CHAR_T *dots	= (CHAR_T *) TEXT("...");
#ifdef USE_UNICODE
		const wchar_t udots[2]	= { 0x2026, 0 };
		if (console_charset_is_utf8)	/* 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;
		}
	}
#endif
}
Example #2
0
static BINDING_FUNCTION(binding_word_rubout)
{
    CHAR_T *p;
    int eaten = 0;

    if (!line_index)
        return;

    xfree(yanked);

    p = line + line_index;

    if (xisspace(*(p - 1))) {
        while (p > line && xisspace(*(p - 1))) {
            p--;
            eaten++;
        }
    } else {
        while (p > line && ! xisalpha(*(p - 1)) && ! xisspace(*(p - 1))) {
            p--;
            eaten++;
        }
    }

    if (p > line) {
        while (p > line && ! xisspace(*(p - 1)) && xisalpha(*(p - 1))) {
            p--;
            eaten++;
        }
    }

    yanked = xcalloc(eaten + 1, sizeof(CHAR_T));
    xwcslcpy(yanked, p, eaten + 1);

    memmove(p, line + line_index, (xwcslen(line) - line_index + 1) * sizeof(CHAR_T));
    line_index -= eaten;
}