2
0

t1menu.pp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. {
  2. Example 18. Menu Basics
  3. from ncurses howto
  4. }
  5. program Menu_Basics;
  6. {$MODE OBJFPC}
  7. uses
  8. ncurses, menu;
  9. const
  10. choices: array[0..4] of PChar =
  11. (
  12. 'Choice 1',
  13. 'Choice 2',
  14. 'Choice 3',
  15. 'Choice 4',
  16. 'Exit'
  17. );
  18. var
  19. my_items: ppITEM;
  20. my_menu: pMENU;
  21. c, n_choices, i: Longint;
  22. cur_item: pITEM;
  23. begin
  24. try
  25. initscr();
  26. cbreak();
  27. noecho();
  28. keypad(stdscr, TRUE);
  29. n_choices := 5;
  30. GetMem(my_items, (n_choices+1)*sizeof(pITEM));
  31. for i := 0 to n_choices - 1 do
  32. my_items[i] := new_item(choices[i], choices[i]);
  33. my_items[n_choices] := nil;
  34. my_menu := new_menu(my_items);
  35. mvprintw(LINES - 2, 0, 'F1 to Exit');
  36. post_menu(my_menu);
  37. refresh();
  38. c := getch();
  39. while c <> KEY_F(1) do
  40. begin
  41. case c of
  42. KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM);
  43. KEY_UP: menu_driver(my_menu, REQ_UP_ITEM);
  44. else
  45. end;
  46. c := getch();
  47. end
  48. finally
  49. free_item(my_items[0]);
  50. free_item(my_items[1]);
  51. free_menu(my_menu);
  52. FreeMem(my_items, (n_choices+1)*sizeof(pITEM));
  53. endwin();
  54. end;
  55. end.