~ubuntu-branches/ubuntu/quantal/hexer/quantal

« back to all changes in this revision

Viewing changes to tio.h

  • Committer: Bazaar Package Importer
  • Author(s): Peter Mathiasson
  • Date: 2003-06-19 09:48:34 UTC
  • Revision ID: james.westby@ubuntu.com-20030619094834-t127jo9kd93shx02
Tags: upstream-0.1.4c
ImportĀ upstreamĀ versionĀ 0.1.4c

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* tio.h        8/19/1995
 
2
 */
 
3
 
 
4
/* Copyright (c) 1995,1996 Sascha Demetrio
 
5
 * All rights reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions
 
9
 * are met:
 
10
 * 1. Redistributions of source code must retain the above copyright
 
11
 *    notice, this list of conditions and the following disclaimer.
 
12
 *    If you modify any part of HEXER and resitribute it, you must add
 
13
 *    a notice to the `README' file and the modified source files containing
 
14
 *    information about the  changes you made.  I do not want to take
 
15
 *    credit or be blamed for your modifications.
 
16
 * 2. Redistributions in binary form must reproduce the above copyright
 
17
 *    notice, this list of conditions and the following disclaimer in the
 
18
 *    documentation and/or other materials provided with the distribution.
 
19
 *    If you modify any part of HEXER and resitribute it in binary form,
 
20
 *    you must supply a `README' file containing information about the
 
21
 *    changes you made.
 
22
 * 3. The name of the developer may not be used to endorse or promote
 
23
 *    products derived from this software without specific prior written
 
24
 *    permission.
 
25
 *
 
26
 * HEXER WAS DEVELOPED BY SASCHA DEMETRIO.
 
27
 * THIS SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
 
28
 * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
 
29
 * NOT MAKE USE OF THIS WORK.
 
30
 *
 
31
 * DISCLAIMER:
 
32
 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
 
33
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
34
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
35
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE DEVELOPER BE LIABLE
 
36
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
37
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
38
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
39
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
40
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
41
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
42
 * SUCH DAMAGE.
 
43
 */
 
44
 
 
45
#ifndef _TIO_H_
 
46
#define _TIO_H_
 
47
 
 
48
#include "config.h"
 
49
#include "defs.h"
 
50
 
 
51
#define TIO_MAX_UNGET 4096
 
52
 
 
53
enum t_keys_e {
 
54
  KEY_ERROR      = -1,
 
55
  KEY_NONE       = 0,
 
56
  KEY_BACKSPACE  = 0x08,
 
57
  KEY_TAB        = 0x09,
 
58
  KEY_RETURN     = 0x0d,
 
59
  KEY_ESCAPE     = 0x1b,
 
60
  KEY_DELETE     = 0x7f,
 
61
  KEY_UP         = 0x100,
 
62
  KEY_DOWN,
 
63
  KEY_LEFT,
 
64
  KEY_RIGHT,
 
65
  KEY_F0,
 
66
  KEY_F1,
 
67
  KEY_F2,
 
68
  KEY_F3,
 
69
  KEY_F4,
 
70
  KEY_F5,
 
71
  KEY_F6,
 
72
  KEY_F7,
 
73
  KEY_F8,
 
74
  KEY_F9,
 
75
  KEY_F10,
 
76
  KEY_BACKTAB,
 
77
  KEY_BEGIN,
 
78
  KEY_CANCEL,
 
79
  KEY_CLOSE,
 
80
  KEY_COPY,
 
81
  KEY_CREATE,
 
82
  KEY_END,
 
83
  KEY_ENTER,
 
84
  KEY_EXIT,
 
85
  KEY_UPPER_LEFT,
 
86
  KEY_UPPER_RIGHT,
 
87
  KEY_CENTER,
 
88
  KEY_BOTTOM_LEFT,
 
89
  KEY_BOTTOM_RIGHT,
 
90
  KEY_HOME,
 
91
  KEY_PAGE_UP,
 
92
  KEY_PAGE_DOWN,
 
93
  KEY_BREAK,
 
94
  KEY_NULL
 
95
};
 
96
 
 
97
#define KEY_BIAS 254            /* bias used for storing non-character
 
98
                                 * keys in character strings */
 
99
 
 
100
extern struct t_keynames_s {
 
101
  enum t_keys_e key;
 
102
  char *name;
 
103
} t_keynames[];
 
104
 
 
105
#if USE_STDARG
 
106
extern void (*error_msg)( const char *, ... );
 
107
#else
 
108
extern void (*error_msg)( /* const char *, ... */ );
 
109
#endif
 
