~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/lib/std/shl/OutputTerm.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ---------------------------------------------------------------------------
 
2
// - OutputTerm.hpp                                                          -
 
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.                  -
 
7
// -                                                                         -
 
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
// ---------------------------------------------------------------------------
 
16
 
 
17
#ifndef  AFNIX_OUTPUTTERM_HPP
 
18
#define  AFNIX_OUTPUTTERM_HPP
 
19
 
 
20
#ifndef  AFNIX_OUTPUTSTREAM_HPP
 
21
#include "OutputStream.hpp"
 
22
#endif
 
23
 
 
24
namespace afnix {
 
25
 
 
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
 
31
 
 
32
  class OutputTerm : public OutputStream {
 
33
  public:
 
34
    /// the terminal mode type
 
35
    enum t_mode {OUTPUT, ERROR};
 
36
 
 
37
  private:
 
38
    /// the stream id
 
39
    int d_sid;
 
40
    /// the terminfo array
 
41
    char** p_tinfo;
 
42
 
 
43
  protected:
 
44
    /// the insert mode flag
 
45
    bool d_insert;
 
46
 
 
47
  public:
 
48
    /// create a new output stream.
 
49
    OutputTerm (void);
 
50
 
 
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);
 
55
 
 
56
    /// destroy this output terminal
 
57
    ~OutputTerm (void);
 
58
 
 
59
    /// @return the class name
 
60
    String repr (void) const;
 
61
 
 
62
    /// @return the stream descriptor
 
63
    int getsid (void) const;
 
64
 
 
65
    /// @return true if the output stream is a tty
 
66
    bool istty (void) const;
 
67
 
 
68
    /// @return the number of columns
 
69
    long getcols (void) const;
 
70
 
 
71
    /// set or reset the terminal error mode
 
72
    /// @param mode set in error mode if true
 
73
    void temode (const bool mode);
 
74
 
 
75
    /// @return true if the screen has been cleared
 
76
    bool clear (void);
 
77
 
 
78
    /// write one character on the output stream.
 
79
    /// @param value the character to write  
 
80
    long write (const char value);
 
81
 
 
82
    /// write a character string to the output stream
 
83
    /// @param data the data to write
 
84
    long write (const char* data);
 
85
 
 
86
    /// write an string with the terminal in error mode
 
87
    /// @param value the string to write
 
88
    void error (const String& value);
 
89
    
 
90
    /// insert a character - depending on the insert mode
 
91
    /// @param c the character to insert
 
92
    virtual void insert (const char c);
 
93
 
 
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);
 
97
 
 
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);
 
101
 
 
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);
 
105
 
 
106
    /// insert a string depending on the character mode
 
107
    //// @param s the string to insert
 
108
    virtual void insert (const String& s);
 
109
 
 
110
    /// delete one character in position
 
111
    virtual bool chdel (void);
 
112
 
 
113
    /// move to the beginning of line
 
114
    virtual bool mvbol (void);
 
115
 
 
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);
 
119
 
 
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);
 
123
 
 
124
    /// move up by a certain amount
 
125
    /// @param num the number of move to do
 
126
    virtual bool moveu (const long num);
 
127
 
 
128
    /// move down by a certain amount
 
129
    /// @param num the number of move to do
 
130
    virtual bool moved (const long num);
 
131
 
 
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);
 
136
 
 
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);
 
141
 
 
142
  private:
 
143
    // make the copy constructor private
 
144
    OutputTerm (const OutputTerm&);
 
145
    // make the assignment operator private
 
146
    OutputTerm& operator = (const OutputTerm&);
 
147
 
 
148
  public:
 
149
    /// create a new output terminal in a generic way
 
150
    /// @param argv the argument vector
 
151
    static Object* mkout (Vector* argv);
 
152
    
 
153
    /// create a new error terminal in a generic way
 
154
    /// @param argv the argument vector
 
155
    static Object* mkerr (Vector* argv);
 
156
 
 
157
    /// @return true if the given quark is defined
 
158
    bool isquark (const long quark, const bool hflg) const;
 
159
 
 
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,
 
166
                   Vector* argv);
 
167
  };
 
168
}
 
169
 
 
170
#endif