beep if the ^D auto-indent erasure reaches the left column
[nvi.git] / common / key.h
blob87edc7631538a5e474d38259536578ed141cb2b5
1 /*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
7 * $Id: key.h,v 8.23 1993/12/19 18:58:08 bostic Exp $ (Berkeley) $Date: 1993/12/19 18:58:08 $
8 */
10 /* Structure to return a character and associated information. */
11 struct _ch {
12 CHAR_T ch; /* Character. */
14 #define K_CARAT 1
15 #define K_CNTRLR 2
16 #define K_CNTRLT 3
17 #define K_CNTRLZ 4
18 #define K_COLON 5
19 #define K_CR 6
20 #define K_ESCAPE 7
21 #define K_FORMFEED 8
22 #define K_NL 9
23 #define K_RIGHTBRACE 10
24 #define K_RIGHTPAREN 11
25 #define K_TAB 12
26 #define K_VEOF 13
27 #define K_VERASE 14
28 #define K_VKILL 15
29 #define K_VLNEXT 16
30 #define K_VWERASE 17
31 #define K_ZERO 18
32 u_char value; /* Special character flag values. */
34 #define CH_ABBREVIATED 0x01 /* Character from an abbreviation. */
35 #define CH_NOMAP 0x02 /* Do not attempt to map the character. */
36 #define CH_QUOTED 0x04 /* Character is already quoted. */
37 u_char flags;
40 /* Structure for the key input buffer. */
41 struct _ibuf {
42 CHAR_T *ch; /* Array of characters. */
43 u_char *chf; /* Array of character flags (CH_*). */
44 #define MAX_MAP_COUNT 50 /* Maximum times a character can remap. */
45 u_char *cmap; /* Number of times character has been mapped. */
47 size_t cnt; /* Count of remaining characters. */
48 size_t len; /* Array length. */
49 size_t next; /* Offset of next array entry. */
51 /* Return if more keys in queue. */
52 #define KEYS_WAITING(sp) ((sp)->gp->tty->cnt)
53 #define MAPPED_KEYS_WAITING(sp) \
54 (KEYS_WAITING(sp) && sp->gp->tty->cmap[sp->gp->tty->next])
57 * Structure to name a character. Used both as an interface to the
58 * screen and to name objects named by characters in error messages.
60 struct _chname {
61 char *name; /* Character name. */
62 u_char len; /* Length of the character name. */
66 * Routines that return a key as a side-effect return:
68 * INP_OK Returning a character; must be 0.
69 * INP_EOF EOF.
70 * INP_ERR Error.
72 * The vi structure depends on the key routines being able to return INP_EOF
73 * multiple times without failing -- eventually enough things will end due to
74 * INP_EOF that vi will reach the command level for the screen, at which point
75 * the exit flags will be set and vi will exit.
77 enum input { INP_OK=0, INP_EOF, INP_ERR };
80 * Routines that return a confirmation return:
82 * CONF_NO User answered no.
83 * CONF_QUIT User answered quit, eof or an error.
84 * CONF_YES User answered yes.
86 enum confirm { CONF_NO, CONF_QUIT, CONF_YES };
89 * Ex/vi commands are generally separated by whitespace characters. We
90 * can't use the standard isspace(3) macro because it returns true for
91 * characters like ^K in the ASCII character set. The 4.4BSD isblank(3)
92 * macro does exactly what we want, but it's not portable yet.
94 * XXX
95 * Note side effect, ch is evaluated multiple times.
97 #ifndef isblank
98 #define isblank(ch) ((ch) == ' ' || (ch) == '\t')
99 #endif
101 /* Various special characters, messages. */
102 #define CURSOR_CH ' ' /* Cursor character. */
103 #define END_CH '$' /* End of a range. */
104 #define HEX_CH 'x' /* Leading hex number. */
105 #define NOT_DIGIT_CH 'a' /* A non-isdigit() character. */
106 #define NO_CH 'n' /* No. */
107 #define QUIT_CH 'q' /* Quit. */
108 #define YES_CH 'y' /* Yes. */
109 #define CONFSTRING "confirm? [ynq]"
110 #define CONTMSG "Enter return to continue: "
111 #define CONTMSG_I "Enter return to continue [q to quit]: "
113 /* Flags describing how input is handled. */
114 #define TXT_AICHARS 0x000001 /* Leading autoindent chars. */
115 #define TXT_ALTWERASE 0x000002 /* Option: altwerase. */
116 #define TXT_APPENDEOL 0x000004 /* Appending after EOL. */
117 #define TXT_AUTOINDENT 0x000008 /* Autoindent set this line. */
118 #define TXT_BEAUTIFY 0x000010 /* Only printable characters. */
119 #define TXT_BS 0x000020 /* Backspace returns the buffer. */
120 #define TXT_CNTRLT 0x000040 /* Control-T is an indent special. */
121 #define TXT_CR 0x000080 /* CR returns the buffer. */
122 #define TXT_EMARK 0x000100 /* End of replacement mark. */
123 #define TXT_ESCAPE 0x000200 /* Escape returns the buffer. */
124 #define TXT_INFOLINE 0x000400 /* Editing the info line. */
125 #define TXT_MAPCOMMAND 0x000800 /* Apply the command map. */
126 #define TXT_MAPINPUT 0x001000 /* Apply the input map. */
127 #define TXT_MAPNODIGIT 0x002000 /* Return to a digit. */
128 #define TXT_NLECHO 0x004000 /* Echo the newline. */
129 #define TXT_OVERWRITE 0x008000 /* Overwrite characters. */
130 #define TXT_PROMPT 0x010000 /* Display a prompt. */
131 #define TXT_RECORD 0x020000 /* Record for replay. */
132 #define TXT_REPLACE 0x040000 /* Replace; don't delete overwrite. */
133 #define TXT_REPLAY 0x080000 /* Replay the last input. */
134 #define TXT_RESOLVE 0x100000 /* Resolve the text into the file. */
135 #define TXT_SHOWMATCH 0x200000 /* Option: showmatch. */
136 #define TXT_TTYWERASE 0x400000 /* Option: ttywerase. */
137 #define TXT_WRAPMARGIN 0x800000 /* Option: wrapmargin. */
139 #define TXT_VALID_EX \
140 (TXT_BEAUTIFY | TXT_CR | TXT_NLECHO | TXT_PROMPT)
142 /* Support keyboard routines. */
143 int __term_key_val __P((SCR *, ARG_CHAR_T));
144 void term_ab_flush __P((SCR *, char *));
145 int term_init __P((SCR *));
146 enum input term_key __P((SCR *, CH *, u_int));
147 int term_key_ch __P((SCR *, int, CHAR_T *));
148 void term_map_flush __P((SCR *, char *));
149 int term_push __P((SCR *, CHAR_T *, size_t, u_int, u_int));
150 enum input term_user_key __P((SCR *, CH *));
151 int term_waiting __P((SCR *));