110
  /* Pointer to the error message function.
 
111
   */
 
112
 
 
113
  extern
 
114
tio_isprint( /* int x */ );
 
115
 
 
116
  extern
 
117
#if USE_STDARG
 
118
nprintf( const char *fmt, ... );
 
119
#else
 
120
nprintf( /* const char *fmt, ... */ );
 
121
#endif
 
122
 
 
123
  extern
 
124
vnprintf( /* const char *fmt, va_list ap */ );
 
125
  /* Returns the number of output characters a call to a printf-like function
 
126
   * would pruduce.
 
127
   */
 
128
 
 
129
  extern
 
130
tio_init( /* char *program_name */ );
 
131
  /* Initialize.  This function should be called before any other
 
132
   * `tio_*'-function.  `program_name' should be the name of the application.
 
133
   */
 
134
 
 
135
#define tio_flush() (void)fflush(stdout)
 
136
  /* Flush `stdout'.
 
137
   */
 
138
 
 
139
  extern void
 
140
tio_start_application( /* void */ );
 
141
  /* Send the start-application string to the terminal.
 
142
   */
 
143
 
 
144
  extern void
 
145
tio_end_application( /* void */ );
 
146
  /* Send the end-application string to the terminal.
 
147
   */
 
148
 
 
149
  extern void
 
150
tio_keypad( /* int on */ );
 
151
  /* Set the keypad mode.
 
152
   * on=0: numeric keypad.
 
153
   * on=1: application keypad.  Select this mode if you want to use the
 
154
   *       keypad (i.e. arrow-keys).
 
155
   */
 
156
 
 
157
  extern
 
158
tio_getch( /* void */ );
 
159
 
 
160
  extern
 
161
tio_get( /* void */ );
 
162
  /* Read a character from the keyboard.  `tio_getch()' waits for input,
 
163
   * `tio_get()' returns `KEY_NONE' (0) if no input is available.
 
164
   * The functions return the following special keys:
 
165
   *   KEY_ERROR                an error occured while waiting for input.
 
166
   *                            NOTE: Changing the size of the window causes
 
167
   *                              `tio_getch()' to return `KEY_ERROR'.
 
168
   *   KEY_NONE                 no key.
 
169
   *   KEY_BACKSPACE            backspace key.
 
170
   *   KEY_TAB                  TAB key.
 
171
   *   KEY_RETURN               return key.
 
172
   *   KEY_ESCAPE               escape key.
 
173
   *   KEY_DELETE               delete key.
 
174
   *   KEY_UP                   up arrow.
 
175
   *   KEY_DOWN                 down arrow.
 
176
   *   KEY_LEFT                 left arrow.
 
177
   *   KEY_RIGHT                right arrow.
 
178
   *   KEY_BACKTAB              BACKTAB key.
 
179
   *   KEY_F0, ... KEY_F10      function keys F0-F10.
 
180
   *   KEY_BEGIN                begin key.
 
181
   *   KEY_CANCEL               cancel key.
 
182
   *   KEY_CLOSE                close key.
 
183
   *   KEY_COPY                 copy key.
 
184
   *   KEY_CREATE               create key.
 
185
   *   KEY_END                  end key.
 
186
   *   KEY_ENTER                enter key.
 
187
   *   KEY_EXIT                 exit key.
 
188
   *   KEY_UPPER_LEFT           upper left key on keypad.
 
189
   *   KEY_UPPER_RIGHT          upper right key on keypad.
 
190
   *   KEY_CENTER               center key on keypad.
 
191
   *   KEY_BOTTOM_LEFT          bottom left key on keypad.
 
192
   *   KEY_BOTTOM_RIGHT         bottom right key on keypad.
 
193
   *   KEY_HOME                 home key.
 
194
   *   KEY_PAGE_UP              page up key.
 
195
   *   KEY_PAGE_DOWN            page down key.
 
196
   */
 
197
 
 
198
  extern
 
199
tio_tget( /* int timeout */ );
 
200
  /* Like `tio_get()', but waits `timeout' tenths of a second for input.
 
201
   * `tio_tget()' returns `KEY_NONE' (0) if nothing has been read.
 
202
   */
 
203
 
 
204
  extern
 
205
tio_ungetch( /* int x */ );
 
206
  /* Put the character `x' back into the input stream.  At most
 
207
   * `IO_MAX_UNGET' characters can be ungetch.  The return value is `x'
 
208
   * or -1 on error.
 
209
   */
 
210
 
 
211
  extern
 
212
tio_ungets( /* int *x */ );
 
