aboutsummaryrefslogtreecommitdiffstats
Commit message (Expand)AuthorAgeFilesLines
...
* Add overflow literal.Tristan Gingold2014-07-2125-293/+522
* Add Entity_Name for architecture and configuration.Tristan Gingold2014-07-194-13/+58
* Replace architecture_declaration by architecture_body to follow lrm.Tristan Gingold2014-07-1929-140/+138
* Handle character literals like simple names.Tristan Gingold2014-07-197-71/+24
* Fix implicit conversion in conversion association.Tristan Gingold2014-07-185-26/+31
* vhdl 2008: visibility, more implicit subprograms, alias...Tristan Gingold2014-07-1742-543/+1406
* vhdl08: add oread, hread.Tristan Gingold2014-07-019-31/+284
* Add many vhdl08 predefined operators and functions. Add std.envTristan Gingold2014-06-3015-142/+508
* Add ticket14.Tristan Gingold2014-06-296-0/+169
* vhdl 2008: handle all-sensitized processes, handle visibility for alias.Tristan Gingold2014-06-299-50/+178
* Resolve expression in variable assignment when target is an aggregate.Tristan Gingold2014-06-286-9/+91
* simulate: fix function call during elaboration of protected object.Tristan Gingold2014-06-282-110/+111
* vhdl2008: add overloaded to_string predefined functions.Tristan Gingold2014-06-276-117/+191
* simulate: fix nbr_objects, improve display of arrays.Tristan Gingold2014-06-274-37/+77
* add more support for vhdl2008: aliases, visibility and preliminary work forTristan Gingold2014-06-2614-235/+748
* Use library unit instead of design unit.Tristan Gingold2014-06-2421-351/+351
* vests/vhdl-93/ashenden/non_compliant/ch_02_ch_02_01.vhd: fix overflow.Tristan Gingold2014-06-241-0/+2
* vhdl 2008: add justify and swrite in textio.Tristan Gingold2014-06-243-34/+154
* Strengthen Is_Signal_Object, add a test for alias.Tristan Gingold2014-06-223-11/+97
* Add psl cover directive (ticket19).Tristan Gingold2014-06-2124-132/+503
* Handla index of 'image. Fix ticket20.Tristan Gingold2014-06-216-5/+194
* Handle report/severity in PSL assertions.Tristan Gingold2014-06-216-1/+161
* improve error message for error in default binding.Tristan Gingold2014-06-214-30/+53
* parser: improve location of aggregates.Tristan Gingold2014-06-211-6/+20
* ghdlcomp: stop in case of errors on delayed checks.Tristan Gingold2014-06-211-2/+5
* simulate: rework configuration, add stats.Tristan Gingold2014-06-2110-570/+851
* Fix regression for 'value on physical types.Tristan Gingold2014-06-211-5/+9
* Add missing grt-readline.ads file.Tristan Gingold2014-06-161-0/+30
* Add interpreted simulator.Tristan Gingold2014-06-1524-0/+14817
* configuration: add Check_Entity_Declaration_Top from translation.Tristan Gingold2014-06-1410-348/+444
* canon: canon entity ports and generics, canon aggregate and subtype indications.Tristan Gingold2014-06-141-2/+113
* grt-values: export ghdl_value_physical_split, to_lc, is_whitespace.Tristan Gingold2014-06-142-26/+60
* grt-vstrings: add to_string for ghdl_f64, use it in grt-images.Tristan Gingold2014-06-143-83/+94
* grt-types: make access type std_string_ptr general.Tristan Gingold2014-06-141-1/+1
* grt-errors: export fatal_error.Tristan Gingold2014-06-142-4/+5
* grt-disp_signals: display explicitly direct drivers.Tristan Gingold2014-06-141-2/+7
* disp_tree: improve display of array subtypes.Tristan Gingold2014-06-141-4/+4
* disp_vhdl: handle 'last_active.Tristan Gingold2014-06-141-0/+3
* sem_specs: allow no port/generic in default binding indication.Tristan Gingold2014-06-142-18/+19
* aggregate: set location on '('Tristan Gingold2014-06-141-5/+4
* sem: remove old comment.Tristan Gingold2014-06-141-2/+0
* iirs: add set/get_process_originTristan Gingold2014-06-142-0/+31
* Fix ticket14: build vars for anonymous subtype in array type indexes.Tristan Gingold2014-05-292-4/+50
* Rework aggregate (when type of context is not static).Tristan Gingold2014-05-295-96/+106
* Adjust set of whole_assoc flag.Tristan Gingold2014-05-291-1/+1
* canon: add Canon_Association_Chain_And_Actuals, set parent and whole assoc.Tristan Gingold2014-05-291-6/+38
* ghdlsimul: add --trace-stmts, -iTristan Gingold2014-05-291-4/+7
* grt-signals: add comments, add Ghdl_Signal_Set_Mode.Tristan Gingold2014-05-293-36/+86
* sem_decls: handle alias of component.Tristan Gingold2014-05-291-1/+2
* Add a comment.Tristan Gingold2014-05-291-0/+1
al.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 *  textbox.c -- implements the text box
 *
 *  ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
 *  MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "dialog.h"

