edline.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #ifndef _GORP_EDLINE_EDLINE_H_
  2. #define _GORP_EDLINE_EDLINE_H_
  3. /*
  4. * Copyright 2009 by egnite GmbH
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. */
  36. #include <compiler.h>
  37. #include <stdint.h>
  38. /*
  39. * \file include/gorp/edline.h
  40. * \brief Simple line editor definitions.
  41. *
  42. * \verbatim
  43. * $Id$
  44. * \endverbatim
  45. */
  46. /*!
  47. * \addtogroup xgEdLine
  48. */
  49. /*@{*/
  50. /*!
  51. * \name Edit mode flags
  52. *
  53. * Used when calling \ref EdLineOpen to enable specific line
  54. * editor features.
  55. */
  56. /*@{*/
  57. /*! \brief Enables echoing of input characters. */
  58. #define EDIT_MODE_ECHO 0x0001
  59. /*! \brief Enables binary mode (currently unused). */
  60. #define EDIT_MODE_BINARY 0x0002
  61. /*! \brief Enables input line history. */
  62. #define EDIT_MODE_HISTORY 0x0004
  63. /*@}*/
  64. /*!
  65. * \name Line editor input commands
  66. *
  67. * Special keys which are interpreted by the editor as commands.
  68. */
  69. /*@{*/
  70. #ifndef EDIT_KEY_IGNORE
  71. /*! \brief No operation. Default is Ctrl-@. */
  72. #define EDIT_KEY_IGNORE 0x00 /* CTRL-@ '\0' */
  73. #endif
  74. #ifndef EDIT_KEY_HOME
  75. /*! \brief Move cursor to line begin. Default is Ctrl-A. */
  76. #define EDIT_KEY_HOME 0x01 /* CTRL-A */
  77. #endif
  78. #ifndef EDIT_KEY_LEFT
  79. /*! \brief Move cursor left. Default is Ctrl-B. */
  80. #define EDIT_KEY_LEFT 0x02 /* CTRL-B */
  81. #endif
  82. #ifndef EDIT_KEY_END
  83. /*! \brief Move cursor to line end. Default is Ctrl-E. */
  84. #define EDIT_KEY_END 0x05 /* CTRL-E */
  85. #endif
  86. #ifndef EDIT_KEY_RIGHT
  87. /*! \brief Move cursor right. Default is Ctrl-F. */
  88. #define EDIT_KEY_RIGHT 0x06 /* CTRL-F */
  89. #endif
  90. #ifndef EDIT_KEY_REMOVE
  91. /*! \brief Delete left character. Default is Ctrl-H. */
  92. #define EDIT_KEY_REMOVE 0x08 /* CTRL-H '\b' */
  93. #endif
  94. #ifndef EDIT_KEY_ENTER
  95. /*! \brief Confirm input. Default is Ctrl-J. */
  96. #define EDIT_KEY_ENTER 0x0a /* CTRL-J '\n' */
  97. #endif
  98. #ifndef EDIT_DISABLE_HISTORY
  99. #ifndef EDIT_KEY_UP
  100. /*! \brief History upwards. Default is Ctrl-R. */
  101. #define EDIT_KEY_UP 0x12 /* CTRL-R */
  102. #endif
  103. #ifndef EDIT_KEY_DOWN
  104. /*! \brief History downwards. Default is Ctrl-V. */
  105. #define EDIT_KEY_DOWN 0x16 /* CTRL-V */
  106. #endif
  107. #ifndef EDIT_KEY_RESTORE
  108. /*! \brief Restore default. Default is ESC. */
  109. #define EDIT_KEY_RESTORE 0x1b /* CTRL-[ '\e' */
  110. #endif
  111. #endif /* EDIT_DISABLE_HISTORY */
  112. /*@}*/
  113. /*!
  114. * \name Line editor output commands
  115. *
  116. * Special characters used by the editor to update the output.
  117. */
  118. /*@{*/
  119. #ifndef EDIT_CHAR_SPACE
  120. /*! \brief Clear character right. */
  121. #define EDIT_CHAR_SPACE ' '
  122. #endif
  123. #ifndef EDIT_CHAR_BACKSPACE
  124. /*! \brief Move cursor left. */
  125. #define EDIT_CHAR_BACKSPACE '\b'
  126. #endif
  127. #ifndef EDIT_CHAR_ALARM
  128. /*! \brief Invoke audible alarm. */
  129. #define EDIT_CHAR_ALARM '\a'
  130. #endif
  131. #ifndef EDIT_STR_EOL
  132. /*! \brief Terminate input. */
  133. #define EDIT_STR_EOL "\r\n"
  134. #endif
  135. /*@}*/
  136. #ifndef EDIT_DISABLE_HISTORY
  137. /*! \brief Line input history. */
  138. typedef struct _EDITHISTORY {
  139. /*! \brief Maximum number of entries. */
  140. int hist_siz;
  141. /*! \brief Table of entries. */
  142. char **hist_tab;
  143. } EDITHISTORY;
  144. #endif
  145. /*! \brief Input routine type. */
  146. typedef int (*EDLINEGET) (void *);
  147. /*! \brief Output routine type. */
  148. typedef int (*EDLINEPUT) (void *, int);
  149. /*! \brief Character mapping routine type. */
  150. typedef int (*EDLINEMAP) (int, int *);
  151. /*! \brief Edit line information structure. */
  152. typedef struct _EDLINE {
  153. /*! \brief Input routine. */
  154. EDLINEGET el_get;
  155. /*! \brief Input routine parameter. */
  156. void *el_iparm;
  157. /*! \brief Output routine. */
  158. EDLINEPUT el_put;
  159. /*! \brief Output routine parameter. */
  160. void *el_oparm;
  161. /*! \brief Character mapping routine. */
  162. EDLINEMAP el_map;
  163. /*! \brief Editor mode flags. */
  164. uint_fast16_t el_mode;
  165. /*! \brief Character mapping sequence. */
  166. int el_seq;
  167. #ifndef EDIT_DISABLE_HISTORY
  168. /*! \brief Line input history. */
  169. EDITHISTORY *el_hist;
  170. #endif
  171. } EDLINE;
  172. /*@}*/
  173. extern EDLINE *EdLineOpen(uint16_t mode);
  174. extern void EdLineClose(EDLINE *el);
  175. extern int EdLineRead(EDLINE *el, char *buf, int siz);
  176. #ifndef EDIT_DISABLE_HISTORY
  177. extern EDITHISTORY *EditHistoryCreate(int siz);
  178. extern void EditHistoryDestroy(EDITHISTORY *hist);
  179. extern void EditHistorySet(EDITHISTORY *hist, int idx, char *buf);
  180. extern int EditHistoryGet(EDITHISTORY *hist, int idx, char *buf, int siz);
  181. extern void EditHistoryInsert(EDITHISTORY *hist, int idx, char *buf);
  182. #endif
  183. extern void EdLineRegisterKeymap(EDLINE *el, EDLINEMAP map);
  184. extern int EdLineKeyMap(int key, int *seq);
  185. extern int EdLineKeyMapVt100(int key, int *seq);
  186. extern void EdLineRegisterInput(EDLINE *el, EDLINEGET get, void *iparm);
  187. extern void EdLineRegisterOutput(EDLINE *el, EDLINEPUT put, void *oparm);
  188. #endif