/packages/ncurses/examples/twindow.pp

https://github.com/slibre/freepascal · Puppet · 82 lines · 69 code · 13 blank · 0 comment · 0 complexity · 61a1bd6092a9ed411053051e98194295 MD5 · raw file

  1. program test_window;
  2. {$mode objfpc}
  3. uses
  4. ncurses, panel, sysutils;
  5. procedure printw(win: PWINDOW; y,x: Smallint; fmt: AnsiString; args: Array of const);
  6. var
  7. tstr: AnsiString;
  8. begin
  9. FmtStr(tstr, fmt, args);
  10. mvwaddstr(win,y,x, PChar(tstr));
  11. end;
  12. procedure printinfo(win: PWINDOW);
  13. begin
  14. with win^ do
  15. begin
  16. printw(win,1 ,1,'_cury=%-3d, _curx=%-3d : cursor position',[_cury,_curx]);
  17. printw(win,2 ,1,'_maxy=%-3d, _maxx=%-3d : maximums of x and y, NOT window size',[_maxy,_maxx]);
  18. printw(win,3 ,1,'_begy=%-3d, _begx=%-3d : screen coords of upper-left-hand corner',[_begy,_begx]);
  19. printw(win,4 ,1,'_flags=%-3d : window state flags',[_flags]);
  20. printw(win,5 ,1,'_attrs=%-4d : current attribute for non-space character',[_attrs]);
  21. printw(win,6 ,1,'_bkgd=%-3d : current background char/attribute pair',[_bkgd]);
  22. printw(win,7 ,1,'_notimeout=%-1d : no time out on function-key entry?', [Byte(_notimeout)]);
  23. printw(win,8 ,1,'_clear=%-1d : consider all data in the window invalid?',[Byte(_clear)]);
  24. printw(win,9 ,1,'_leaveok=%-1d : OK to not reset cursor on exit?',[Byte(_leaveok)]);
  25. printw(win,10,1,'_scroll=%-1d : OK to scroll this window?',[Byte(_scroll)]);
  26. printw(win,11,1,'_idlok=%-1d : OK to use insert/delete line?',[Byte(_idlok)]);
  27. printw(win,12,1,'_idcok=%-1d : OK to use insert/delete char?',[Byte(_idcok)]);
  28. printw(win,13,1,'_immed=%-1d : window in immed mode? (not yet used)',[Byte(_immed)]);
  29. printw(win,14,1,'_sync=%-1d : window in sync mode?',[Byte(_sync)]);
  30. printw(win,15,1,'_use_keypad=%-1d : process function keys into KEY_ symbols?',[Byte(_use_keypad)]);
  31. printw(win,16,1,'_delay=%-3d : 0 = nodelay, <0 = blocking, >0 = delay',[_delay]);
  32. printw(win,17,1,'_parx=%-3d : x coordinate of this window in parent',[_parx]);
  33. printw(win,18,1,'_pary=%-3d : y coordinate of this window in parent',[_pary]);
  34. printw(win,19,1,'_yoffset=%-3d : real begy is _begy + _yoffset',[_yoffset]);
  35. printw(win,20,1,'_bkgrnd.attr=%-4d : current background char/attribute pair',[_bkgrnd.attr]);
  36. end;
  37. end;
  38. var
  39. win : pWINDOW;
  40. cy, cx, by, bx, my, mx: Longint;
  41. begin
  42. try
  43. initscr();
  44. start_color;
  45. noecho;
  46. init_pair(1,COLOR_WHITE,COLOR_BLUE);
  47. init_pair(2,COLOR_RED,COLOR_BLUE);
  48. win:= newwin( LINES - 2, COLS - 6, 1, 3);
  49. wbkgd(win, COLOR_PAIR(1));
  50. erase;
  51. refresh;
  52. box(win, ACS_VLINE, ACS_HLINE);
  53. wmove(win,12,24);
  54. printinfo(win);
  55. wrefresh(win);
  56. getch;
  57. getyx(win,cy,cx);
  58. getbegyx(win,by,bx);
  59. getmaxyx(win,my,mx);
  60. delwin(win);
  61. clear();
  62. printw(stdscr,1 ,1,'getyx(win,%d,%d)',[cy,cx]);
  63. printw(stdscr,2 ,1,'getbegyx(win,%d,%d);',[by,bx]);
  64. printw(stdscr,3 ,1,'getmaxyx(win,%d,%d);',[my,mx]);
  65. getch;
  66. finally
  67. endwin();
  68. end;
  69. end.