static void back_lines(int n);
static void print_page(WINDOW *win, int height, int width, update_text_fn
		       update_text, void *data);
static void print_line(WINDOW *win, int row, int width);
static char *get_line(void);
static void print_position(WINDOW * win);

static int hscroll;
static int begin_reached, end_reached, page_length;
static char *buf;
static char *page;

/*
 * refresh window content
 */
static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
			     int cur_y, int cur_x, update_text_fn update_text,
			     void *data)
{
	print_page(box, boxh, boxw, update_text, data);
	print_position(dialog);
	wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
	wrefresh(dialog);
}


/*
 * Display text from a file in a dialog box.
 *
 * keys is a null-terminated array
 * update_text() may not add or remove any '\n' or '\0' in tbuf
 */
int dialog_textbox(const char *title, char *tbuf, int initial_height,
		   int initial_width, int *keys, int *_vscroll, int *_hscroll,
		   update_text_fn update_text, void *data)
{
	int i, x, y, cur_x, cur_y, key = 0;
	int height, width, boxh, boxw;
	WINDOW *dialog, *box;
	bool done = false;

	begin_reached = 1;
	end_reached = 0;
	page_length = 0;
	hscroll = 0;
	buf = tbuf;
	page = buf;	/* page is pointer to start of page to be displayed */

	if (_vscroll && *_vscroll) {
		begin_reached = 0;

		for (i = 0; i < *_vscroll; i++)
			get_line();
	}
	if (_hscroll)
		hscroll = *_hscroll;

do_resize:
	getmaxyx(stdscr, height, width);
	if (height < TEXTBOX_HEIGTH_MIN || width < TEXTBOX_WIDTH_MIN)
		return -ERRDISPLAYTOOSMALL;
	if (initial_height != 0)
		height = initial_height;
	else
		if (height > 4)
			height -= 4;
		else
			height = 0;
	if (initial_width != 0)
		width = initial_width;
	else
		if (width > 5)
			width -= 5;
		else
			width = 0;

	/* center dialog box on screen */
	x = (getmaxx(stdscr) - width) / 2;
	y = (getmaxy(stdscr) - height) / 2;

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	/* Create window for box region, used for scrolling text */
	boxh = height - 4;
	boxw = width - 2;
	box = subwin(dialog, boxh, boxw, y + 1, x + 1);
	wattrset(box, dlg.dialog.atr);
	wbkgdset(box, dlg.dialog.atr & A_COLOR);

	keypad(box, TRUE);

	/* register the new window, along with its borders */
	draw_box(dialog, 0, 0, height, width,
		 dlg.dialog.atr, dlg.border.atr);

	wattrset(dialog, dlg.border.atr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dlg.dialog.atr);
	wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	print_button(dialog, gettext(" Exit "), height - 2, width / 2 - 4, TRUE);
	wnoutrefresh(dialog);
	getyx(dialog, cur_y, cur_x);	/* Save cursor position */

	/* Print first page of text */
	attr_clear(box, boxh, boxw, dlg.dialog.atr);
	refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x, update_text,
			 data);

	while (!done) {
		key = wgetch(dialog);
		switch (key) {
		case 'E':	/* Exit */
		case 'e':
		case 'X':
		case 'x':
		case 'q':
		case '\n':
			done = true;
			break;
		case 'g':	/* First page */
		case KEY_HOME:
			if (!begin_reached) {
				begin_reached = 1;
				page = buf;
				refresh_text_box(dialog, box, boxh, boxw,
						 cur_y, cur_x, update_text,
						 data);
			}
			break;
		case 'G':	/* Last page */
		case KEY_END:

			end_reached = 1;
			/* point to last char in buf */
			page = buf + strlen(buf);
			back_lines(boxh);
			refresh_text_box(dialog, box, boxh, boxw, cur_y,
					 cur_x, update_text, data);
			break;
		case 'K':	/* Previous line */
		case 'k':
		case KEY_UP:
			if (begin_reached)
				break;

			back_lines(page_length + 1);
			refresh_text_box(dialog, box, boxh, boxw, cur_y,
					 cur_x, update_text, data);
			break;
		case 'B':	/* Previous page */
		case 'b':
		case 'u':
		case KEY_PPAGE:
			if (begin_reached)
				break;
			back_lines(page_length + boxh);
			refresh_text_box(dialog, box, boxh, boxw, cur_y,
					 cur_x, update_text, data);
			break;
		case 'J':	/* Next line */
		case 'j':
		case KEY_DOWN:
			if (end_reached)
				break;

			back_lines(page_length - 1);
			refresh_text_box(dialog, box, boxh, boxw, cur_y,
					 cur_x, update_text, data);
			break;
		case KEY_NPAGE:	/* Next page */
		case ' ':
		case 'd':
			if (end_reached)
				break;

			begin_reached = 0;
			refresh_text_box(dialog, box, boxh, boxw, cur_y,
					 cur_x, update_text, data);
			break;
		case '0':	/* Beginning of line */
		case 'H':	/* Scroll left */
		case 'h':
		case KEY_LEFT:
			if (hscroll <= 0)
				break;

			if (key == '0')
				hscroll = 0;
			else
				hscroll--;
			/* Reprint current page to scroll horizontally */
			back_lines(page_length);
			refresh_text_box(dialog, box, boxh, boxw, cur_y,
					 cur_x, update_text, data);
			break;
		case 'L':	/* Scroll right */
		case 'l':
		case KEY_RIGHT:
			if (hscroll >= MAX_LEN)
				break;
			hscroll++;
			/* Reprint current page to scroll horizontally */
			back_lines(page_length);
			refresh_text_box(dialog, box, boxh, boxw, cur_y,
					 cur_x, update_text, data);
			break;
		case KEY_ESC:
			if (on_key_esc(dialog) == KEY_ESC)
				done = true;
			break;
		case KEY_RESIZE:
			back_lines(height);
			delwin(box);
			delwin(dialog);
			on_key_resize();
			goto do_resize;
		default:
			for (i = 0; keys[i]; i++) {
				if (key == keys[i]) {
					done = true;
					break;
				}
			}
		}
	}
	delwin(box);
	delwin(dialog);
	if (_vscroll) {
		const char *s;

		s = buf;
		*_vscroll = 0;
		back_lines(page_length);
		while (s < page && (s = strchr(s, '\n'))) {
			(*_vscroll)++;
			s++;
		}
	}
	if (_hscroll)
		*_hscroll = hscroll;
	return key;
}

