File: term.h

package info (click to toggle)
curves 0.8.19
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge, squeeze, wheezy
  • size: 724 kB
  • ctags: 1,016
  • sloc: cpp: 6,284; ansic: 535; makefile: 292; sh: 192; fortran: 149
file content (121 lines) | stat: -rw-r--r-- 3,254 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* term.h							-*- C++ -*-
   $Id: term.h,v 1.5 2001/11/27 23:57:36 elf Exp $
   
   written by Marc Singer
   27 Jul 1997

   This file is part of the project CurVeS.  See the file README for
   more information.

   Copyright (C) 1997,1998 Marc Singer

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   with your Debian GNU/Linux system, in
   /usr/share/common-licenses/GPL, or with the Debian GNU/Linux hello
   source package as the file COPYING. If not, write to the Free
   Software Foundation, Inc., 59 Temple Place -Suite 330, MA
   02111-1307, USA.

   Terminal abstractions routines.

*/

#if !defined (__TERM_H__)
#    define   __TERM_H__

/* ----- Includes */

#include "termcap.h"

typedef enum {
  attrBold		= 0x0001,
  attrUnderline		= 0x0002,
  attrInverse		= 0x0004,
  attrStandout		= 0x0008,
  attrBlink		= 0x0010,
  //  attrDim		= 0x0020,
  attrAllMode		= 0x003f,
  attrFgBright		= 0x0080,
  attrFgDefault		= 0x0000,	// Foreground colors
  attrFgMask		= 0x0f00,
  attrFgShift		= 8,
  attrFgFirst		= 0x0100,
  attrFgBlack		= 0x0100,
  attrFgRed		= 0x0200,
  attrFgGreen		= 0x0300,
  attrFgYellow		= 0x0400,
  attrFgBlue		= 0x0500,
  attrFgMagenta		= 0x0600,
  attrFgCyan		= 0x0700,
  attrFgWhite		= 0x0800,
  attrBgMask		= 0xf000, 	// Background colors
  attrBgShift		= 12,
  attrBgDefault		= 0x0000,
  attrBgFirst		= 0x1000,
  attrBgBlack		= 0x1000,
  attrBgRed		= 0x2000,
  attrBgGreen		= 0x3000,
  attrBgYellow		= 0x4000,
  attrBgBlue		= 0x5000,
  attrBgMagenta		= 0x6000,
  attrBgCyan		= 0x7000,
  attrBgWhite		= 0x8000,
} eAttribute;

/* ----- Classes */

class LTerm {
private:
  static Termcap g_termcap;

  char* m_pb;			// Buffer of pending output
  int m_cb;			// Amount of data pending for output
  int m_cbMax;			// Length of output buffer
  int m_fh;			// Output file handle

  unsigned16 m_attribute;	// Current display attribute

public:
  LTerm () {
    zero (); }
  ~LTerm () {
    release_this (); }
  void zero (void) {
    memset (this, 0, sizeof (*this)); }
  void init (void);
  void release_this (void);

  void flush (void);

  Termcap& termcap (void) {
    return g_termcap; }

				// Informational methods
  int columns (void) {
    return g_termcap.num (termcapNumColumns); }
  int lines (void) {
    return g_termcap.num (termcapNumLines); }

				// Output queuing methods
  void cls (void) {
    m_cb += g_termcap.compose (termcapClearScreen, m_pb + m_cb); }
  void home (void) {
    m_cb += g_termcap.compose (termcapMoveHome, m_pb + m_cb); }
  void moveto (int line, int column) {
    m_cb += g_termcap.compose (termcapMoveTo, m_pb + m_cb, line, column); }
  void set_attribute (unsigned16 value, unsigned16 mask = ~0);
  int sprintf (char* pb, ...);

};

#endif  /* __TERM_H__ */