File: term-ostream.oo.h

package info (click to toggle)
gettext 0.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 168,104 kB
  • sloc: ansic: 532,579; sh: 68,252; perl: 28,011; makefile: 9,068; lisp: 3,184; yacc: 1,055; java: 615; cs: 589; cpp: 397; objc: 343; sed: 79; tcl: 63; xml: 40; pascal: 11; awk: 7; php: 7
file content (142 lines) | stat: -rw-r--r-- 4,842 bytes parent folder | download | duplicates (4)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* Output stream for attributed text, producing ANSI escape sequences.
   Copyright (C) 2006, 2019-2020 Free Software Foundation, Inc.
   Written by Bruno Haible <bruno@clisp.org>, 2006.

   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 3 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
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */

#ifndef _TERM_OSTREAM_H
#define _TERM_OSTREAM_H

#include <stdbool.h>

#include "ostream.h"


/* Querying and setting of text attributes.
   The stream has a notion of the current text attributes; they apply
   implicitly to all following output.  The attributes are automatically
   reset when the stream is closed.
   Note: Not all terminal types can actually render all attributes adequately.
   For example, xterm cannot render POSTURE_ITALIC nor the combination of
   WEIGHT_BOLD and UNDERLINE_ON.  */

/* Colors are represented by indices >= 0 in a stream dependent format.  */
typedef int term_color_t;
/* The value -1 denotes the default (foreground or background) color.  */
enum
{
  COLOR_DEFAULT = -1  /* unknown */
};

typedef enum
{
  WEIGHT_NORMAL = 0,
  WEIGHT_BOLD,
  WEIGHT_DEFAULT = WEIGHT_NORMAL
} term_weight_t;

typedef enum
{
  POSTURE_NORMAL = 0,
  POSTURE_ITALIC, /* same as oblique */
  POSTURE_DEFAULT = POSTURE_NORMAL
} term_posture_t;

typedef enum
{
  UNDERLINE_OFF = 0,
  UNDERLINE_ON,
  UNDERLINE_DEFAULT = UNDERLINE_OFF
} term_underline_t;

/* Get ttyctl_t.  */
#define term_style_user_data term_ostream_representation
#include "term-style-control.h"

struct term_ostream : struct ostream
{
methods:

  /* Convert an RGB value (red, green, blue in [0..255]) to a color, valid
     for this stream only.  */
  term_color_t rgb_to_color (term_ostream_t stream,
                             int red, int green, int blue);

  /* Get/set the text color.  */
  term_color_t get_color (term_ostream_t stream);
  void         set_color (term_ostream_t stream, term_color_t color);

  /* Get/set the background color.  */
  term_color_t get_bgcolor (term_ostream_t stream);
  void         set_bgcolor (term_ostream_t stream, term_color_t color);

  /* Get/set the font weight.  */
  term_weight_t get_weight (term_ostream_t stream);
  void          set_weight (term_ostream_t stream, term_weight_t weight);

  /* Get/set the font posture.  */
  term_posture_t get_posture (term_ostream_t stream);
  void           set_posture (term_ostream_t stream, term_posture_t posture);

  /* Get/set the text underline decoration.  */
  term_underline_t get_underline (term_ostream_t stream);
  void             set_underline (term_ostream_t stream,
                                  term_underline_t underline);

  /* Get/set the hyperlink attribute and its id.  */
  const char * get_hyperlink_ref (term_ostream_t stream);
  const char * get_hyperlink_id (term_ostream_t stream);
  void         set_hyperlink (term_ostream_t stream,
                              const char *ref, const char *id);

  /* Like term_ostream_flush (first_arg, FLUSH_THIS_STREAM), except that it
     leaves the terminal with the current text attributes enabled, instead of
     with the default text attributes.
     After calling this function, you can output strings without newlines(!)
     to the underlying file descriptor, and they will be rendered like strings
     passed to 'ostream_write_mem', 'ostream_write_str', or
     'ostream_write_printf'.  */
  void flush_to_current_style (term_ostream_t stream);

  /* Accessors.  */
  int          get_descriptor (term_ostream_t stream);
  const char * get_filename (term_ostream_t stream);
  ttyctl_t     get_tty_control (term_ostream_t stream);
  ttyctl_t     get_effective_tty_control (term_ostream_t stream);
};


#ifdef __cplusplus
extern "C" {
#endif


/* Create an output stream referring to the file descriptor FD.
   FILENAME is used only for error messages.
   TTY_CONTROL specifies the amount of control to take over the underlying tty.
   The resulting stream will be line-buffered.
   Note that the resulting stream must be closed before FD can be closed.  */
extern term_ostream_t
       term_ostream_create (int fd, const char *filename, ttyctl_t tty_control);


/* Test whether a given output stream is a term_ostream.  */
extern bool is_instance_of_term_ostream (ostream_t stream);


#ifdef __cplusplus
}
#endif

#endif /* _TERM_OSTREAM_H */