Esempio n. 1
0
File: main.c Progetto: hiciu/ekg2
static int logs_print_window(session_t *s, window_t *w, const char *line, time_t ts) {
	static plugin_t *ui_plugin = NULL;

	fstring_t *fstr;

	/* it's enough to look for ui_plugin once */
	if (!ui_plugin) ui_plugin = plugin_find(("ncurses"));
	if (!ui_plugin) ui_plugin = plugin_find(("gtk"));
	if (!ui_plugin) {
		debug_error("WARN logs_print_window() called but neither ncurses plugin nor gtk found\n");
		return -1;
	}

	fstr = fstring_new_format(line);
	fstr->ts = ts;

	query_emit(ui_plugin, "ui-window-print", &w, &fstr);
	fstring_free(fstr);
	return 0;
}
Esempio n. 2
0
/*
 * wyswietla ponownie linie wprowadzenia tekstu		(prompt + aktualnie wpisany tekst)
 *	przy okazji jesli jest aspell to sprawdza czy tekst jest poprawny.
 */
void ncurses_redraw_input(unsigned int ch) {
	int x, y;
	/* draw prompt */
	werase(input);
	wmove(input, 0, 0);
	if (!ncurses_lines) {
		gchar *tmp = ekg_recode_to_locale(format_find(
					ncurses_current->prompt ? "ncurses_prompt_query" : "ncurses_prompt_none"));
		gchar *tmp2 = format_string(tmp, "\037"); /* unit separator */
		fstring_t *prompt_f = fstring_new(tmp2);
		gchar *s = prompt_f->str, *s2;
		fstr_attr_t *a = prompt_f->attr, *a2;
		g_free(tmp2);
		g_free(tmp);

		if (ncurses_current->prompt) {
				/* find our \037 */
			for (s2 = s, a2 = a; *s2 != '\037'; s2++, a2++)
				g_assert(*s2);
			*s2 = '\0'; /* and split the original string using it */
		}

		ncurses_fstring_print(input, s, a, -1);
		
		if (ncurses_current->prompt) {
			if (!ncurses_simple_print(input, ncurses_current->prompt,
						*a2, input->_maxx / 4)) {

					/* don't change colors or anything
					 * just disable bold to distinguish */
				wattroff(input, A_BOLD); /* XXX? */
				waddstr(input, ncurses_hellip);
			}
			s2++, a2++;
			ncurses_fstring_print(input, s2, a2, -1);
		}
		fstring_free(prompt_f);
	}
	getyx(input, y, x);
	ncurses_current->prompt_len = x;

	/* XXX: cleanup, optimize */
	{
		int cur_posx = -1, cur_posy = 0;
		const int width = input->_maxx - x;

		if ((line_index - line_start >= width) || (line_index - line_start < 2))
			line_start = line_index - width/2;
		if (line_start < 0)
			line_start = 0;

		ncurses_redraw_input_already_exec = 1;

		wattrset(input, color_pair(COLOR_WHITE, COLOR_BLACK));

		if (ncurses_lines) {
			int i, x;

			cur_posy = lines_index - lines_start;
			for (i = 0; i < MULTILINE_INPUT_SIZE; i++) {
				if (!ncurses_lines[lines_start + i])
					break;

				wmove(input, i, 0);
				x = ncurses_redraw_input_line(ncurses_lines[lines_start + i]);
				if (lines_index == (lines_start + i))
					cur_posx = x;
			}
			wattrset(input, color_pair(COLOR_BLACK, COLOR_BLACK) | A_BOLD);
			if (lines_start>0)
				mvwaddch(input, 0, input->_maxx, '^');
			if (g_strv_length((char **) ncurses_lines)-lines_start > MULTILINE_INPUT_SIZE)
				mvwaddch(input, MULTILINE_INPUT_SIZE-1, input->_maxx, 'v');
			wattrset(input, A_NORMAL);
		} else {
#if 0
			if (ncurses_noecho) {
				static char *funnything	= ncurses_funnything;

				waddch(input, ' ');		/* XXX why here? If you want to add space after propt, add it in theme */
				waddch(input, *funnything);
				wmove(input, 0, getcurx(input)-1);
				if (!*(++funnything))
					funnything = ncurses_funnything;
				return;
			}
#endif

			cur_posx = ncurses_redraw_input_line(ncurses_line);

		}
		/* this mut be here if we don't want 'timeout' after pressing ^C */
		if (ch == 3) ncurses_commit();
		if (cur_posx != -1) {
			wmove(input, cur_posy, cur_posx);
			curs_set(1);
		} else {
			wmove(input, 0, 0);	// XXX ???
			curs_set(0);
		}
	}
}