Ejemplo n.º 1
0
int main(int argc, char const *argv[])
{
	char *bf;
	size_t a;

	if(argc > 1)	{
		//readline_set_comment();
		while((bf = readline_continue(argv[1], &a)) != NULL)	{
			printf("(%4d): %s\n", (int)a, bf);
		}
		if(readline_error())	{
			puts(readline_errstr());
		}
	} else {
		readline_set_strip();
		while((bf = readline_fp(stdin, &a)) != NULL)	{
			printf("(%4d): %s\n", (int)a, bf);
		}
		if(readline_error())	{
			puts(readline_errstr());
		}
	}

	return 0;
}
Ejemplo n.º 2
0
/**
 * Write the command-prompt.
 */
static void
write_cmdprompt(WINDOW *win, char *prompt, int size)
{
    if (werase(win) == ERR) {
	readline_error(0, "werase");
    }

    if (waddnstr(win, prompt, size) == ERR) {
	readline_error(0, "waddnstr");
    }

    update_panels();
    (void) doupdate();
}
Ejemplo n.º 3
0
/**
 * Regular handling of a key-press.
 */
static void
handle_key(volatile struct readline_session_context *ctx, wint_t wc)
{
    if (ctx->no_bufspc) {
	term_beep();
	return;
    }

    if (hiLim_isset(ctx->act)) {
	magic_swap_panels(ctx, true);
    }

    if (ctx->insert_mode) {
	wchar_t				*ptr = &ctx->buffer[ctx->bufpos];
	struct current_cursor_pos	 yx;

	(void) wmemmove(ptr + 1, ptr, wcslen(ptr));
	*ptr = wc;
	ctx->bufpos++, ctx->n_insert++;
	readline_winsch(ctx->act, wc);
	yx = term_get_pos(ctx->act);

	if (wmove(ctx->act, yx.cury, yx.curx + 1) == ERR) {
	    readline_error(EPERM, "wmove");
	}
    } else {
	ctx->buffer[ctx->bufpos] = wc;
	ctx->bufpos++, ctx->n_insert++;
	readline_waddch(ctx->act, wc);
    }

    update_panels();
    (void) doupdate();
}
Ejemplo n.º 4
0
/**
 * Key backspace.
 */
static void
case_key_backspace(volatile struct readline_session_context *ctx)
{
    struct current_cursor_pos yx;

    if (ctx->bufpos == 0) {
	term_beep();
	return;
    }

    if (loLim_isset(ctx->act, ctx->prompt_size)) {
	magic_swap_panels(ctx, false);
    }

    if (ctx->insert_mode) {
	wchar_t *ptr = &ctx->buffer[ctx->bufpos--];

	(void) wmemmove(ptr - 1, ptr, wcslen(ptr));
	ctx->buffer[--ctx->n_insert] = 0L;
	yx = term_get_pos(ctx->act);

	if (wmove(ctx->act, yx.cury, yx.curx - 1) == ERR ||
	    wdelch(ctx->act) == ERR || wclrtoeol(ctx->act) == ERR) {
	    readline_error(EPERM, "wmove, wdelch or wclrtoeol");
	}

	readline_winsnstr(ctx->act, &ctx->buffer[ctx->bufpos], -1);
    } else { /* not insert_mode */
	ctx->buffer[--ctx->bufpos] = 0L;
	ctx->n_insert--;
	yx = term_get_pos(ctx->act);

	if (wmove(ctx->act, yx.cury, yx.curx - 1) == ERR ||
	    wdelch(ctx->act) == ERR) {
	    readline_error(EPERM, "wmove or wdelch");
	}
    }

    update_panels();
    (void) doupdate();
}
Ejemplo n.º 5
0
/**
 * When swapping between panels: computes the new window entry.
 */
static void
compute_new_window_entry(volatile struct readline_session_context *ctx,
			 bool fwd)
{
    int		 diff, buf_index;
    wchar_t	*str1, *str2;

    if (fwd) {
	diff	  = COLS / 2;
	buf_index = int_diff(ctx->bufpos, diff);

	if (COLS % 2 == 0) {
	    buf_index += 1;
	}

	str1 = &ctx->buffer[buf_index];
	str2 = &ctx->buffer[ctx->bufpos];
    } else {
	diff = int_diff(COLS / 2, ctx->prompt_size);

	if ((buf_index = int_diff(ctx->bufpos, diff)) < 0) {
	    readline_error(ERANGE, "compute_new_window_entry");
	}

	str1 = &ctx->buffer[buf_index];
	str2 = &ctx->buffer[ctx->bufpos];
    }

    if (ctx->insert_mode) {
	if (ctx->bufpos > 0) {
	    readline_waddnstr(ctx->act, str1, str2 - str1);
	}

	readline_winsnstr(ctx->act, str2, -1);
    } else {
	readline_waddnstr(ctx->act, str1, -1);
    }

    update_panels();
    (void) doupdate();
}
Ejemplo n.º 6
0
/**
 * Handles what happens if the delete key is pressed.
 */
static void
case_key_dc(volatile struct readline_session_context *ctx)
{
    wchar_t	*ptr;
    const int	 this_index = ctx->bufpos + 1;

    if (!ctx->insert_mode) {
	term_beep();
	return;
    }

    ptr = &ctx->buffer[this_index];
    (void) wmemmove(ptr - 1, ptr, wcslen(ptr));
    ctx->buffer[--ctx->n_insert] = 0L;

    if (wdelch(ctx->act) == ERR || wclrtoeol(ctx->act) == ERR) {
	readline_error(EPERM, "wdelch or wclrtoeol");
    }

    readline_winsnstr(ctx->act, &ctx->buffer[ctx->bufpos], -1);

    update_panels();
    (void) doupdate();
}
Ejemplo n.º 7
0
/**
 * Key right
 */
static void
case_key_right(volatile struct readline_session_context *ctx)
{
    struct current_cursor_pos yx;

    if (!ctx->insert_mode) {
	term_beep();
	return;
    }

    if (hiLim_isset(ctx->act)) {
	magic_swap_panels(ctx, true);
    }

    ctx->bufpos++;
    yx = term_get_pos(ctx->act);

    if (wmove(ctx->act, yx.cury, yx.curx + 1) == ERR) {
	readline_error(EPERM, "wmove");
    }

    update_panels();
    (void) doupdate();
}
Ejemplo n.º 8
0
/**
 * Key left
 */
static void
case_key_left(volatile struct readline_session_context *ctx)
{
    struct current_cursor_pos yx;

    if (ctx->bufpos == 0) {
	term_beep();
	return;
    }

    if (loLim_isset(ctx->act, ctx->prompt_size)) {
	magic_swap_panels(ctx, false);
    }

    ctx->bufpos--;
    yx = term_get_pos(ctx->act);

    if (wmove(ctx->act, yx.cury, yx.curx - 1) == ERR) {
	readline_error(EPERM, "wmove");
    }

    update_panels();
    (void) doupdate();
}