213
  /* Put the character string `x' back into the input stream using
 
214
   * `tio_ungetch()'.  The return value is 0 and -1 on error.
 
215
   */
 
216
 
 
217
  extern
 
218
tio_readmore( /* void */ );
 
219
  /* Returns a non-zero value iff there are pending input characters.
 
220
   * NOTE:  Keys put into the unput-queue (via `tio_ungetch()' or
 
221
   *   `tio_ungets()') are not counted.
 
222
   */
 
223
 
 
224
  extern
 
225
tio_getmore( /* void */ );
 
226
  /* Returns a non-zero value iff there are any keys in the unget-queue.
 
227
   */
 
228
 
 
229
  extern
 
230
tio_testkey( /* int key */ );
 
231
  /* Returns 1, if a termcap entry for the requested key exists, else 0.
 
232
   * The function return always 1 for the keys `KEY_BACKSPACE', `KEY_TAB',
 
233
   * `KEY_RETURN', `KEY_ESCAPE', `KEY_DELETE', `KEY_NONE' and `KEY_ERROR'.
 
234
   */
 
235
 
 
236
  extern char *
 
237
tio_keyname( /* int key */ );
 
238
  /* Returns the name of the key `key'.  If `key' is a printable character,
 
239
   * it is returned as a string.  If `key' is a special key, the name of
 
240
   * that key is returned.  If `key' is unknown and greater than 0xff "??"
 
241
   * is returned, else a `\x??' hexadecimal code.
 
242
   */
 
243
 
 
244
  extern char *
 
245
tio_keyrep( /* int key */ );
 
246
  /* Returs a string representation of `key'.  If `key' is not a printable
 
247
   * character an escape sequence is generated:
 
248
   *   key > 0xff      if key is a known special key, a unique sequence
 
249
   *                   ~<keyname> (i.e. ~UP for up-arrow)
 
250
   *   key < 0x1f      standard ^<char> escape sequence
 
251
   *   key == 0x7f     ^? (delete)
 
252
   *   else            a \x?? escape (hex representation of the key)
 
253
   * if `key' is a printable character, a string containing that character
 
254
   * is returned.
 
255
   */
 
256
 
 
257
  extern char *
 
258
tio_vkeyrep( /* int key */ );
 
259
  /* Similar to `tio_keyrep', but returns a long string representation
 
260
   * whenever available.
 
261
   */
 
262
 
 
263
  extern char *
 
264
tio_keyscan( /* int *key, char *s, int mode */ );
 
265
  /* Check if `s' is a sting representation of a key.  on success,
 
266
   * the keycode is written to `*key' and a pointer to the first
 
267
   * character after the srep is returned, else `*key' is set to 0
 
268
   * and `s' is returned.
 
269
   * mode & 1:  scan for escapes starting with a `^'.
 
270
   * mode & 2:  scan for escapes starting with a `~'.
 
271
   * mode == 0:  scan for all known escapes.
 
272
   */
 
273
 
 
274
  extern
 
275
tio_echo( /* int on */ );
 
276
  /* on=1:  characters are echoed as they are typed.
 
277
   * on=0:  characters are not echoed.
 
278
   * RETURN VALUE:  Previous echo-state.
 
279
   */
 
280
 
 
281
  extern void
 
282
tio_return( /* void */ );
 
283
  /* Move cursor to column 0.
 
284
   */
 
285
 
 
286
  extern void
 
287
tio_home( /* void */ );
 
288
  /* Cursor home.
 
289
   */
 
290
 
 
291
  extern void
 
292
tio_goto_line( /* int line */ );
 
293
  /* Move cursor to line `line'.
 
294
   */
 
295
 
 
296
  extern void
 
297
tio_goto_column( /* int line */ );
 
298
  /* Move cursor to column `column'.
 
299
   */
 
300
 
 
301
  extern void
 
302
tio_last_line( /* void */ );
 
303
  /* Move cursor to the last line, column 0.
 
304
   */
 
305
 
 
306
  extern
 
307
tio_scroll_up( /* int count, int first, int last */ );
 
308
  /* Scroll up `count' lines; insert `count' lines at the bottom of the
 
309
   * screen.
 
310
   * The function returns -1 if the terminal can't scroll backwards.
 
311
   */
 
312
 
 
313
  extern
 
314
tio_scroll_down( /* int count, int first, int last */ );
 
315
  /* Scroll down `count' lines; insert `count' lines at the top of the screen.
 
316
   * The function returns -1 if the terminal can't scroll backwards.
 
317
   */
 
318
 
 
319
  extern void
 
320
tio_display( /* char *text, int indent */ );
 
