menu.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright 2010-2011 Calxeda, Inc.
  4. */
  5. #ifndef __MENU_H__
  6. #define __MENU_H__
  7. struct cli_ch_state;
  8. struct menu;
  9. struct menu *menu_create(char *title, int timeout, int prompt,
  10. void (*display_statusline)(struct menu *),
  11. void (*item_data_print)(void *),
  12. char *(*item_choice)(void *),
  13. void *item_choice_data);
  14. int menu_default_set(struct menu *m, char *item_key);
  15. int menu_get_choice(struct menu *m, void **choice);
  16. int menu_item_add(struct menu *m, char *item_key, void *item_data);
  17. int menu_destroy(struct menu *m);
  18. int menu_default_choice(struct menu *m, void **choice);
  19. /**
  20. * menu_show() Show a boot menu
  21. *
  22. * This shows a menu and lets the user select an option. The menu is defined by
  23. * environment variables (see README.bootmenu).
  24. *
  25. * This function doesn't normally return, but if the users requests the command
  26. * problem, it will.
  27. *
  28. * @bootdelay: Delay to wait before running the default menu option (0 to run
  29. * the entry immediately)
  30. * Return: If it returns, it always returns -1 to indicate that the boot should
  31. * be aborted and the command prompt should be provided
  32. */
  33. int menu_show(int bootdelay);
  34. struct bootmenu_data {
  35. int delay; /* delay for autoboot */
  36. int active; /* active menu entry */
  37. int count; /* total count of menu entries */
  38. struct bootmenu_entry *first; /* first menu entry */
  39. };
  40. /** enum bootmenu_key - keys that can be returned by the bootmenu */
  41. enum bootmenu_key {
  42. BKEY_NONE = 0,
  43. BKEY_UP,
  44. BKEY_DOWN,
  45. BKEY_SELECT,
  46. BKEY_QUIT,
  47. BKEY_PLUS,
  48. BKEY_MINUS,
  49. BKEY_SPACE,
  50. BKEY_SAVE,
  51. BKEY_COUNT,
  52. };
  53. /**
  54. * bootmenu_autoboot_loop() - handle autobooting if no key is pressed
  55. *
  56. * This shows a prompt to allow the user to press a key to interrupt auto boot
  57. * of the first menu option.
  58. *
  59. * It then waits for the required time (menu->delay in seconds) for a key to be
  60. * pressed. If nothing is pressed in that time, @key returns KEY_SELECT
  61. * indicating that the current option should be chosen.
  62. *
  63. * @menu: Menu being processed
  64. * @esc: Set to 1 if the escape key is pressed, otherwise not updated
  65. * Returns: code for the key the user pressed:
  66. * enter: KEY_SELECT
  67. * Ctrl-C: KEY_QUIT
  68. * anything else: KEY_NONE
  69. */
  70. enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
  71. struct cli_ch_state *cch);
  72. /**
  73. * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled
  74. *
  75. * This is used when the menu delay is negative, indicating that the delay has
  76. * elapsed, or there was no delay to begin with.
  77. *
  78. * It reads a character and processes it, returning a menu-key code if a
  79. * character is recognised
  80. *
  81. * @menu: Menu being processed
  82. * @esc: On input, a non-zero value indicates that an escape sequence has
  83. * resulted in that many characters so far. On exit this is updated to the
  84. * new number of characters
  85. * Returns: code for the key the user pressed:
  86. * enter: BKEY_SELECT
  87. * Ctrl-C: BKEY_QUIT
  88. * Up arrow: BKEY_UP
  89. * Down arrow: BKEY_DOWN
  90. * Escape (by itself): BKEY_QUIT
  91. * Plus: BKEY_PLUS
  92. * Minus: BKEY_MINUS
  93. * Space: BKEY_SPACE
  94. */
  95. enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
  96. struct cli_ch_state *cch);
  97. /**
  98. * bootmenu_conv_key() - Convert a U-Boot keypress into a menu key
  99. *
  100. * @ichar: Keypress to convert (ASCII, including control characters)
  101. * Returns: Menu key that corresponds to @ichar, or BKEY_NONE if none
  102. */
  103. enum bootmenu_key bootmenu_conv_key(int ichar);
  104. #endif /* __MENU_H__ */