summaryrefslogtreecommitdiff
path: root/packages/ncurses/tests
diff options
context:
space:
mode:
authormichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-03-27 21:23:26 +0000
committermichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2008-03-27 21:23:26 +0000
commit1aa0cf6d54dc0a7bdeee1d65e3744a7d712d0045 (patch)
treec88631773d3c4008b9a829cb19710b4ad6322d32 /packages/ncurses/tests
parenta1218787f4d308a39fc8255306ca9b445690241c (diff)
downloadfpc-1aa0cf6d54dc0a7bdeee1d65e3744a7d712d0045.tar.gz
* Support for version 5.6 of ncurses, by Tolstov Igor
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@10573 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/ncurses/tests')
-rw-r--r--packages/ncurses/tests/cotest.pp36
-rw-r--r--packages/ncurses/tests/t1form.pp80
-rw-r--r--packages/ncurses/tests/t1menu.pp64
-rw-r--r--packages/ncurses/tests/t2form.pp186
-rw-r--r--packages/ncurses/tests/t2menu.pp438
-rw-r--r--packages/ncurses/tests/t3form.pp238
-rw-r--r--packages/ncurses/tests/tbackground.pp67
-rw-r--r--packages/ncurses/tests/tclock.pp269
-rw-r--r--packages/ncurses/tests/tevent.pp39
-rw-r--r--packages/ncurses/tests/tmouse.pp144
-rw-r--r--packages/ncurses/tests/tnlshello.pp49
11 files changed, 1610 insertions, 0 deletions
diff --git a/packages/ncurses/tests/cotest.pp b/packages/ncurses/tests/cotest.pp
new file mode 100644
index 0000000000..c9dd3a5811
--- /dev/null
+++ b/packages/ncurses/tests/cotest.pp
@@ -0,0 +1,36 @@
+program const_test;
+
+uses
+ ncurses;
+
+begin
+ //writeln('NCURSES_TRIPLE_CLICKED', NCURSES_TRIPLE_CLICKED);
+ writeln('BUTTON1_RELEASED ', BUTTON1_RELEASED);
+ writeln('BUTTON1_PRESSED ', BUTTON1_PRESSED);
+ writeln('BUTTON1_CLICKED ', BUTTON1_CLICKED);
+ writeln('BUTTON1_DOUBLE_CLICKED ', BUTTON1_DOUBLE_CLICKED);
+ writeln('BUTTON1_TRIPLE_CLICKED ', BUTTON1_TRIPLE_CLICKED);
+
+
+
+ writeln('BUTTON2_RELEASED', BUTTON2_RELEASED);
+ writeln('BUTTON2_PRESSED', BUTTON2_PRESSED);
+ writeln('BUTTON2_CLICKED', BUTTON2_CLICKED);
+ writeln('BUTTON2_DOUBLE_CLICKED', BUTTON2_DOUBLE_CLICKED);
+ writeln('BUTTON2_TRIPLE_CLICKED', BUTTON2_TRIPLE_CLICKED);
+
+ writeln('BUTTON3_RELEASED', BUTTON3_RELEASED);
+ writeln('BUTTON3_PRESSED', BUTTON3_PRESSED);
+ writeln('BUTTON3_CLICKED', BUTTON3_CLICKED);
+ writeln('BUTTON3_DOUBLE_CLICKED', BUTTON3_DOUBLE_CLICKED);
+ writeln('BUTTON3_TRIPLE_CLICKED', BUTTON3_TRIPLE_CLICKED);
+
+ writeln('BUTTON4_RELEASED', BUTTON4_RELEASED);
+ writeln('BUTTON4_PRESSED', BUTTON4_PRESSED);
+ writeln('BUTTON4_CLICKED', BUTTON4_CLICKED);
+ writeln('BUTTON4_DOUBLE_CLICKED', BUTTON4_DOUBLE_CLICKED);
+ writeln('BUTTON4_TRIPLE_CLICKED', BUTTON4_TRIPLE_CLICKED);
+
+
+ //writeln('ALL_MOUSE_EVENTS', ALL_MOUSE_EVENTS);
+end. \ No newline at end of file
diff --git a/packages/ncurses/tests/t1form.pp b/packages/ncurses/tests/t1form.pp
new file mode 100644
index 0000000000..6b45f623ea
--- /dev/null
+++ b/packages/ncurses/tests/t1form.pp
@@ -0,0 +1,80 @@
+program form_basic;
+{
+ Example 25. Forms Basics
+ from ncurses howto
+}
+{$MODE OBJFPC}
+
+uses
+ ncurses, form;
+
+var
+ field: array[0..2] of PFIELD;
+ my_form: PFORM;
+ ch: Longint;
+begin
+
+try
+ (* Initialize curses *)
+ initscr();
+ cbreak();
+ noecho();
+ keypad(stdscr, TRUE);
+
+ (* Initialize the fields *)
+ field[0] := new_field(1, 10, 4, 18, 0, 0);
+ field[1] := new_field(1, 10, 6, 18, 0, 0);
+ field[2] := nil;
+
+ (* Set field options *)
+ set_field_back(field[0], A_UNDERLINE); { Print a line for the option }
+ field_opts_off(field[0], O_AUTOSKIP); { Don't go to next field when this }
+ { Field is filled up }
+ set_field_back(field[1], A_UNDERLINE);
+ field_opts_off(field[1], O_AUTOSKIP);
+
+ (* Create the form and post it *)
+ my_form := new_form(field);
+ post_form(my_form);
+ refresh();
+
+ mvprintw(4, 10, 'Value 1:');
+ mvprintw(6, 10, 'Value 2:');
+ refresh();
+
+ (* Loop through to get user requests *)
+ ch := getch();
+ while ch <> KEY_F(1) do
+ begin
+ case ch of
+ KEY_DOWN:
+ (* Go to next field *)
+ begin
+ form_driver(my_form, REQ_NEXT_FIELD);
+ { Go to the end of the present buffer
+ Leaves nicely at the last character }
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ KEY_UP:
+ (* Go to previous field *)
+ begin
+ form_driver(my_form, REQ_PREV_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ else
+ { If this is a normal character, it gets
+ Printed }
+ form_driver(my_form, ch);
+ end;
+ ch := getch();
+ end
+ finally
+ (* Un post form and free the memory *)
+ unpost_form(my_form);
+ free_form(my_form);
+ free_field(field[0]);
+ free_field(field[1]);
+
+ endwin();
+ end;
+end. \ No newline at end of file
diff --git a/packages/ncurses/tests/t1menu.pp b/packages/ncurses/tests/t1menu.pp
new file mode 100644
index 0000000000..fe8bc00cee
--- /dev/null
+++ b/packages/ncurses/tests/t1menu.pp
@@ -0,0 +1,64 @@
+program Menu_Basics;
+{
+ Example 18. Menu Basics
+ from ncurses howto
+}
+{$MODE OBJFPC}
+
+uses
+ ncurses, menu;
+
+const
+ choices: array[0..4] of PChar =
+ (
+ 'Choice 1',
+ 'Choice 2',
+ 'Choice 3',
+ 'Choice 4',
+ 'Exit'
+ );
+
+
+var
+ my_items: ppITEM;
+ my_menu: pMENU;
+ c, n_choices, i: Longint;
+ cur_item: pITEM;
+begin
+ try
+ initscr();
+ cbreak();
+ noecho();
+ keypad(stdscr, TRUE);
+
+ n_choices := 5;
+ GetMem(my_items, (n_choices+1)*sizeof(pITEM));
+
+ for i := 0 to n_choices - 1 do
+ my_items[i] := new_item(choices[i], choices[i]);
+ my_items[n_choices] := nil;
+
+ my_menu := new_menu(my_items);
+ mvprintw(LINES - 2, 0, 'F1 to Exit');
+ post_menu(my_menu);
+ refresh();
+
+ c := getch();
+ while c <> KEY_F(1) do
+ begin
+ case c of
+ KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM);
+ KEY_UP: menu_driver(my_menu, REQ_UP_ITEM);
+ else
+ end;
+ c := getch();
+ end
+
+ finally
+ free_item(my_items[0]);
+ free_item(my_items[1]);
+ free_menu(my_menu);
+ FreeMem(my_items, (n_choices+1)*sizeof(pITEM));
+ endwin();
+ end;
+end. \ No newline at end of file
diff --git a/packages/ncurses/tests/t2form.pp b/packages/ncurses/tests/t2form.pp
new file mode 100644
index 0000000000..f29bd21ace
--- /dev/null
+++ b/packages/ncurses/tests/t2form.pp
@@ -0,0 +1,186 @@
+program form_test_2;
+
+{$MODE OBJFPC}
+
+uses
+ ncurses, form, libc;
+
+
+var
+ my_bg: NC_FPC_COLOR = COLOR_BLACK;
+
+ field: array[0..5] of PFIELD;
+ my_form: PFORM;
+ i, ch: Longint;
+begin
+
+try
+ setlocale(LC_ALL, ''); { Tested with Russian UTF-8 locale }
+
+ (* Initialize curses *)
+ initscr();
+ cbreak();
+ noecho();
+ keypad(stdscr, TRUE);
+
+ (* Initialize colors *)
+ if has_colors() then
+ begin
+ start_color();
+ if (use_default_colors() = OK) then
+ my_bg := -1
+ else
+ my_bg := COLOR_BLACK;
+
+ init_pair(1, COLOR_YELLOW, my_bg);
+ init_pair(2, COLOR_MAGENTA, my_bg);
+ init_pair(3, COLOR_WHITE, my_bg);
+ init_pair(4, COLOR_WHITE, COLOR_BLUE);
+ init_pair(5, COLOR_WHITE, COLOR_GREEN);
+ init_pair(6, COLOR_YELLOW, COLOR_GREEN);
+ init_pair(7, COLOR_BLACK, COLOR_CYAN);
+ end;
+
+ (* Initialize the fields *)
+ for i := 0 to 3 do
+ begin
+ field[i] := new_field(1, 30, 2 + i * 2, 10, 0, 0);
+ field_opts_off(field[i], O_AUTOSKIP);
+ end;
+
+ field[4] := new_field(7, 30, 2, 42, 0, 0);
+ field[5] := nil;
+
+ (* Set field options *)
+ set_field_fore(field[0], COLOR_PAIR(2));
+ set_field_back(field[0], A_UNDERLINE OR COLOR_PAIR(3));
+
+ set_field_fore(field[1], COLOR_PAIR(1));
+ set_field_back(field[1], A_UNDERLINE OR COLOR_PAIR(1));
+ field_opts_off(field[1], O_ACTIVE);
+
+ set_field_fore(field[2], COLOR_PAIR(4));
+ set_field_back(field[2], A_UNDERLINE OR COLOR_PAIR(4));
+ field_opts_off(field[2], O_PUBLIC);
+
+ set_field_fore(field[3], COLOR_PAIR(5));
+ set_field_back(field[3], A_UNDERLINE OR COLOR_PAIR(5));
+ field_opts_off(field[3], O_STATIC);
+
+ set_field_fore(field[4], COLOR_PAIR(7));
+ set_field_back(field[4], COLOR_PAIR(7));
+
+ (* Create the form and post it *)
+ my_form := new_form(field);
+ post_form(my_form);
+
+ (* Center Justification *)
+ set_field_just(field[0], JUSTIFY_CENTER);
+ set_field_buffer(field[0], 0, 'This is a static Field');
+
+ set_field_just(field[1], JUSTIFY_CENTER);
+ set_field_buffer(field[1], 0, 'This is a inactive Field');
+
+ (* Set focus to the blue field *)
+ set_current_field(my_form, field[0]);
+
+ for i := 0 to 3 do
+ mvprintw(2 + i * 2, 2, 'Value %d:', i + 1);
+ mvaddstr(LINES - 2, 0, 'F1 to Exit');
+ refresh();
+
+ (* Loop through to get user requests *)
+ ch := getch();
+ while (ch <> KEY_F(1)) AND (ch <> 27) do
+ begin
+ case ch of
+ 9: { TAB }
+ begin
+ if form_driver(my_form, REQ_NEXT_WORD) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_NEXT_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ end;
+ KEY_NPAGE:
+ (* Go to next field *)
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_NEXT_FIELD);
+ { Go to the end of the present buffer
+ Leaves nicely at the last character }
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ KEY_PPAGE:
+ (* Go to previous field *)
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_PREV_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ KEY_DOWN:
+ if form_driver(my_form, REQ_DOWN_CHAR) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_DOWN_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ KEY_UP:
+ if form_driver(my_form, REQ_UP_CHAR) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_UP_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ KEY_LEFT:
+ if form_driver(my_form, REQ_LEFT_CHAR) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_LEFT_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ KEY_RIGHT:
+ if form_driver(my_form, REQ_RIGHT_CHAR) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_RIGHT_FIELD);
+ end;
+ KEY_BACKSPACE: form_driver(my_form, REQ_DEL_PREV);
+ 10: { ENTER }
+ begin
+ form_driver(my_form, 10);
+ if form_driver(my_form, REQ_NEXT_LINE) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_NEXT_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ end;
+ else
+ { If this is a normal character, it gets
+ Printed }
+ form_driver(my_form, ch);
+ end;
+ ch := getch();
+ end;
+
+ refresh();
+
+ finally
+ unpost_form(my_form);
+ free_form(my_form);
+ endwin();
+
+ for i := 0 to 4 do
+ begin
+ if field_status(field[i]) then
+ begin
+ writeln;
+ writeln('Value ', i,':');
+ writeln(field_buffer(field[i], 0));
+ end;
+ free_field(field[i]);
+ end
+ end;
+end. \ No newline at end of file
diff --git a/packages/ncurses/tests/t2menu.pp b/packages/ncurses/tests/t2menu.pp
new file mode 100644
index 0000000000..8cd5d5ad8e
--- /dev/null
+++ b/packages/ncurses/tests/t2menu.pp
@@ -0,0 +1,438 @@
+{$MODE OBJFPC}
+program Menu_Example;
+
+
+uses
+ ncurses, menu, panel, sysutils;
+
+
+function st_middle(scrlen, itemlen: Smallint): Smallint; inline;
+begin
+ st_middle := (scrlen - itemlen) div 2;
+end;
+
+procedure print_in_middle(win: PWINDOW; starty, startx: Smallint;
+ width: Longint; pair: NC_FPC_COLOR;
+ const fmt: AnsiString; args: array of const);
+var
+ tstr: AnsiString;
+ my, mx: Smallint;
+begin
+ FmtStr(tstr, fmt, args);
+ getmaxyx(win, my, mx);
+ mx -= startx;
+
+ if (width > length(tstr)) OR (width < 2) then
+ width := length(tstr);
+
+ if width > mx then
+ width := mx;
+
+ wattron(win,pair);
+ mvwaddnstr(win,starty,startx + st_middle(mx,width),PChar(tstr),width);
+ wattroff(win,pair);
+end;
+
+
+type
+ PMinfo = ^TMinfo;
+ TMinfo = record
+ n, d: PChar;
+ end;
+
+
+type
+ TSubmenu = class
+ private
+ _win: PWINDOW;
+ _pan: PPANEL;
+ _items: ppITEM;
+ _exit, _sitem: pITEM;
+ _menu: pMENU;
+ public
+ function doevent: chtype;
+ constructor create(szy,szx,nch: Smallint; choices: PMinfo;
+ pair: NC_FPC_COLOR;const name: AnsiString);
+ destructor destroy; override;
+ property menu: pMENU read _menu;
+ property items: ppITEM read _items;
+ property sitem: pITEM read _sitem write _sitem ;
+ property win: PWINDOW read _win;
+ property pan: PPANEL read _pan;
+ end;
+
+function TSubmenu.doevent: chtype;
+
+function doenter(var ch: chtype): Boolean;
+begin
+ if current_item(_menu) = _exit then
+ begin
+ doenter := false;
+ ch := -1
+ end
+ else
+ if current_item(_menu) = sitem then
+ begin
+ doenter := false;
+ ch := 10
+ end
+ else
+ doenter := true;
+end;
+
+var
+ ch: chtype = 0;
+ doiter: Boolean = true;
+begin
+ while doiter do
+ begin
+ ch := wgetch(_win);
+ case ch of
+ KEY_DOWN: menu_driver(_menu, REQ_DOWN_ITEM);
+ KEY_UP: menu_driver(_menu, REQ_UP_ITEM);
+ KEY_LEFT: menu_driver(_menu, REQ_LEFT_ITEM);
+ KEY_RIGHT: menu_driver(_menu, REQ_RIGHT_ITEM);
+ KEY_NPAGE: menu_driver(_menu, REQ_SCR_DPAGE);
+ KEY_PPAGE: menu_driver(_menu, REQ_SCR_UPAGE);
+ chtype(' '): menu_driver(_menu, REQ_TOGGLE_ITEM);
+ 10: doiter := doenter(ch); (* Enter *)
+ else
+ if menu_driver(_menu, ch) <> E_OK then
+ begin
+ doiter := false;
+ if (ch <> chtype('q')) AND (ch <> KEY_F(10)) then
+ ch := -1; (* Close menu *)
+ end
+ else
+ if (ch = KEY_MOUSE) then
+ doiter := doenter(ch);
+ end;
+ end;
+ update_panels();
+ doupdate();
+ doevent := ch;
+end;
+
+constructor TSubmenu.create(szy,szx,nch: Smallint; choices: PMinfo;
+ pair: NC_FPC_COLOR;const name: AnsiString);
+var
+ i: Longint = 0;
+ sy,sx: Smallint;
+ //mrows,mcols: Longint;
+begin
+ GetMem(_items, (nch+1)*sizeof(pITEM));
+ for i := 0 to nch - 1 do
+ _items[i] := new_item(choices[i].n, choices[i].d);
+ _items[nch] := nil;
+ _exit := _items[i];
+ sitem := nil;
+
+ _menu := new_menu(_items);
+
+ //scale_menu(_menu, @mrows, @mcols);
+ _win := newwin(szy,szx,st_middle(LINES,szy),st_middle(COLS,szx));
+ //_win := newwin(mrows + 2, mcols + 2, st_middle(LINES,mrows+2),st_middle(COLS,mcols+2));
+ _pan := new_panel(_win);
+
+ keypad(_win, TRUE);
+ box(_win, ACS_VLINE, ACS_HLINE);
+
+ wbkgd(_win, COLOR_PAIR(pair));
+ set_menu_back(_menu, COLOR_PAIR(pair));
+
+ print_in_middle(_win,0,0,szx-2,pair,name,[]);
+
+ set_menu_win(_menu, _win);
+ set_menu_sub(_menu, derwin(_win, szy-2, szx-2, 1, 1));
+ //set_menu_sub(_menu, derwin(_win, mrows, mcols, 1, 1));
+ set_menu_mark(_menu, '-');
+end;
+
+destructor TSubmenu.destroy;
+var
+ i: Longint = 0;
+begin
+ unpost_menu(_menu);
+ free_menu(_menu);
+ while _items[i] <> nil do
+ begin
+ free_item(_items[i]); Inc(i);
+ end;
+ FreeMem(_items, (i+1)*sizeof(pITEM));
+
+ del_panel(_pan);
+ delwin(_win);
+ update_panels();
+ doupdate();
+end;
+
+
+type
+ Tmainptr = function: chtype;
+
+const
+ EXIT_PROGRAM = KEY_MAX + 100;
+
+function confirm_menu: chtype;
+const
+ choices: array[0..2] of TMinfo =
+ (
+ (n:' Yes ';d:nil),
+ (n:'I dont know';d:nil),
+ (n:' No ';d:nil)
+ );
+var
+ smenu: TSubmenu;
+ i: Longint;
+begin
+ smenu := TSubmenu.create(3, 41,3,choices,5,'Do you really want to quit?');
+
+ menu_opts_off(smenu.menu, O_SHOWDESC);
+ set_menu_format(smenu.menu, 1, 3);
+ post_menu(smenu.menu);
+
+ smenu.sitem := smenu.items[0];
+
+ confirm_menu := smenu.doevent;
+
+ if (confirm_menu = 10) OR (confirm_menu = chtype('q')) OR (confirm_menu = KEY_F(10)) then
+ confirm_menu := EXIT_PROGRAM
+ else
+ confirm_menu := -1;
+ smenu.destroy;
+end;
+
+
+(* Scrolling Menus example *)
+
+function scroll_menu: chtype;
+const
+ choices: array[0..9] of TMinfo =
+ (
+ (n: '1_'; d: 'Choice'),
+ (n: '2_'; d: 'Choice'),
+ (n: '3_'; d: 'Choice'),
+ (n: '4_'; d: 'Choice'),
+ (n: '5_'; d: 'Choice'),
+ (n: '6_'; d: 'Choice'),
+ (n: '7_'; d: 'Choice'),
+ (n: '8_'; d: 'Choice'),
+ (n: '9_'; d: 'Choice'),
+ (n: '..'; d: 'Close')
+ );
+var
+ smenu: TSubmenu;
+ i: Longint;
+begin
+ mvaddstr(LINES - 3, COLS - 30, '"PAGEUP" "PAGEDOWN" - scroll');
+ refresh();
+ smenu := TSubmenu.create(8, 13,10,choices,6,'Scrolling');
+
+ set_menu_format(smenu.menu, 6, 1);
+ post_menu(smenu.menu);
+
+ scroll_menu := smenu.doevent;
+ smenu.destroy;
+ mvaddstr(LINES - 3, COLS - 30, ' ');
+ refresh();
+end;
+
+
+(* Milt Columnar Menus Example *)
+
+function multicol_menu: chtype;
+const
+ choices: array[0..24] of TMinfo =
+ (
+ (n:'1_';d:nil),(n:'2_';d:nil),(n:'3_';d:nil),(n:'4_';d:nil),(n:'5_';d:nil),
+ (n:'6_';d:nil),(n:'7_';d:nil),(n:'8_';d:nil),(n:'9_';d:nil),(n:'10';d:nil),
+ (n:'11';d:nil),(n:'12';d:nil),(n:'13';d:nil),(n:'14';d:nil),(n:'15';d:nil),
+ (n:'16';d:nil),(n:'17';d:nil),(n:'18';d:nil),(n:'19';d:nil),(n:'20';d:nil),
+ (n:'21';d:nil),(n:'22';d:nil),(n:'23';d:nil),(n:'24';d:nil),(n:'..';d:nil)
+ );
+var
+ smenu: TSubmenu;
+ i: Longint;
+begin
+ smenu := TSubmenu.create(7, 22,25,choices,5,'Multicol');
+
+(* Set menu option not to show the description *)
+ menu_opts_off(smenu.menu, O_SHOWDESC);
+ set_menu_format(smenu.menu, 5, 5);
+ post_menu(smenu.menu);
+
+ multicol_menu := smenu.doevent;
+ smenu.destroy;
+end;
+
+
+(* Multi Valued Menus example *)
+
+function multival_menu: chtype;
+const
+ choices: array[0..5] of TMinfo =
+ (
+ (n: '1_'; d: 'Choice'),
+ (n: '2_'; d: 'Choice'),
+ (n: '3_'; d: 'Choice'),
+ (n: '4_'; d: 'Choice'),
+ (n: '5_'; d: 'Choice'),
+ (n: '..'; d: 'Close')
+ );
+var
+ smenu: TSubmenu;
+ i: Longint;
+begin
+ mvaddstr(LINES - 3, COLS - 30, '"SPACE" - toggle choice');
+ refresh();
+ smenu := TSubmenu.create(8, 13,6,choices,7,'Multival');
+
+ menu_opts_off(smenu.menu, O_ONEVALUE);
+ post_menu(smenu.menu);
+
+ multival_menu := smenu.doevent;
+ smenu.destroy;
+ mvaddstr(LINES - 3, COLS - 30, ' ');
+ refresh();
+end;
+
+
+const
+ n_choices = 4;
+ choices: array[0..3] of TMinfo =
+ (
+ (n: '1_'; d: 'Scrolling Menus'),
+ (n: '2_'; d: 'Multi Columnar Menus'),
+ (n: '3_'; d: 'Multi Valued Menus'),
+ (n: '..'; d: 'Exit')
+ );
+
+var
+ main_menu_win: PWINDOW;
+ main_menu_panel: PPANEL;
+
+function mgetch: chtype;
+begin
+ mgetch := wgetch(main_menu_win);
+end;
+
+var
+ my_bg: NC_FPC_COLOR = COLOR_BLACK;
+
+ main_items: ppITEM;
+ cur_item: pITEM;
+ main_menu: pMENU;
+ ptr: Tmainptr = @mgetch;
+
+ ch: chtype = -1;
+ i: Longint;
+ tstr: AnsiString;
+begin
+ try
+ (* Initialize curses *)
+ initscr();
+ noecho();
+ cbreak();
+ keypad(stdscr, TRUE);
+ curs_set(0);
+ clear();
+ mousemask(ALL_MOUSE_EVENTS, nil);
+
+ if has_colors() then
+ begin
+ start_color();
+ if (use_default_colors() = OK) then
+ my_bg := -1
+ else
+ my_bg := COLOR_BLACK;
+
+ init_pair(1, COLOR_YELLOW, my_bg);
+ init_pair(2, COLOR_RED, my_bg);
+ init_pair(3, COLOR_MAGENTA, my_bg);
+ init_pair(4, COLOR_CYAN, my_bg);
+ init_pair(5, COLOR_WHITE, COLOR_RED);
+ init_pair(6, COLOR_WHITE, COLOR_BLUE);
+ init_pair(7, COLOR_WHITE, COLOR_GREEN);
+ end;
+
+ main_menu_win := newwin(8, 40, st_middle(LINES, 8) - 2, st_middle(COLS, 40) - 10);
+ main_menu_panel := new_panel(main_menu_win);
+ keypad(main_menu_win, TRUE);
+
+ (* Create items *)
+ GetMem(main_items, (n_choices+1)*sizeof(pITEM));
+ for i := 0 to n_choices-1 do
+ main_items[i] := new_item(choices[i].n, choices[i].d);
+ main_items[n_choices] := nil;
+
+ (* Set the user pointers *)
+ set_item_userptr(main_items[0], @scroll_menu);
+ set_item_userptr(main_items[1], @multicol_menu);
+ set_item_userptr(main_items[2], @multival_menu);
+ set_item_userptr(main_items[3], @confirm_menu);
+
+ (* Crate menu *)
+ main_menu := new_menu(main_items);
+
+ (* Set main window and sub window *)
+ set_menu_win(main_menu, main_menu_win);
+ set_menu_sub(main_menu, derwin(main_menu_win, 4, 38, 3, 1));
+
+ (* Set menu mark to the string "=>" *)
+ set_menu_mark(main_menu, '=>');
+
+ (* Print a border around the main window and print a title *)
+ box(main_menu_win, 0, 0);
+ wbkgd(main_menu_win, COLOR_PAIR(6));
+ set_menu_back(main_menu, COLOR_PAIR(6));
+
+ print_in_middle(main_menu_win, 1, 0, 40, COLOR_PAIR(6), 'Main Menu', []);
+ mvwaddch(main_menu_win, 2, 0, ACS_LTEE);
+ mvwhline(main_menu_win, 2, 1, ACS_HLINE, 38);
+ mvwaddch(main_menu_win, 2, 39, ACS_RTEE);
+ attron(COLOR_PAIR(4));
+ mvaddstr(LINES - 1, COLS - 30, 'Press "F10" or "q" to exit ');
+ attroff(COLOR_PAIR(4));
+ refresh();
+
+ (* Post the menu *)
+ post_menu(main_menu);
+ wrefresh(main_menu_win);
+
+ while ch <> EXIT_PROGRAM do
+ begin
+ case ch of
+ KEY_DOWN: menu_driver(main_menu, REQ_DOWN_ITEM);
+ KEY_UP: menu_driver(main_menu, REQ_UP_ITEM);
+ -1: ptr := @mgetch; (* Restore ptr *)
+ 10: (* Enter *)
+ begin
+ cur_item := current_item(main_menu); (* get current item *)
+ ptr := Tmainptr(item_userptr(cur_item)); (* set ptr to current item *)
+ end;
+ else
+ (* Process mouse and others events *)
+ if (menu_driver(main_menu, ch) = E_OK) AND (ch = KEY_MOUSE) then
+ begin
+ cur_item := current_item(main_menu);
+ ptr := Tmainptr(item_userptr(cur_item));
+ end;
+ end;
+ ch := ptr(); (* Call ptr function *)
+
+ if (ch = chtype('q')) OR (ch = KEY_F(10)) then
+ ch := confirm_menu();
+ end;
+
+ finally
+ unpost_menu(main_menu);
+ free_menu(main_menu);
+ for i := 0 to n_choices - 1 do
+ free_item(main_items[i]);
+ FreeMem(main_items, (n_choices+1)*sizeof(pITEM));
+ del_panel(main_menu_panel);
+ delwin(main_menu_win);
+ curs_set(1);
+ endwin();
+ end;
+end. \ No newline at end of file
diff --git a/packages/ncurses/tests/t3form.pp b/packages/ncurses/tests/t3form.pp
new file mode 100644
index 0000000000..41c27bfc03
--- /dev/null
+++ b/packages/ncurses/tests/t3form.pp
@@ -0,0 +1,238 @@
+program form_test_3;
+
+{$MODE OBJFPC}
+
+uses
+ ncurses, form, libc;
+
+
+
+function st_middle(scrlen, itemlen: Smallint): Smallint; inline;
+begin
+ st_middle := (scrlen - itemlen) div 2;
+end;
+
+
+procedure draw;
+
+function randomchar: chtype;
+var
+ ch: Char = #0;
+begin
+ while not (ch in ['0'..'9','A'..'Z','a'..'z']) do
+ ch := Char(Random(123));
+ randomchar := chtype(ch);
+end;
+
+function randompair: longint;
+var
+ pair: longint = 0;
+begin
+ while not (pair in [1..5]) do
+ pair := Random(6);
+ randompair := pair;
+end;
+
+var
+ y, x: Smallint;
+begin
+ for y := 0 to LINES - 1 do
+ for x := 0 to COLS - 1 do
+ mvaddch(y, x, randomchar OR COLOR_PAIR(randompair));
+end;
+
+const
+ enumval: array[0..2] of PChar = ('one', 'two', 'three');
+ desc: array[0..5] of PChar =
+ (
+ 'TYPE_ALPHA Char data, a min width 8',
+ 'TYPE_ENUM one, two, three',
+ 'TYPE_INTEGER -300 .. 300',
+ 'TYPE_NUMERIC -30.0 .. 30.0',
+ 'TYPE_REGEXP ^http://.+\.(ru|net|com)\s*$',
+ 'TYPE_IPV4 An IP Version 4 address.'
+ );
+var
+ my_bg: NC_FPC_COLOR = COLOR_BLACK;
+ form_win: PWINDOW;
+
+ pair: Smallint;
+ field: array[0..6] of PFIELD;
+ my_form: PFORM;
+ i, frows, fcols, ch: Longint;
+begin
+
+try
+ setlocale(LC_ALL, '');
+
+ (* Initialize curses *)
+ initscr();
+ cbreak();
+ noecho();
+ keypad(stdscr, TRUE);
+
+ (* Initialize colors *)
+ if has_colors() then
+ begin
+ start_color();
+ if (use_default_colors() = OK) then
+ my_bg := -1
+ else
+ my_bg := COLOR_BLACK;
+
+ init_pair(1, COLOR_YELLOW, my_bg);
+ init_pair(2, COLOR_MAGENTA, my_bg);
+ init_pair(3, COLOR_WHITE, my_bg);
+ init_pair(4, COLOR_CYAN, my_bg);
+ init_pair(5, COLOR_GREEN, my_bg);
+ init_pair(6, COLOR_WHITE, COLOR_BLUE);
+ init_pair(7, COLOR_BLACK, COLOR_CYAN);
+ end;
+
+
+ for i := 0 to 5 do
+ begin
+ field[i] := new_field(1, 30, 2 + i * 3, 10, 0, 0);
+ field_opts_off(field[i], O_AUTOSKIP);
+ if i AND 1 = 0 then
+ pair := 7
+ else
+ pair := 6;
+ set_field_fore(field[i], COLOR_PAIR(pair));
+ set_field_back(field[i], A_UNDERLINE OR COLOR_PAIR(pair));
+ //set_field_pad(field[i],chtype(' '));
+ end;
+ draw;
+ refresh();
+
+ field[6] := nil;
+
+ set_field_type(field[0],TYPE_ALPHA,8);
+ set_field_type(field[1],TYPE_ENUM,PPChar(enumval),0,0);
+ set_field_type(field[2],TYPE_INTEGER,3,-300,300);
+ set_field_type(field[3],TYPE_NUMERIC,8,-30.0,30.0);
+ set_field_type(field[4],TYPE_REGEXP,'^http://.+\.(ru|net|com)\s*$');
+ set_field_type(field[5],TYPE_IPV4);
+
+
+ my_form := new_form(field);
+
+(* Calculate the area required for the form *)
+ scale_form(my_form, @frows, @fcols);
+
+(* Create the window to be associated with the form *)
+ //form_win := newwin(rows + 4, cols + 4, 4, 4);
+ form_win := newwin(frows + 4, fcols + 4, st_middle(LINES,frows+4), st_middle(COLS,fcols+4));
+ keypad(form_win, TRUE);
+
+(* Set main window and sub window *)
+ set_form_win(my_form, form_win);
+ set_form_sub(my_form, derwin(form_win, frows, fcols, 2, 2));
+
+(* Print a border around the main window and print a title *)
+ box(form_win, 0, 0);
+ //print_in_middle(my_form_win, 1, 0, cols + 4, "My Form", COLOR_PAIR(1));
+
+ post_form(my_form);
+ wrefresh(form_win);
+
+ for i := 0 to 5 do
+ mvwaddstr(form_win, 3 + i * 3, 1,desc[i]);
+ wrefresh(form_win);
+
+ //set_field_buffer(field[0], 0, 'Test Field');
+ //refresh();
+
+ (* Loop through to get user requests *)
+ ch := wgetch(form_win);
+ while (ch <> KEY_F(1)) AND (ch <> 27) do
+ begin
+ case ch of
+ 9: { TAB }
+ begin
+ if form_driver(my_form, REQ_NEXT_WORD) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_NEXT_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ end;
+ KEY_NPAGE:
+ (* Go to next field *)
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_NEXT_FIELD);
+ { Go to the end of the present buffer
+ Leaves nicely at the last character }
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ KEY_PPAGE:
+ (* Go to previous field *)
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_PREV_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ KEY_DOWN:
+ if form_driver(my_form, REQ_DOWN_CHAR) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_DOWN_FIELD);
+ end;
+ KEY_UP:
+ if form_driver(my_form, REQ_UP_CHAR) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_UP_FIELD);
+ end;
+ KEY_LEFT:
+ if form_driver(my_form, REQ_LEFT_CHAR) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_LEFT_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ KEY_RIGHT:
+ if form_driver(my_form, REQ_RIGHT_CHAR) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_RIGHT_FIELD);
+ end;
+ KEY_BACKSPACE: form_driver(my_form, REQ_DEL_PREV);
+ 10: { ENTER }
+ begin
+ form_driver(my_form, 10);
+ if form_driver(my_form, REQ_NEXT_LINE) <> E_OK then
+ begin
+ form_driver(my_form, REQ_VALIDATION);
+ form_driver(my_form, REQ_NEXT_FIELD);
+ form_driver(my_form, REQ_END_LINE);
+ end;
+ end;
+ else
+ { If this is a normal character, it gets
+ Printed }
+ form_driver(my_form, ch);
+ end;
+ ch := wgetch(form_win);
+ end;
+
+ finally
+
+ unpost_form(my_form);
+ free_form(my_form);
+ delwin(form_win);
+ endwin();
+
+ for i := 0 to 5 do
+ begin
+ if field_status(field[i]) then
+ begin
+ writeln;
+ writeln('Value ', i,':');
+ writeln(field_buffer(field[i], 0));
+ end;
+ free_field(field[i]);
+ end
+ end;
+end. \ No newline at end of file
diff --git a/packages/ncurses/tests/tbackground.pp b/packages/ncurses/tests/tbackground.pp
new file mode 100644
index 0000000000..6d04b7a96c
--- /dev/null
+++ b/packages/ncurses/tests/tbackground.pp
@@ -0,0 +1,67 @@
+
+uses
+ ncurses;
+
+var
+ f, b: Smallint;
+begin
+
+ initscr();
+ cbreak();
+ noecho();
+
+ if (has_colors()) then
+ begin
+ start_color();
+
+ pair_content(0, @f, @b);
+ printw(PChar('pair 0 contains (%d,%d)'#10), f, b);
+ getch();
+
+ printw('Initializing pair 1 to red/black'#10);
+ init_pair(1, COLOR_RED, COLOR_BLACK);
+ bkgdset(chtype(' ') OR COLOR_PAIR(1));
+ printw('RED/BLACK'#10);
+ getch();
+
+ printw('Initializing pair 2 to white/blue'#10);
+ init_pair(2, COLOR_WHITE, COLOR_BLUE);
+ bkgdset(chtype(' ') OR COLOR_PAIR(2));
+ printw('WHITE/BLUE'#10);
+ getch();
+
+ printw('Resetting colors to pair 0'#10);
+ bkgdset(chtype(' ') OR COLOR_PAIR(0));
+ printw('Default Colors'#10);
+ getch();
+
+ printw('Resetting colors to pair 1'#10);
+ bkgdset(chtype(' ') OR COLOR_PAIR(1));
+ printw('RED/BLACK'#10);
+ getch();
+
+ printw('Setting screen to pair 0'#10);
+ bkgd(chtype(' ') OR COLOR_PAIR(0));
+ getch();
+
+ printw('Setting screen to pair 1'#10);
+ bkgd(chtype(' ') OR COLOR_PAIR(1));
+ getch();
+
+ printw('Setting screen to pair 2'#10);
+ bkgd(chtype(' ') OR COLOR_PAIR(2));
+ getch();
+
+ printw('Setting screen to pair 0'#10);
+ bkgd(chtype(' ') OR COLOR_PAIR(0));
+ getch();
+
+ end
+ else
+ begin
+ printw('This demo requires a color terminal'#10);
+
+ getch();
+ end;
+ endwin();
+end.
diff --git a/packages/ncurses/tests/tclock.pp b/packages/ncurses/tests/tclock.pp
new file mode 100644
index 0000000000..6bae8ca257
--- /dev/null
+++ b/packages/ncurses/tests/tclock.pp
@@ -0,0 +1,269 @@
+program tclock;
+{$MODE OBJFPC}
+
+uses
+ libc, ncurses, sysutils;
+
+const
+ ASPECT = 2.2;
+ _2PI = 2.0 * PI;
+
+function sign(_x: Integer): Integer;
+begin
+ if _x < 0 then
+ sign := -1
+ else
+ sign := 1
+end;
+
+function A2X(angle,radius: Double): Integer; inline;
+begin
+ A2X := round(ASPECT * radius * sin(angle))
+end;
+
+function A2Y(angle,radius: Double): Integer; inline;
+begin
+ A2Y := round(radius * cos(angle))
+end;
+
+type
+ PRchar = ^TRchar;
+ TRchar = record
+ ry,rx: Smallint;
+ rch: chtype;
+ end;
+
+procedure restore( rest: PRchar );
+var
+ i: Longint = 0;
+begin
+ while rest[i].rch <> 0 do
+ begin
+ with rest[i] do
+ mvaddch(ry, rx, rch);
+ Inc(i);
+ end;
+ freemem(rest)
+end;
+
+(* Draw a diagonal(arbitrary) line using Bresenham's alogrithm. *)
+procedure dline(from_y, from_x, end_y, end_x: Smallint; ch: chtype; var rest: PRchar);
+var
+ dx, dy: Smallint;
+ ax, ay: Smallint;
+ sx, sy: Smallint;
+ x, y, d, i: Smallint;
+begin
+ dx := end_x - from_x;
+ dy := end_y - from_y;
+
+ ax := abs(dx * 2);
+ ay := abs(dy * 2);
+
+ sx := sign(dx);
+ sy := sign(dy);
+
+ x := from_x;
+ y := from_y;
+
+ i := 0;
+ if (ax > ay) then
+ begin
+ getmem(rest, sizeof(TRchar)*(abs(dx)+3));
+ d := ay - (ax DIV 2);
+
+ while true do
+ begin
+ move(y, x);
+ with rest[i] do
+ begin
+ rch := inch;
+ ry := y;
+ rx := x;
+ Inc(i)
+ end;
+ addch(ch);
+ if (x = end_x) then
+ begin
+ rest[i].rch := 0;
+ exit;
+ end;
+
+ if (d >= 0) then
+ begin
+ y += sy;
+ d -= ax;
+ end;
+ x += sx;
+ d += ay;
+ end
+ end
+ else
+ begin
+ getmem(rest, sizeof(TRchar)*(abs(dy)+3));
+ d := ax - (ay DIV 2);
+
+ while true do
+ begin
+ move(y, x);
+ with rest[i] do
+ begin
+ rch := inch;
+ ry := y;
+ rx := x;
+ Inc(i)
+ end;
+ addch(ch);
+ if (y = end_y) then
+ begin
+ rest[i].rch := 0;
+ exit;
+ end;
+
+ if (d >= 0) then
+ begin
+ x += sx;
+ d -= ay;
+ end;
+ y += sy;
+ d += ax;
+ end
+ end
+end;
+
+
+var
+ cx, cy: Integer;
+ cr, sradius, mradius, hradius: Double;
+
+
+procedure clockinit;
+const
+ title1 = 'Free pascal';
+ title2 = 'ncurses clock';
+ title3 = 'Press F10 or q to exit';
+var
+ i: Integer;
+ vstr, tstr: AnsiString;
+ angle: Double;
+begin
+ cx := (COLS - 1) DIV 2;
+ cy := LINES DIV 2;
+ if (cx / ASPECT < cy) then
+ cr := cx / ASPECT
+ else
+ cr := cy;
+
+ sradius := (8 * cr) / 9;
+ mradius := (3 * cr) / 4;
+ hradius := cr / 2;
+
+
+ for i := 1 to 24 do
+ begin
+ angle := i * _2PI / 24.0;
+
+
+ if (i MOD 2) = 0 then
+ begin
+ Str (i DIV 2, tstr);
+ attron(A_BOLD OR COLOR_PAIR(5));
+ mvaddstr(cy - A2Y(angle, sradius), cx + A2X(angle, sradius), @tstr[1]);
+ attroff(A_BOLD OR COLOR_PAIR(5));
+ end
+ else
+ begin
+ attron(COLOR_PAIR(1));
+ mvaddch(cy - A2Y(angle, sradius), cx + A2X(angle, sradius), chtype('.'));
+ attroff(COLOR_PAIR(1));
+ end
+ end;
+
+ vstr := curses_version;
+
+ attron(A_DIM OR COLOR_PAIR(2));
+ mvhline(cy , cx - round(sradius * ASPECT) + 1, ACS_HLINE, round(sradius * ASPECT) * 2 - 1);
+ mvvline(cy - round(sradius) + 1, cx , ACS_VLINE, round(sradius) * 2 - 1);
+ attroff(A_DIM OR COLOR_PAIR(1));
+ attron(COLOR_PAIR(3));
+ mvaddstr(cy - 5, cx - Length(title1) DIV 2, title1);
+ mvaddstr(cy - 4, cx - Length(title2) DIV 2, title2);
+ mvaddstr(cy - 3, cx - Length(vstr) DIV 2, PChar(vstr));
+ attroff(COLOR_PAIR(3));
+ attron(A_UNDERLINE);
+ mvaddstr(cy + 2, cx - Length(title3) DIV 2, title3);
+ attroff(A_UNDERLINE);
+end;
+
+
+var
+ angle: Double;
+ ch: chtype;
+ Hour, Min, Sec, Msec: Word;
+ Hrest, Mrest, Srest: PRchar;
+ timestr: AnsiString;
+ my_bg: NC_FPC_COLOR = COLOR_BLACK;
+begin
+ setlocale(LC_ALL, '');
+
+ try
+ initscr();
+ noecho();
+ cbreak();
+
+ halfdelay(10);
+ keypad(stdscr, TRUE);
+ curs_set(0);
+
+ if (has_colors()) then
+ begin
+ start_color();
+ if (use_default_colors() = OK) then
+ my_bg := -1;
+
+ init_pair(1, COLOR_YELLOW, my_bg);
+ init_pair(2, COLOR_RED, my_bg);
+ init_pair(3, COLOR_GREEN, my_bg);
+ init_pair(4, COLOR_CYAN, my_bg);
+ init_pair(5, COLOR_YELLOW, COLOR_BLACK) ;
+ end;
+
+ clockinit;
+ repeat
+ if (ch = KEY_RESIZE) then
+ begin
+ flash();
+ erase();
+ wrefresh(curscr);
+ clockinit;
+ end;
+
+ decodeTime(Time, Hour, Min, Sec, Msec);
+ Hour := Hour MOD 12;
+
+ timestr := DateTimeToStr(Now);
+ mvaddstr(cy + round(sradius) - 4, cx - Length(timestr) DIV 2, PChar(timestr));
+
+ angle := Hour * _2PI / 12;
+ dline(cy, cx, cy - A2Y(angle, hradius), cx + A2X(angle, hradius), chtype('*'),Hrest);
+
+ angle := Min * _2PI / 60;
+ dline(cy, cx, cy - A2Y(angle, mradius), cx + A2X(angle, mradius), chtype('*'),Mrest);
+
+ angle := Sec * _2PI / 60;
+ dline(cy, cx, cy - A2Y(angle, sradius), cx + A2X(angle, sradius), chtype('.'),Srest);
+
+ wsyncup(stdscr);
+ refresh;
+ ch := getch();
+
+ restore(Srest);
+ restore(Mrest);
+ restore(Hrest);
+
+ until (ch = chtype('q')) OR (ch = KEY_F(10));
+ finally
+ curs_set(1);
+ endwin();
+ end;
+end.
diff --git a/packages/ncurses/tests/tevent.pp b/packages/ncurses/tests/tevent.pp
new file mode 100644
index 0000000000..aacbd7a102
--- /dev/null
+++ b/packages/ncurses/tests/tevent.pp
@@ -0,0 +1,39 @@
+program test_event;
+
+{$MODE OBJFPC}
+
+uses
+ ncurses, sysutils;
+
+
+var
+ ch: chtype;
+begin
+ try
+ initscr();
+ noecho();
+ clear();
+ cbreak();
+ keypad(stdscr, TRUE);
+ mousemask(1, nil);
+
+ mvaddstr(1, 1,'press F10 or q to exit');
+ mvaddstr(2, 1,'press 1 to cbreak mode');
+ mvaddstr(3, 1,'press 2 to raw mode');
+ mvaddstr(4, 1,'press 3 to halfdelay(10) mode');
+ repeat
+ ch := getch;
+ mvaddstr(LINES - 1, 1,' ');
+ case ch of
+ ERR: mvaddstr(LINES - 1, 1,'timeout: 1 sec');
+ chtype('1'): cbreak();
+ chtype('2'): raw();
+ chtype('3'): halfdelay(10);
+ else
+ mvaddstr(LINES - 1, 1,PChar(Format('name:%-14s code:%d', [ keyname(ch), ch ] )));
+ end;
+ until (ch = chtype('q')) OR (ch = KEY_F(10));
+ finally
+ endwin();
+ end;
+end. \ No newline at end of file
diff --git a/packages/ncurses/tests/tmouse.pp b/packages/ncurses/tests/tmouse.pp
new file mode 100644
index 0000000000..2ae485f09b
--- /dev/null
+++ b/packages/ncurses/tests/tmouse.pp
@@ -0,0 +1,144 @@
+program mouse_test;
+{$MODE OBJFPC}
+{$COPERATORS ON}
+
+
+uses
+ ncurses, panel, sysutils;
+
+procedure draw;
+
+function randomchar: chtype;
+var
+ ch: Char = #0;
+begin
+ while not (ch in ['0'..'9','A'..'Z','a'..'z']) do
+ ch := Char(Random(123));
+ randomchar := chtype(ch);
+end;
+
+function randompair: longint;
+var
+ pair: longint = 0;
+begin
+ while not (pair in [1..5]) do
+ pair := Random(6);
+ randompair := pair;
+end;
+
+var
+ y, x: Smallint;
+begin
+ for y := 0 to 2 do
+ for x := 0 to COLS - 7 do
+ mvaddch(y, x, randomchar OR COLOR_PAIR(randompair));
+ attron(A_BOLD OR COLOR_PAIR(7));
+ mvaddstr(0, COLS - 6, ' ');
+ mvaddstr(1, COLS - 6, ' QUIT ');
+ mvaddstr(2, COLS - 6, ' ');
+ attroff(A_BOLD OR COLOR_PAIR(7));
+ for y := 3 to LINES - 1 do
+ for x := 0 to COLS - 1 do
+ mvaddch(y, x, randomchar OR COLOR_PAIR(randompair));
+end;
+
+
+var
+ win: PWINDOW;
+ pan: PPANEL;
+ str: AnsiString;
+function doevent: chtype;
+var
+ event: MEVENT;
+begin
+ getmouse(@event);
+ if (event.y > 2) OR (event.x < COLS - 6) then
+ begin
+ mvwaddstr(win, 1, 1, ' ');
+ str := Format('y := %D, x := %D', [event.y, event.x]);
+ mvwaddstr(win, 1, 2, PChar(str));
+ wattron(win,A_BOLD);
+ mvwaddch(win, 3, 9, mvinch(event.y,event.x ));
+ wattroff(win,A_BOLD);
+ halfdelay(12);
+
+ show_panel(pan);
+
+ if event.bstate AND BUTTON1_RELEASED<> 0 then
+ mvwaddstr(win, 5, 2,'BUTTON1_RELEASED')
+ else if event.bstate AND BUTTON2_RELEASED <> 0 then
+ mvwaddstr(win, 5, 2,'BUTTON2_RELEASED')
+ else if event.bstate AND BUTTON3_RELEASED <> 0 then
+ mvwaddstr(win, 5, 2,'BUTTON3_RELEASED')
+ else if event.bstate AND BUTTON1_PRESSED <> 0 then
+ mvwaddstr(win, 5, 2,'BUTTON1_PRESSED ')
+ else if event.bstate AND BUTTON2_PRESSED <> 0 then
+ mvwaddstr(win, 5, 2,'BUTTON2_PRESSED ')
+ else if event.bstate AND BUTTON3_PRESSED <> 0 then
+ mvwaddstr(win, 5, 2,'BUTTON3_PRESSED ')
+ else if event.bstate AND BUTTON1_CLICKED <> 0 then
+ mvwaddstr(win, 5, 2,'BUTTON1_CLICKED ')
+ else if event.bstate AND BUTTON2_CLICKED <> 0 then
+ mvwaddstr(win, 5, 2,'BUTTON2_CLICKED ')
+ else if event.bstate AND BUTTON3_CLICKED <> 0 then
+ mvwaddstr(win, 5, 2,'BUTTON3_CLICKED ');
+
+ doevent := wgetch(win);
+ cbreak();
+ hide_panel(pan);
+ end
+ else
+ doevent := chtype('q')
+end;
+
+var
+ ch: chtype;
+ my_bg: NC_FPC_COLOR = COLOR_BLACK;
+begin
+ try
+ initscr();
+ noecho();
+ clear();
+ cbreak();
+ keypad(stdscr, TRUE);
+ curs_set(0);
+ mousemask(ALL_MOUSE_EVENTS, nil);
+
+ if (has_colors()) then
+ begin
+ start_color();
+ if (use_default_colors() = OK) then
+ my_bg := -1
+ else
+ my_bg := COLOR_BLACK;
+
+ init_pair(1, COLOR_YELLOW, my_bg);
+ init_pair(2, COLOR_RED, my_bg);
+ init_pair(3, COLOR_MAGENTA, my_bg);
+ init_pair(4, COLOR_CYAN, my_bg);
+ init_pair(5, COLOR_GREEN, my_bg);
+ init_pair(6, COLOR_WHITE, COLOR_BLUE);
+ init_pair(7, COLOR_WHITE, COLOR_RED);
+ end;
+
+ win:= newwin(7, 20, (LINES - 7) DIV 2 , (COLS - 20) DIV 2);
+ pan := new_panel(win);
+ box(win, ACS_VLINE, ACS_HLINE);
+ wbkgd(win, COLOR_PAIR(6));
+
+ draw;
+ repeat
+ if ch = KEY_MOUSE then
+ ch := doevent
+ else
+ ch := getch();
+ until (ch = chtype('q')) OR (ch = KEY_F(10));
+
+ finally
+ del_panel(pan);
+ delwin(win);
+ curs_set(1);
+ endwin();
+ end;
+end.
+
diff --git a/packages/ncurses/tests/tnlshello.pp b/packages/ncurses/tests/tnlshello.pp
new file mode 100644
index 0000000000..c2cf2bb447
--- /dev/null
+++ b/packages/ncurses/tests/tnlshello.pp
@@ -0,0 +1,49 @@
+{
+ rstconv -i tnlshello.rst -o tnlshello_ru_UTF8.pot
+ msgfmt tnlshello_ru_UTF8.pot
+ mv messages.mo ru
+}
+
+program nlshello;
+{$mode objfpc}
+
+uses
+ gettext, libc, ncurses;
+
+resourcestring
+ hello_world = 'Hello world!';
+ press_key = 'Press any key to continue!';
+
+
+var
+ win : pWINDOW;
+begin
+ setlocale(LC_ALL, '');
+
+ try
+ initscr();
+ start_color;
+ noecho;
+ win:= newwin ( 10, COLS - 20, 5, 10);
+
+ init_pair(1,COLOR_WHITE,COLOR_BLUE);
+ init_pair(2,COLOR_RED,COLOR_BLUE);
+ wbkgd(win, COLOR_PAIR(1));
+ erase;
+ refresh;
+
+ box(win, ACS_VLINE, ACS_HLINE);
+ wrefresh(win);
+ mvwaddstr(win,1,3, curses_version);
+
+ TranslateResourcestrings('%s/messages.mo');
+ wattron(win,A_BLINK OR A_BOLD OR COLOR_PAIR(2));
+ mvwaddstr(win,3,3, PChar(hello_world));
+ wattroff(win,A_BLINK OR A_BOLD OR COLOR_PAIR(2));
+ mvwaddstr(win,5,3, PChar(press_key));
+ wrefresh(win);
+ getch();
+ finally
+ endwin();
+ end;
+end. \ No newline at end of file