321
  /* Send the string `text' to the terminal.  The string may contain the
 
322
   * following `@*'-commands:
 
323
   *
 
324
   *  @@                   @
 
325
   *  @c                   clear screen.
 
326
   *  @M[+-]rrr[+-]ccc     absolute move.
 
327
   *                       Move the cursor to position row rrr, column ccc.
 
328
   *                       If a value is prefixed by a `-', it is interpreted
 
329
   *                       relative to the bottom-right corner of the screen.
 
330
   *  @m[+-]rrr[+-]ccc     relative move.
 
331
   *  @Iiii                set indent.
 
332
   *  @b                   bell.
 
333
   *  @v                   flash, visible bell.
 
334
   *  @U                   underline on.
 
335
   *  @u                   underline off.
 
336
   *  @Am                  set attribute m, where m is one of the
 
337
   *                       following:
 
338
   *                        b  bold.
 
339
   *                        l  blink.
 
340
   *                        h  half bright.
 
341
   *                        r  reverse.
 
342
   *                        u  underline (equivalent to `@U').
 
343
   *                        s  standout.
 
344
   *                        ~  normal.
 
345
   *  @r                   return.
 
346
   *  @n                   newline.
 
347
   *
 
348
   * `indent' sets the indent.  If `indent < 0', the indent stays unchanged.
 
349
   */
 
350
 
 
351
  extern void
 
352
tio_message( /* char **message, int indent */ );
 
353
  /* displays the array of strings `message' via `tio_display()' providing
 
354
   * a simple pager.  this function assumes, that every string in
 
355
   * `message' displays as a single line.
 
356
   */
 
357
 
 
358
  extern
 
359
#if USE_STDARG
 
360
tio_printf( const char *fmt, ... );
 
361
#else
 
362
tio_printf( );
 
363
#endif
 
364
 
 
365
  extern
 
366
tio_vprintf( /* const char *fmt, va_list */ );
 
367
  /* Similar to `printf()'.  `tio_printf()' understands the same @-commands
 
368
   * as `tio_display()'.  Note that @-commands in strings inserted via %s
 
369
   * are executed.  Use `tio_raw_printf()' if you don't wan't @-commands to
 
370
   * be executed.
 
371
   */
 
372
 
 
373
  extern
 
374
#if USE_STDARG
 
375
tio_raw_printf( const char *fmt, ... );
 
376
#else
 
377
tio_raw_printf( /* const char *fmt, ... */ );
 
378
#endif
 
379
 
 
380
  extern
 
381
tio_raw_vprintf( /* const char *fmt, va_list */ );
 
382
  /* Like `printf()'.  No @-commands.
 
383
   */
 
384
 
 
385
  extern
 
386
tio_puts( /* char *s */ );
 
387
  /* Like `fputs(s, stdout)'.
 
388
   */
 
389
 
 
390
  extern
 
391
tio_putchar( /* int x */ );
 
392
  /* Like `putchar(x)'.
 
393
   */
 
394
 
 
395
  extern void
 
396
tio_up( /* int count */ );
 
397
  /* Move cursor up `count' lines.
 
398
   */
 
399
 
 
400
  extern void
 
401
tio_down( /* int count */ );
 
402
  /* Move cursor down `count' lines.
 
403
   */
 
404
 
 
405
  extern void
 
406
tio_left( /* int count */ );
 
407
  /* Move cursor left `count' lines.
 
408
   */
 
409
  extern void
 
410
tio_right( /* int count */ );
 
411
  /* Move cursor right `count' lines.
 
412
   */
 
413
 
 
414
  extern void
 
415
tio_move( /* int line, int column */ );
 
416
  /* Move the cursor to position `line'/`column'.
 
417
   */
 
418
 
 
419
  extern void
 
420
tio_rel_move( /* int line, int column */ );
 
421
  /* Move the cursor relative to the cursor position.
 
422
   */
 
423
 
 
424
  extern void
 
425
tio_last_line( /* void */ );
 
426
  /* Move the cursor to the last line, first column.
 
427
   */
 
428
 
 
429
  extern void
 
430
tio_clear( /* void */ );
 
431
  /* Clear screen.
 
432
   */
 
433
 
 
434
  extern void
 
435
tio_clear_to_eol( /* void */ );
 
436
  /* Clear to end of line.
 
437
   */
 
438
 
 
439
  extern void
 
440
tio_bell( /* void */ );
 
441
 
 
442
  extern void
 
443
tio_visible_bell( /* void */ );
 
444
 
 
445
  extern void
 
446
tio_underscore( /* void */ );
 
