Esempio n. 1
0
static void tinput_display_prompt(tinput_t *ti)
{
	tinput_console_set_lpos(ti, ti->prompt_coord);

	console_set_style(ti->console, STYLE_EMPHASIS);
	printf("%s", ti->prompt);
	console_flush(ti->console);
	console_set_style(ti->console, STYLE_NORMAL);
}
Esempio n. 2
0
/** Display text in the status line. */
static void status_display(char const *str)
{
	console_set_pos(con, 0, scr_rows - 1);
	console_set_style(con, STYLE_INVERTED);
	
	int pos = -(scr_columns - 3);
	printf(" %*s ", pos, str);
	console_flush(con);
	console_set_style(con, STYLE_NORMAL);

	pane.rflags |= REDRAW_CARET;
}
Esempio n. 3
0
static void tinput_display_tail(tinput_t *ti, size_t start, size_t pad)
{
	wchar_t *dbuf = malloc((INPUT_MAX_SIZE + 1) * sizeof(wchar_t));
	if (!dbuf)
		return;	
	
	size_t sa;
	size_t sb;
	tinput_sel_get_bounds(ti, &sa, &sb);
	
	tinput_console_set_lpos(ti, ti->text_coord + start);
	console_set_style(ti->console, STYLE_NORMAL);
	
	size_t p = start;
	if (p < sa) {
		memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(wchar_t));
		dbuf[sa - p] = '\0';
		printf("%ls", dbuf);
		p = sa;
	}
	
	if (p < sb) {
		console_flush(ti->console);
		console_set_style(ti->console, STYLE_SELECTED);
		
		memcpy(dbuf, ti->buffer + p,
		    (sb - p) * sizeof(wchar_t));
		dbuf[sb - p] = '\0';
		printf("%ls", dbuf);
		p = sb;
	}
	
	console_flush(ti->console);
	console_set_style(ti->console, STYLE_NORMAL);
	
	if (p < ti->nc) {
		memcpy(dbuf, ti->buffer + p,
		    (ti->nc - p) * sizeof(wchar_t));
		dbuf[ti->nc - p] = '\0';
		printf("%ls", dbuf);
	}
	
	for (p = 0; p < pad; p++)
		putchar(' ');
	
	console_flush(ti->console);

	free(dbuf);
}
Esempio n. 4
0
static void waitprompt(void)
{
	console_set_pos(console, 0, console_rows-1);
	console_set_color(console, COLOR_WHITE, COLOR_BLUE, 0);
	
	printf("ENTER/SPACE/PAGE DOWN - next page, "
	       "ESC/Q - quit, C - continue unpaged");
	fflush(stdout);
	
	console_set_style(console, STYLE_NORMAL);
}
Esempio n. 5
0
/** Display pane status in the status line. */
static void pane_status_display(void)
{
	spt_t caret_pt;
	coord_t coord;

	tag_get_pt(&pane.caret_pos, &caret_pt);
	spt_get_coord(&caret_pt, &coord);

	const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>";

	console_set_pos(con, 0, scr_rows - 1);
	console_set_style(con, STYLE_INVERTED);
	int n = printf(" %d, %d: File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
	    "Ctrl-E Save As", coord.row, coord.column, fname);
	
	int pos = scr_columns - 1 - n;
	printf("%*s", pos, "");
	console_flush(con);
	console_set_style(con, STYLE_NORMAL);

	pane.rflags |= REDRAW_CARET;
}
Esempio n. 6
0
static void pane_row_range_display(int r0, int r1)
{
	int i, j, fill;
	spt_t rb, re, dep, pt;
	coord_t rbc, rec;
	char row_buf[ROW_BUF_SIZE];
	wchar_t c;
	size_t pos, size;
	int s_column;
	coord_t csel_start, csel_end, ctmp;

	/* Determine selection start and end. */

	tag_get_pt(&pane.sel_start, &pt);
	spt_get_coord(&pt, &csel_start);

	tag_get_pt(&pane.caret_pos, &pt);
	spt_get_coord(&pt, &csel_end);

	if (coord_cmp(&csel_start, &csel_end) > 0) {
		ctmp = csel_start;
		csel_start = csel_end;
		csel_end = ctmp;
	}

	/* Draw rows from the sheet. */

	console_set_pos(con, 0, 0);
	for (i = r0; i < r1; ++i) {
		/* Starting point for row display */
		rbc.row = pane.sh_row + i;
		rbc.column = pane.sh_column;
		sheet_get_cell_pt(&doc.sh, &rbc, dir_before, &rb);

		/* Ending point for row display */
		rec.row = pane.sh_row + i;
		rec.column = pane.sh_column + pane.columns;
		sheet_get_cell_pt(&doc.sh, &rec, dir_before, &re);

		/* Copy the text of the row to the buffer. */
		sheet_copy_out(&doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep);

		/* Display text from the buffer. */

		if (coord_cmp(&csel_start, &rbc) <= 0 &&
		    coord_cmp(&rbc, &csel_end) < 0) {
			console_flush(con);
			console_set_style(con, STYLE_SELECTED);
			console_flush(con);
		}

		console_set_pos(con, 0, i);
		size = str_size(row_buf);
		pos = 0;
		s_column = pane.sh_column;
		while (pos < size) {
			if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) {
				console_flush(con);
				console_set_style(con, STYLE_SELECTED);
				console_flush(con);
			}
	
			if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
				console_flush(con);
				console_set_style(con, STYLE_NORMAL);
				console_flush(con);
			}
	
			c = str_decode(row_buf, &pos, size);
			if (c != '\t') {
				printf("%lc", (wint_t) c);
				s_column += 1;
			} else {
				fill = 1 + ALIGN_UP(s_column, TAB_WIDTH)
				    - s_column;

				for (j = 0; j < fill; ++j)
					putchar(' ');
				s_column += fill;
			}
		}

		if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
			console_flush(con);
			console_set_style(con, STYLE_NORMAL);
			console_flush(con);
		}

		/* Fill until the end of display area. */

		if (str_length(row_buf) < (unsigned) scr_columns)
			fill = scr_columns - str_length(row_buf);
		else
			fill = 0;

		for (j = 0; j < fill; ++j)
			putchar(' ');
		console_flush(con);
		console_set_style(con, STYLE_NORMAL);
	}

	pane.rflags |= REDRAW_CARET;
}
Esempio n. 7
0
/** Ask for a file name. */
static char *filename_prompt(char const *prompt, char const *init_value)
{
	kbd_event_t ev;
	char *str;
	wchar_t buffer[INFNAME_MAX_LEN + 1];
	int max_len;
	int nc;
	bool done;

	asprintf(&str, "%s: %s", prompt, init_value);
	status_display(str);
	console_set_pos(con, 1 + str_length(str), scr_rows - 1);
	free(str);

	console_set_style(con, STYLE_INVERTED);

	max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt));
	str_to_wstr(buffer, max_len + 1, init_value);
	nc = wstr_length(buffer);
	done = false;

	while (!done) {
		console_get_kbd_event(con, &ev);

		if (ev.type == KEY_PRESS) {
			/* Handle key press. */
			if (((ev.mods & KM_ALT) == 0) &&
			     (ev.mods & KM_CTRL) != 0) {
				;
			} else if ((ev.mods & (KM_CTRL | KM_ALT)) == 0) {
				switch (ev.key) {
				case KC_ESCAPE:
					return NULL;
				case KC_BACKSPACE:
					if (nc > 0) {
						putchar('\b');
						console_flush(con);
						--nc;
					}
					break;
				case KC_ENTER:
					done = true;
					break;
				default:
					if (ev.c >= 32 && nc < max_len) {
						putchar(ev.c);
						console_flush(con);
						buffer[nc++] = ev.c;
					}
					break;
				}
			}
		}
	}

	buffer[nc] = '\0';
	str = wstr_to_astr(buffer);

	console_set_style(con, STYLE_NORMAL);

	return str;
}
Esempio n. 8
0
static void resume_normal(void)
{
	console_flush(console);
	console_set_style(console, STYLE_NORMAL);
}