]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - console.h
Implement Con_Error(f) and Con_Warn(f), error and warning, for prettier colors
[xonotic/darkplaces.git] / console.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #ifndef CONSOLE_H
22 #define CONSOLE_H
23
24 //
25 // console
26 //
27 extern int con_totallines;
28 extern int con_backscroll;
29 extern qboolean con_initialized;
30
31 void Con_Rcon_Redirect_Init(lhnetsocket_t *sock, lhnetaddress_t *dest, qboolean proquakeprotocol);
32 void Con_Rcon_Redirect_End(void);
33 void Con_Rcon_Redirect_Abort(void);
34
35 /// If the line width has changed, reformat the buffer.
36 void Con_CheckResize (void);
37 void Con_Init (void);
38 void Con_Init_Commands (void);
39 void Con_Shutdown (void);
40 void Con_DrawConsole (int lines);
41
42 /// Prints to a chosen console target
43 void Con_MaskPrint(int mask, const char *msg);
44
45 // Prints to a chosen console target
46 void Con_MaskPrintf(int mask, const char *fmt, ...) DP_FUNC_PRINTF(2);
47
48 /// Prints to all appropriate console targets, and adds timestamps
49 void Con_Print(const char *txt);
50
51 /// Prints to all appropriate console targets.
52 void Con_Printf(const char *fmt, ...) DP_FUNC_PRINTF(1);
53
54 /// Prints warnings
55 void Con_Warn(const char *msg);
56 void Con_Warnf(const char *fmt, ...);
57
58 /// Prints errors
59 void Con_Error(const char *msg);
60 void Con_Errorf(const char *fmt, ...);
61
62 /// A Con_Print that only shows up if the "developer" cvar is set.
63 void Con_DPrint(const char *msg);
64
65 /// A Con_Printf that only shows up if the "developer" cvar is set
66 void Con_DPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
67 void Con_Clear_f(cmd_state_t *cmd);
68 void Con_DrawNotify (void);
69
70 /// Clear all notify lines.
71 void Con_ClearNotify (void);
72 void Con_ToggleConsole_f(cmd_state_t *cmd);
73
74 int Nicks_CompleteChatLine(char *buffer, size_t size, unsigned int pos);
75
76 qboolean GetMapList (const char *s, char *completedname, int completednamebufferlength);
77
78 /// wrapper function to attempt to either complete the command line
79 /// or to list possible matches grouped by type
80 /// (i.e. will display possible variables, aliases, commands
81 /// that match what they've typed so far)
82 void Con_CompleteCommandLine(cmd_state_t *cmd);
83
84 /// Generic libs/util/console.c function to display a list
85 /// formatted in columns on the console
86 void Con_DisplayList(const char **list);
87
88
89 /*! \name log
90  * @{
91  */
92 void Log_Init (void);
93 void Log_Close (void);
94 void Log_Start (void);
95 void Log_DestBuffer_Flush (void); ///< call this once per frame to send out replies to rcon streaming clients
96
97 void Log_Printf(const char *logfilename, const char *fmt, ...) DP_FUNC_PRINTF(2);
98 //@}
99
100 // CON_MASK_PRINT is the default (Con_Print/Con_Printf)
101 // CON_MASK_DEVELOPER is used by Con_DPrint/Con_DPrintf
102 #define CON_MASK_HIDENOTIFY 128
103 #define CON_MASK_CHAT 1
104 #define CON_MASK_INPUT 2
105 #define CON_MASK_DEVELOPER 4
106 #define CON_MASK_PRINT 8
107
108 typedef struct con_lineinfo_s
109 {
110         char *start;
111         size_t len;
112         int mask;
113
114         /// used only by console.c
115         double addtime;
116         int height; ///< recalculated line height when needed (-1 to unset)
117 }
118 con_lineinfo_t;
119
120 typedef struct conbuffer_s
121 {
122         qboolean active;
123         int textsize;
124         char *text;
125         int maxlines;
126         con_lineinfo_t *lines;
127         int lines_first;
128         int lines_count; ///< cyclic buffer
129 }
130 conbuffer_t;
131
132 #define CONBUFFER_LINES(buf, i) (buf)->lines[((buf)->lines_first + (i)) % (buf)->maxlines]
133 #define CONBUFFER_LINES_COUNT(buf) ((buf)->lines_count)
134 #define CONBUFFER_LINES_LAST(buf) CONBUFFER_LINES(buf, CONBUFFER_LINES_COUNT(buf) - 1)
135
136 void ConBuffer_Init(conbuffer_t *buf, int textsize, int maxlines, mempool_t *mempool);
137 void ConBuffer_Clear (conbuffer_t *buf);
138 void ConBuffer_Shutdown(conbuffer_t *buf);
139
140 /*! Notifies the console code about the current time
141  * (and shifts back times of other entries when the time
142  * went backwards)
143  */
144 void ConBuffer_FixTimes(conbuffer_t *buf);
145
146 /// Deletes the first line from the console history.
147 void ConBuffer_DeleteLine(conbuffer_t *buf);
148
149 /// Deletes the last line from the console history.
150 void ConBuffer_DeleteLastLine(conbuffer_t *buf);
151
152 /// Appends a given string as a new line to the console.
153 void ConBuffer_AddLine(conbuffer_t *buf, const char *line, int len, int mask);
154 int ConBuffer_FindPrevLine(conbuffer_t *buf, int mask_must, int mask_mustnot, int start);
155 int ConBuffer_FindNextLine(conbuffer_t *buf, int mask_must, int mask_mustnot, int start);
156 const char *ConBuffer_GetLine(conbuffer_t *buf, int i);
157
158 #endif
159