447
 
 
448
  extern void
 
449
tio_underscore_off( /* void */ );
 
450
 
 
451
  extern void
 
452
tio_bold( /* void */ );
 
453
 
 
454
  extern void
 
455
tio_blink( /* void */ );
 
456
 
 
457
  extern void
 
458
tio_half_bright( /* void */ );
 
459
 
 
460
  extern void
 
461
tio_reverse( /* void */ );
 
462
 
 
463
  extern void
 
464
tio_normal( /* void */ );
 
465
  /* End all standout modes.
 
466
   */
 
467
 
 
468
  extern void
 
469
tio_set_cursor( /* int mode */ );
 
470
  /* Set the visibility of the cursor.
 
471
   * `mode == 0':  invisible.
 
472
   * `mode == 1':  normal.
 
473
   * `mode == 2':  standout.
 
474
   */
 
475
 
 
476
  extern
 
477
tio_have_color( /* void */ );
 
478
  /* returns a non-zero value if color is available, 0 else.
 
479
   */
 
480
 
 
481
  extern void
 
482
tio_set_colors( /* int fg_color, int bg_color */ );
 
483
 
 
484
  extern void
 
485
tio_set_fg( /* int color */ );
 
486
  /* set the foreground color to `color'.
 
487
   */
 
488
 
 
489
  extern void
 
490
tio_set_bg( /* int color */ );
 
491
  /* set the background color to `color'.
 
492
   */
 
493
 
 
494
  extern
 
495
tio_get_fg( /* void */ );
 
496
  /* return the current foreground color.
 
497
   */
 
498
 
 
499
  extern
 
500
tio_get_bg( /* void */ );
 
501
  /* return the current background color.
 
502
   */
 
503
 
 
504
  extern
 
505
tio_insert_character( /* char x */ );
 
506
  /* Insert the character `x' at the current position.
 
507
   */
 
508
 
 
509
  extern
 
510
tio_delete_character( /* void */ );
 
511
  /* Delete the character under the cursor.
 
512
   */
 
513
 
 
514
  extern
 
515
tio_readwait( /* int timeout */ );
 
516
  /* Wait until input is availabe on `stdin' using `select()'.
 
517
   * The `timeout' is measured in microseconds.  If `timeout' is a negative
 
518
   * value, `tio_readwait()' blocks until input is availabe.  If
 
519
   * `timeout == 0', `tio_readwait()' will return immeiately.
 
520
   * Return values:
 
521
   *  1  Success.  Data available on `stdin'.
 
522
   *  0  Timeout.  No input availabe.
 
523
   *  -1 Error.  See `select(2)'.
 
524
   * If `tio_readwait()' is interrupted by a signal, -1 is returned and
 
525
   * `errno' is set to `EINTR'.
 
526
   * NOTE:  if the unread-buffer is not empty, 1 is returned.
 
527
   */
 
528
 
 
529
  extern
 
530
tio_raw_readwait( /* int timeout */ );
 
531
  /* Similar to `tio_readwait()', but ignores the unread buffer.
 
532
   */
 
533
 
 
534
  extern
 
535
tio_getwait( /* int timeout */ );
 
536
  /* Similar to `tio_readwait()', but returns also if the unget buffer is
 
537
   * not empty.
 
538
   */
 
539
 
 
540
  extern void
 
541
tio_reset( /* void */ );
 
542
 
 
543
  extern void
 
544
tio_suspend( /* void */ );
 
545
 
 
546
  extern void
 
547
tio_restart( /* void */ );
 
548
 
 
549
#ifndef TIO_MAP
 
550
#define TIO_MAP 0
 
551
#endif
 
552
 
 
553
#if TIO_MAP
 
554
 
 
555
  extern
 
556
tio_mgetch( /* int map, char *map_string */ );
 
557
 
 
558
  extern
 
559
tio_map( /* int map, int *from, int *to */ );
 
560
 
 
561
  extern
 
562
tio_unmap( /* int map, int *from */ );
 
563
 
 
564
  extern char **
 
565
tio_maplist( /* int map */ );
 
566
 
 
567
#endif
 
568
#endif
 
569
 
 
570
/* end of tio.h */
 
571
 
 
572
 
 
573
/* VIM configuration: (do not delete this line)
 
574
 *
 
575
 * vim:aw:bk:bdir=./bak:ch=2:nodg:ef=make.log:efm=%f\:%l\:%m:et:hid:icon:
 
576
 * vim:sw=2:sc:sm:si:textwidth=79:to:ul=1024:wh=12:wrap:wb:
 
577
 */