console.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 The ClanLib Team
4**
5** This software is provided 'as-is', without any express or implied
6** warranty. In no event will the authors be held liable for any damages
7** arising from the use of this software.
8**
9** Permission is granted to anyone to use this software for any purpose,
10** including commercial applications, and to alter it and redistribute it
11** freely, subject to the following restrictions:
12**
13** 1. The origin of this software must not be misrepresented; you must not
14** claim that you wrote the original software. If you use this software
15** in a product, an acknowledgment in the product documentation would be
16** appreciated but is not required.
17** 2. Altered source versions must be plainly marked as such, and must not be
18** misrepresented as being the original software.
19** 3. This notice may not be removed or altered from any source distribution.
20**
21** Note: Some of the libraries ClanLib may link to may have additional
22** requirements or restrictions.
23**
24** File Author(s):
25**
26** Magnus Norddahl
27** Kenneth Gangstoe
28** Mark Page
29*/
30
31#pragma once
32
33// 'kbhit' was declared deprecated
34#ifdef WIN32
35#pragma warning(disable: 4996)
36#endif
37
38#include "string_format.h"
39#include "string_help.h"
40#ifdef WIN32
41#include <conio.h>
42#else
43#include <unistd.h>
44#endif
45
46namespace clan
47{
50
52 class Console
53 {
54 public:
56 static void write(const std::string &text);
57
62 template <class Arg1>
63 static void write(const std::string &format, Arg1 arg1)
64 {
65 StringFormat f(format);
66 f.set_arg(1, arg1);
67 write(f.get_result());
68 }
69
75 template <class Arg1, class Arg2>
76 static void write(const std::string &format, Arg1 arg1, Arg2 arg2)
77 {
78 StringFormat f(format);
79 f.set_arg(1, arg1);
80 f.set_arg(2, arg2);
81 write(f.get_result());
82 }
83
90 template <class Arg1, class Arg2, class Arg3>
91 static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
92 {
93 StringFormat f(format);
94 f.set_arg(1, arg1);
95 f.set_arg(2, arg2);
96 f.set_arg(3, arg3);
97 write(f.get_result());
98 }
99
107 template <class Arg1, class Arg2, class Arg3, class Arg4>
108 static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
109 {
110 StringFormat f(format);
111 f.set_arg(1, arg1);
112 f.set_arg(2, arg2);
113 f.set_arg(3, arg3);
114 f.set_arg(4, arg4);
115 write(f.get_result());
116 }
117
126 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
127 static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
128 {
129 StringFormat f(format);
130 f.set_arg(1, arg1);
131 f.set_arg(2, arg2);
132 f.set_arg(3, arg3);
133 f.set_arg(4, arg4);
134 f.set_arg(arg5);
135 write(f.get_result());
136 }
137
147 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
148 static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
149 {
150 StringFormat f(format);
151 f.set_arg(1, arg1);
152 f.set_arg(2, arg2);
153 f.set_arg(3, arg3);
154 f.set_arg(4, arg4);
155 f.set_arg(arg5);
156 f.set_arg(arg6);
157 write(f.get_result());
158 }
159
170 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
171 static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
172 {
173 StringFormat f(format);
174 f.set_arg(1, arg1);
175 f.set_arg(2, arg2);
176 f.set_arg(3, arg3);
177 f.set_arg(4, arg4);
178 f.set_arg(arg5);
179 f.set_arg(arg6);
180 f.set_arg(arg7);
181 write(f.get_result());
182 }
183
185 static void write_line(const std::string &text)
186 {
187 write(text);
188#ifdef WIN32
189 write("\r\n");
190#else
191 write("\n");
192#endif
193 }
194
199 template <class Arg1>
200 static void write_line(const std::string &format, Arg1 arg1)
201 {
202 StringFormat f(format);
203 f.set_arg(1, arg1);
204 write_line(f.get_result());
205 }
206
212 template <class Arg1, class Arg2>
213 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2)
214 {
215 StringFormat f(format);
216 f.set_arg(1, arg1);
217 f.set_arg(2, arg2);
218 write_line(f.get_result());
219 }
220
227 template <class Arg1, class Arg2, class Arg3>
228 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
229 {
230 StringFormat f(format);
231 f.set_arg(1, arg1);
232 f.set_arg(2, arg2);
233 f.set_arg(3, arg3);
234 write_line(f.get_result());
235 }
236
244 template <class Arg1, class Arg2, class Arg3, class Arg4>
245 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
246 {
247 StringFormat f(format);
248 f.set_arg(1, arg1);
249 f.set_arg(2, arg2);
250 f.set_arg(3, arg3);
251 f.set_arg(4, arg4);
252 write_line(f.get_result());
253 }
254
263 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
264 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
265 {
266 StringFormat f(format);
267 f.set_arg(1, arg1);
268 f.set_arg(2, arg2);
269 f.set_arg(3, arg3);
270 f.set_arg(4, arg4);
271 f.set_arg(5, arg5);
272 write_line(f.get_result());
273 }
274
284 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
285 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
286 {
287 StringFormat f(format);
288 f.set_arg(1, arg1);
289 f.set_arg(2, arg2);
290 f.set_arg(3, arg3);
291 f.set_arg(4, arg4);
292 f.set_arg(5, arg5);
293 f.set_arg(6, arg6);
294 write_line(f.get_result());
295 }
296
307 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
308 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
309 {
310 StringFormat f(format);
311 f.set_arg(1, arg1);
312 f.set_arg(2, arg2);
313 f.set_arg(3, arg3);
314 f.set_arg(4, arg4);
315 f.set_arg(5, arg5);
316 f.set_arg(6, arg6);
317 f.set_arg(7, arg7);
318 write_line(f.get_result());
319 }
320
324 static void wait_for_key();
325 };
326
328}
Console access helper class.
Definition console.h:53
static void write_line(const std::string &text)
Writes text to the console window and then advances to a new line.
Definition console.h:185
static void write(const std::string &text)
Writes text to the console window.
static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
Write.
Definition console.h:108
static void write(const std::string &format, Arg1 arg1)
Write.
Definition console.h:63
static void write(const std::string &format, Arg1 arg1, Arg2 arg2)
Write.
Definition console.h:76
static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
Write.
Definition console.h:171
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
Write line.
Definition console.h:228
static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
Write.
Definition console.h:91
static void wait_for_key()
Block until a key is pressed in the console window.
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
Write line.
Definition console.h:245
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
Write line.
Definition console.h:308
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2)
Write line.
Definition console.h:213
static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
Write.
Definition console.h:148
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
Write line.
Definition console.h:285
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
Write line.
Definition console.h:264
static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
Write.
Definition console.h:127
static void write_line(const std::string &format, Arg1 arg1)
Write line.
Definition console.h:200
String formatting class.
Definition string_format.h:71
Definition clanapp.h:36