libDwm-0.9.45
DwmTerminalTricks.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2005
5// All rights reserved.
6//
7// Permission to use, copy, modify and distribute any part of this
8// software for educational, research and non-profit purposes,
9// without fee, and without a written agreement is hereby granted,
10// provided that the above copyright notice, this paragraph and the
11// following paragraphs appear in all copies.
12//
13// Those desiring to incorporate this into commercial products or use
14// for commercial purposes should contact:
15//
16// Daniel W. McRobb
17// dwm@mcplex.net
18//
19// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
20// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
21// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
22// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
23// DAMAGE.
24//
25// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
26// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
27// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
28// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
29// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
31// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
32// TRADEMARK OR OTHER RIGHTS.
33//===========================================================================
34
35//---------------------------------------------------------------------------
38//---------------------------------------------------------------------------
39
40#ifndef _DWMTERMINALTRICKS_HH_
41#define _DWMTERMINALTRICKS_HH_
42
43#include <string>
44#include <sstream>
45
46namespace Dwm {
47
48 //--------------------------------------------------------------------------
50 //--------------------------------------------------------------------------
52 {
53 public:
54 //------------------------------------------------------------------------
58 //------------------------------------------------------------------------
60
61 //------------------------------------------------------------------------
64 //------------------------------------------------------------------------
65 void On(bool on);
66
67 //------------------------------------------------------------------------
70 //------------------------------------------------------------------------
71 template <typename T>
72 std::string Bold(const T & t) const
73 {
74 std::ostringstream os;
75 if (_on) {
76 os.imbue(std::locale(""));
77 os << _startBold;
78 }
79 os << t;
80 if (_on)
81 os << _endBold;
82 return(os.str());
83 }
84
85 //------------------------------------------------------------------------
88 //------------------------------------------------------------------------
89 template <typename T>
90 std::string Underscore(const T & t) const
91 {
92 std::ostringstream os;
93 if (_on) {
94 os.imbue(std::locale(""));
95 os << _startUnderscore;
96 }
97 os << t;
98 if (_on)
99 os << _endUnderscore;
100 return(os.str());
101 }
102
103 //------------------------------------------------------------------------
105 //------------------------------------------------------------------------
106 void Bold(std::ostream & os, bool on)
107 {
108 if (_on) {
109 if (on) {
110 os.imbue(std::locale(""));
111 os << _startBold;
112 }
113 else {
114 os << _endBold;
115 }
116 }
117 return;
118 }
119
120 //------------------------------------------------------------------------
122 //------------------------------------------------------------------------
123 void Underscore(std::ostream & os, bool on)
124 {
125 if (_on) {
126 if (on) {
127 os.imbue(std::locale(""));
128 os << _startUnderscore;
129 }
130 else {
131 os << _endUnderscore;
132 }
133 }
134 return;
135 }
136
137 int Columns() const;
138 int Rows() const;
139
140 private:
141 bool _on;
142 std::string _startBold;
143 std::string _endBold;
144 std::string _startUnderscore;
145 std::string _endUnderscore;
146 int _columns;
147 int _rows;
148 };
149
150} // namespace Dwm
151
152#endif // _DWMTERMINALTRICKS_HH_
153
154
155//---------------------------- emacs settings -----------------------------
156// Local Variables:
157// mode: C++
158// tab-width: 2
159// indent-tabs-mode: nil
160// c-basic-offset: 2
161// End:
162//-------------------------------------------------------------------------
Encapsulate simple terminal tricks (bold and underscore).
Definition DwmTerminalTricks.hh:52
TerminalTricks()
Constructor.
void On(bool on)
If on is true, turns the terminal tricks on.
std::string Bold(const T &t) const
Returns a string representation of t, wrapped with bold start and end strings for terminal output in ...
Definition DwmTerminalTricks.hh:72
std::string Underscore(const T &t) const
Returns a string representation of t, wrapped with underscore start and end strings for terminal outp...
Definition DwmTerminalTricks.hh:90