1
// ---------------------------------------------------------------------------
3
// - standard object library - terminal output stream class definition -
4
// ---------------------------------------------------------------------------
5
// - This program is free software; you can redistribute it and/or modify -
6
// - it provided that this copyright notice is kept intact. -
8
// - This program is distributed in the hope that it will be useful, but -
9
// - without any warranty; without even the implied warranty of -
10
// - merchantability or fitness for a particular purpose. In no event shall -
11
// - the copyright holder be liable for any direct, indirect, incidental or -
12
// - special damages arising in any way out of the use of this software. -
13
// ---------------------------------------------------------------------------
14
// - copyright (c) 1999-2011 amaury darsch -
15
// ---------------------------------------------------------------------------
17
#ifndef AFNIX_OUTPUTTERM_HPP
18
#define AFNIX_OUTPUTTERM_HPP
20
#ifndef AFNIX_OUTPUTSTREAM_HPP
21
#include "OutputStream.hpp"
26
/// The OutputTerm class is the terminal output class for writing various
27
/// formatted data. The class implements the Output stream interface. The
28
/// output stream type is selected at construction and can be either standard
29
/// output or error output
30
/// @author amaury darsch
32
class OutputTerm : public OutputStream {
34
/// the terminal mode type
35
enum t_mode {OUTPUT, ERROR};
40
/// the terminfo array
44
/// the insert mode flag
48
/// create a new output stream.
51
/// create a new output stream. The output stream is created with the
52
/// standard output mode (i.e. Output or error)
53
/// @param mode the output mode
54
OutputTerm (t_mode mode);
56
/// destroy this output terminal
59
/// @return the class name
60
String repr (void) const;
62
/// @return the stream descriptor
63
int getsid (void) const;
65
/// @return true if the output stream is a tty
66
bool istty (void) const;
68
/// @return the number of columns
69
long getcols (void) const;
71
/// set or reset the terminal error mode
72
/// @param mode set in error mode if true
73
void temode (const bool mode);
75
/// @return true if the screen has been cleared
78
/// write one character on the output stream.
79
/// @param value the character to write
80
long write (const char value);
82
/// write a character string to the output stream
83
/// @param data the data to write
84
long write (const char* data);
86
/// write an string with the terminal in error mode
87
/// @param value the string to write
88
void error (const String& value);
90
/// insert a character - depending on the insert mode
91
/// @param c the character to insert
92
virtual void insert (const char c);
94
/// insert a character buffer depending on the insert mode
95
/// @param s the character buffer to insert
96
virtual void insert (const char* s);
98
/// insert a unicode character depending on the insert mode
99
/// @param c the unicode character to insert
100
virtual void insert (const t_quad c);
102
/// insert a unicode buffer depending on the insert mode
103
/// @param s the buffer to insert
104
virtual void insert (const t_quad* s);
106
/// insert a string depending on the character mode
107
//// @param s the string to insert
108
virtual void insert (const String& s);
110
/// delete one character in position
111
virtual bool chdel (void);
113
/// move to the beginning of line
114
virtual bool mvbol (void);
116
/// move to the left by a certain amount
117
/// @param num the number of move to do
118
virtual bool movel (const long num);
120
/// move to the right by a certain amount
121
/// @param num the number of move to do
122
virtual bool mover (const long num);
124
/// move up by a certain amount
125
/// @param num the number of move to do
126
virtual bool moveu (const long num);
128
/// move down by a certain amount
129
/// @param num the number of move to do
130
virtual bool moved (const long num);
132
/// move to the bol from a position by a number
133
/// @param pos the current position
134
/// @param num the number of move
135
void mvbol (const long pos, const long num);
137
/// move to the eol from a position by a number
138
/// @param pos the current position
139
/// @param num the number of move
140
void mveol (const long pos, const long num);
143
// make the copy constructor private
144
OutputTerm (const OutputTerm&);
145
// make the assignment operator private
146
OutputTerm& operator = (const OutputTerm&);
149
/// create a new output terminal in a generic way
150
/// @param argv the argument vector
151
static Object* mkout (Vector* argv);
153
/// create a new error terminal in a generic way
154
/// @param argv the argument vector
155
static Object* mkerr (Vector* argv);
157
/// @return true if the given quark is defined
158
bool isquark (const long quark, const bool hflg) const;
160
/// apply this object with a set of arguments and a quark
161
/// @param robj the current runnable
162
/// @param nset the current nameset
163
/// @param quark the quark to apply these arguments
164
/// @param argv the arguments to apply
165
Object* apply (Runnable* robj, Nameset* nset, const long quark,