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.26 1994/01/07 19:29:09 bostic Exp $ (Berkeley) $Date: 1994/01/07 19:29:09 $
10 /* Structure to return a character and associated information. */
12 CHAR_T ch
; /* Character. */
23 #define K_RIGHTBRACE 10
24 #define K_RIGHTPAREN 11
33 u_char value
; /* Special character flag values. */
35 #define CH_ABBREVIATED 0x01 /* Character from an abbreviation. */
36 #define CH_NOMAP 0x02 /* Do not attempt to map the character. */
37 #define CH_QUOTED 0x04 /* Character is already quoted. */
42 * Structure for the key input buffer.
44 * MAX_MAP_COUNT was chosen based on the vi maze script, which remaps
45 * characters roughly 250 times.
48 CHAR_T
*ch
; /* Array of characters. */
49 u_char
*chf
; /* Array of character flags (CH_*). */
50 #define MAX_MAP_COUNT 270 /* Maximum times a character can remap. */
51 u_char
*cmap
; /* Number of times character has been mapped. */
53 size_t cnt
; /* Count of remaining characters. */
54 size_t len
; /* Array length. */
55 size_t next
; /* Offset of next array entry. */
57 /* Return if more keys in queue. */
58 #define KEYS_WAITING(sp) ((sp)->gp->tty->cnt)
59 #define MAPPED_KEYS_WAITING(sp) \
60 (KEYS_WAITING(sp) && sp->gp->tty->cmap[sp->gp->tty->next])
63 * Structure to name a character. Used both as an interface to the
64 * screen and to name objects named by characters in error messages.
67 char *name
; /* Character name. */
68 u_char len
; /* Length of the character name. */
72 * Routines that return a key as a side-effect return:
74 * INP_OK Returning a character; must be 0.
78 * The vi structure depends on the key routines being able to return INP_EOF
79 * multiple times without failing -- eventually enough things will end due to
80 * INP_EOF that vi will reach the command level for the screen, at which point
81 * the exit flags will be set and vi will exit.
83 enum input
{ INP_OK
=0, INP_EOF
, INP_ERR
};
86 * Routines that return a confirmation return:
88 * CONF_NO User answered no.
89 * CONF_QUIT User answered quit, eof or an error.
90 * CONF_YES User answered yes.
92 enum confirm
{ CONF_NO
, CONF_QUIT
, CONF_YES
};
95 * Ex/vi commands are generally separated by whitespace characters. We
96 * can't use the standard isspace(3) macro because it returns true for
97 * characters like ^K in the ASCII character set. The 4.4BSD isblank(3)
98 * macro does exactly what we want, but it's not portable yet.
101 * Note side effect, ch is evaluated multiple times.
104 #define isblank(ch) ((ch) == ' ' || (ch) == '\t')
107 /* Various special characters, messages. */
108 #define CURSOR_CH ' ' /* Cursor character. */
109 #define END_CH '$' /* End of a range. */
110 #define HEX_CH 'x' /* Leading hex number. */
111 #define NOT_DIGIT_CH 'a' /* A non-isdigit() character. */
112 #define NO_CH 'n' /* No. */
113 #define QUIT_CH 'q' /* Quit. */
114 #define YES_CH 'y' /* Yes. */
115 #define CONFSTRING "confirm? [ynq]"
116 #define CONTMSG "Enter return to continue: "
117 #define CONTMSG_I "Enter return to continue [q to quit]: "
119 /* Flags describing how input is handled. */
120 #define TXT_AICHARS 0x000001 /* Leading autoindent chars. */
121 #define TXT_ALTWERASE 0x000002 /* Option: altwerase. */
122 #define TXT_APPENDEOL 0x000004 /* Appending after EOL. */
123 #define TXT_AUTOINDENT 0x000008 /* Autoindent set this line. */
124 #define TXT_BEAUTIFY 0x000010 /* Only printable characters. */
125 #define TXT_BS 0x000020 /* Backspace returns the buffer. */
126 #define TXT_CNTRLT 0x000040 /* Control-T is an indent special. */
127 #define TXT_CR 0x000080 /* CR returns the buffer. */
128 #define TXT_EMARK 0x000100 /* End of replacement mark. */
129 #define TXT_ESCAPE 0x000200 /* Escape returns the buffer. */
130 #define TXT_INFOLINE 0x000400 /* Editing the info line. */
131 #define TXT_MAPCOMMAND 0x000800 /* Apply the command map. */
132 #define TXT_MAPINPUT 0x001000 /* Apply the input map. */
133 #define TXT_MAPNODIGIT 0x002000 /* Return to a digit. */
134 #define TXT_NLECHO 0x004000 /* Echo the newline. */
135 #define TXT_OVERWRITE 0x008000 /* Overwrite characters. */
136 #define TXT_PROMPT 0x010000 /* Display a prompt. */
137 #define TXT_RECORD 0x020000 /* Record for replay. */
138 #define TXT_REPLACE 0x040000 /* Replace; don't delete overwrite. */
139 #define TXT_REPLAY 0x080000 /* Replay the last input. */
140 #define TXT_RESOLVE 0x100000 /* Resolve the text into the file. */
141 #define TXT_SHOWMATCH 0x200000 /* Option: showmatch. */
142 #define TXT_TTYWERASE 0x400000 /* Option: ttywerase. */
143 #define TXT_WRAPMARGIN 0x800000 /* Option: wrapmargin. */
145 #define TXT_VALID_EX \
146 (TXT_BEAUTIFY | TXT_CR | TXT_NLECHO | TXT_PROMPT)
148 /* Support keyboard routines. */
149 int __term_key_val
__P((SCR
*, ARG_CHAR_T
));
150 void term_ab_flush
__P((SCR
*, char *));
151 int term_init
__P((SCR
*));
152 enum input term_key
__P((SCR
*, CH
*, u_int
));
153 int term_key_ch
__P((SCR
*, int, CHAR_T
*));
154 int term_key_queue
__P((SCR
*));
155 void term_map_flush
__P((SCR
*, char *));
156 int term_push
__P((SCR
*, CHAR_T
*, size_t, u_int
, u_int
));
157 enum input term_user_key
__P((SCR
*, CH
*));
158 int term_waiting
__P((SCR
*));