Freeciv21
Develop your civilization from humble roots to a global empire
console.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 // utility
14 #include "support.h" // bool type and fc__attribute
15 
16 // Forward definitions
17 class QString;
18 
19 #define MAX_LEN_CONSOLE_LINE \
20  1024 // closing '/* closing '\0' included */' included
21 
22 /*
23  * A note on "rfc-style":
24  *
25  * This style of server output, started with the /rfcstyle server
26  * command, prefixes all output with a status number. This is similar
27  * to how some common ascii based internet protocols like FTP and SMTP
28  * work. A parser can check these numbers to determine whether an
29  * action was successful or not, instead of attempting to parse the
30  * text (which can be translated into various languages and easily
31  * change between versions). This status number is given to the output
32  * functions below as their first parameter, or to cmd_reply* as their
33  * third parameter.
34  */
35 
36 enum rfc_status {
37  C_COMMENT = 0, // for human eyes only
38  C_VERSION = 1, // version info
39  C_DEBUG = 2, // debug info
40  C_LOG_BASE = 10, // 10, 11, 12 depending on log level
41  C_OK = 100, // success of requested operation
42  C_DISCONNECTED = 102, // client gone
43  C_FAIL = 200, // failure of requested operation
44  C_METAERROR = 201, // failure of meta server
45  C_SYNTAX = 300, // syntax error or value out of range
46  C_BOUNCE = 301, // option no longer available
47  C_GENFAIL = 400, // failure not caused by a requested operation
48  C_WARNING = 500 // something may be wrong
49 };
50 
51 #define CON_RED "\u001b[31m"
52 #define CON_GREEN "\u001b[32m"
53 #define CON_YELLOW "\u001b[33m"
54 #define CON_BLUE "\u001b[34m"
55 #define CON_MAGENTA "\u001b[35m"
56 #define CON_CYAN "\u001b[36m"
57 #define CON_WHITE "\u001b[37m"
58 #define CON_RESET "\u001b[0m"
59 
60 void con_set_color(const char *);
61 
62 // initialize logging via console
63 void con_log_init(const QString &log_filename);
64 void con_log_close();
65 
66 // write to console and add line-break, and show prompt if required.
67 void con_write(enum rfc_status rfc_status, const char *message, ...)
68  fc__attribute((__format__(__printf__, 2, 3)));
69 
70 /* write to console and add line-break, and show prompt if required.
71  ie, same as con_write, but without the format string stuff. */
72 void con_puts(enum rfc_status rfc_status, const char *str);
73 
74 // ensure timely update
75 void con_flush();
76 
77 // initialize prompt; display initial message
78 void con_prompt_init();
79 
80 // do not print a prompt after every message
81 void con_prompt_off();
82 
83 // user pressed enter: will need a new prompt
84 void con_prompt_enter();
85 
86 // set server output style
87 void con_set_style(bool i);
88 
89 // return server output style
90 bool con_get_style();
void con_log_init(const QString &log_filename)
Initialize logging via console.
Definition: console.cpp:111
void con_prompt_off()
Do not print a prompt after log messages.
Definition: console.cpp:220
void con_flush()
Ensure timely update.
Definition: console.cpp:183
void con_log_close()
Deinitialize logging.
Definition: console.cpp:123
void void con_puts(enum rfc_status rfc_status, const char *str)
Write to console and add line-break, and show prompt if required.
Definition: console.cpp:162
void con_set_style(bool i)
Set style.
Definition: console.cpp:188
void con_prompt_init()
Initialize prompt; display initial message.
Definition: console.cpp:206
rfc_status
Definition: console.h:36
@ C_DISCONNECTED
Definition: console.h:42
@ C_BOUNCE
Definition: console.h:46
@ C_FAIL
Definition: console.h:43
@ C_SYNTAX
Definition: console.h:45
@ C_DEBUG
Definition: console.h:39
@ C_OK
Definition: console.h:41
@ C_METAERROR
Definition: console.h:44
@ C_GENFAIL
Definition: console.h:47
@ C_LOG_BASE
Definition: console.h:40
@ C_COMMENT
Definition: console.h:37
@ C_VERSION
Definition: console.h:38
@ C_WARNING
Definition: console.h:48
void con_write(enum rfc_status rfc_status, const char *message,...) fc__attribute((__format__(__printf__
bool con_get_style()
Returns rfc-style.
Definition: console.cpp:201
void con_prompt_enter()
User pressed enter: will need a new prompt.
Definition: console.cpp:225
void con_set_color(const char *)
Definition: console.cpp:130
int fc__attribute((nonnull(1, 3)))