Exemple #1
0
static char *rl_strndup(gchar *s, gssize n) {
	static GString *buf = NULL;
	gchar *rec;

		/* XXX: API for stated-size recoding */
	if (G_UNLIKELY(!buf))
		buf = g_string_sized_new(G_LIKELY(n != -1) ? n+1 : 16);
	if (G_LIKELY(n == -1))
		g_string_assign(buf, s);
	else {
		g_string_truncate(buf, 0);
		g_string_append_len(buf, s, n);
	}

	rec = ekg_recode_to_locale(buf->str);
	if (G_LIKELY(g_mem_is_system_malloc()))
		return rec;
	else {
		gsize len = strlen(rec) + 1;
		char *out = malloc(len);

		memcpy(out, rec, len);
		g_free(rec);
		return out;
	}
}
Exemple #2
0
/**
 * current_prompt()
 *
 * Get the current prompt, locale-recoded.
 *
 * @return Static buffer pointer, non-NULL, locale-encoded.
 */
const /*locale*/ char *current_prompt(void)
{
	static gchar *buf = NULL;
	session_t *s;
	char *tmp, *act, *sid;
	char *format, *format_act;

	if (no_prompt)
		return "";

	s = session_current;
	sid = s ? (s->alias?s->alias:s->uid) : "";

	if (window_current->id > 1) {
		format		= "rl_prompt_query";
		format_act	= "rl_prompt_query_act";
	} else if (s && (s && s->status == EKG_STATUS_INVISIBLE)) {
		format		= "rl_prompt_invisible";
		format_act	= "rl_prompt_invisible_act";
	} else if (s && (s->status < EKG_STATUS_AVAIL)) {
		format		= "rl_prompt_away";
		format_act	= "rl_prompt_away_act";
	} else {
		format		= "rl_prompt";
		format_act	= "rl_prompt_act";
	}

	act = window_activity();
	if (act)
		tmp = format_string(format_find(format_act), sid, ekg_itoa(window_current->id), act, window_current->target);
	else
		tmp = format_string(format_find(format), sid, ekg_itoa(window_current->id), window_current->target);

	g_free(buf);
	buf = ekg_recode_to_locale(tmp);
	g_free(tmp);
	g_free(act);

	return buf;
}
Exemple #3
0
/*
 * ui_readline_print()
 *
 * wy¶wietla dany tekst na ekranie, uwa¿aj±c na trwaj±ce w danych chwili
 * readline().
 */
void ui_readline_print(window_t *w, int separate, const /*locale*/ char *xline)
{
	int old_end = rl_end, id = w->id;
	char *old_prompt = NULL, *line_buf = NULL;
	const char *line = NULL;

	if (config_timestamp) {
			/* XXX: recode timestamp? for fun or wcs? */
		string_t s = string_init(NULL);
		const char *p = xline;
		const char *buf = timestamp(formated_config_timestamp);

		string_append(s, "\033[0m");
		string_append(s, buf);
		string_append_c(s, ' ');
		
		while (*p) {
			string_append_c(s, *p);
			if (*p == '\n' && *(p + 1)) {
				string_append(s, buf);
				string_append_c(s, ' ');
			}
			p++;
		}

		line = line_buf = string_free(s, 0);
	} else
		line = xline;

	/* je¶li nie piszemy do aktualnego, to zapisz do bufora i wyjd¼ */
	if (id != window_current->id) {
		window_write(id, line);

		/* XXX trzeba jeszcze waln±æ od¶wie¿enie prompta */
		goto done;
	}

	/* je¶li mamy ukrywaæ wszystko, wychodzimy */
	if (pager_lines == -2)
		goto done;

	window_write(window_current->id, line);

	/* ukryj prompt, je¶li jeste¶my w trakcie readline */
	if (in_readline) {
		old_prompt = g_strdup(rl_prompt);
		rl_end = 0;
/*		set_prompt(NULL);*/
		rl_redisplay();
			/* XXX: string width instead?
			 * or cleartoeol? */
		printf("\r%*c\r", (int) xstrlen(old_prompt), ' ');
	}

	printf("%s", line);

	if (pager_lines >= 0) {
		pager_lines++;

		if (pager_lines >= screen_lines - 2) {
			const gchar *prompt = format_find("readline_more");
			char *lprompt = ekg_recode_to_locale(prompt);
			char *tmp;
				/* XXX: lprompt pretty const, make it static? */

			in_readline++;

			set_prompt(lprompt);

			pager_lines = -1;
			tmp = readline(lprompt);
			g_free(lprompt);
			in_readline--;
			if (tmp) {
				free(tmp); /* allocd by readline */
				pager_lines = 0;
			} else {
				printf("\n");
				pager_lines = -2;
			}
			printf("\033[A\033[K");		/* XXX brzydko */
		}
	}

	/* je¶li jeste¶my w readline, poka¿ z powrotem prompt */
	if (in_readline) {
		rl_end = old_end;
		set_prompt(old_prompt);
		g_free(old_prompt);
		rl_forced_update_display();
	}
	
done:
	if (line_buf)
		g_free(line_buf);
}
Exemple #4
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);
		}
	}
}