/*
 * Go back 'n' lines in text. Called by dialog_textbox().
 * 'page' will be updated to point to the desired line in 'buf'.
 */
static void back_lines(int n)
{
	int i;

	begin_reached = 0;
	/* Go back 'n' lines */
	for (i = 0; i < n; i++) {
		if (*page == '\0') {
			if (end_reached) {
				end_reached = 0;
				continue;
			}
		}
		if (page == buf) {
			begin_reached = 1;
			return;
		}
		page--;
		do {
			if (page == buf) {
				begin_reached = 1;
				return;
			}
			page--;
		} while (*page != '\n');
		page++;
	}
}

/*
 * Print a new page of text.
 */
static void print_page(WINDOW *win, int height, int width, update_text_fn
		       update_text, void *data)
{
	int i, passed_end = 0;

	if (update_text) {
		char *end;

		for (i = 0; i < height; i++)
			get_line();
		end = page;
		back_lines(height);
		update_text(buf, page - buf, end - buf, data);
	}

	page_length = 0;
	for (i = 0; i < height; i++) {
		print_line(win, i, width);
		if (!passed_end)
			page_length++;
		if (end_reached && !passed_end)
			passed_end = 1;
	}
	wnoutrefresh(win);
}

/*
 * Print a new line of text.
 */
static void print_line(WINDOW * win, int row, int width)
{
	char *line;

	line = get_line();
	line += MIN(strlen(line), hscroll);	/* Scroll horizontally */
	wmove(win, row, 0);	/* move cursor to correct line */
	waddch(win, ' ');
	waddnstr(win, line, MIN(strlen(line), width - 2));

	/* Clear 'residue' of previous line */
#if OLD_NCURSES
	{
		int x = getcurx(win);
		int i;
		for (i = 0; i < width - x; i++)
			waddch(win, ' ');
	}
#else
	wclrtoeol(win);
#endif
}

/*
 * Return current line of text. Called by dialog_textbox() and print_line().
 * 'page' should point to start of current line before calling, and will be
 * updated to point to start of next line.
 */
static char *get_line(void)
{
	int i = 0;
	static char line[MAX_LEN + 1];

	end_reached = 0;
	while (*page != '\n') {
		if (*page == '\0') {
			end_reached = 1;
			break;
		} else if (i < MAX_LEN)
			line[i++] = *(page++);
		else {
			/* Truncate lines longer than MAX_LEN characters */
			if (i == MAX_LEN)
				line[i++] = '\0';
			page++;
		}
	}
	if (i <= MAX_LEN)
		line[i] = '\0';
	if (!end_reached)
		page++;		/* move past '\n' */

	return line;
}

/*
 * Print current position
 */
static void print_position(WINDOW * win)
{
	int percent;

	wattrset(win, dlg.position_indicator.atr);
	wbkgdset(win, dlg.position_indicator.atr & A_COLOR);
	percent = (page - buf) * 100 / strlen(buf);
	wmove(win, getmaxy(win) - 3, getmaxx(win) - 9);
	wprintw(win, "(%3d%%)", percent);
}