]> git.xonotic.org Git - xonotic/darkplaces.git/blob - console.h
CREDITS: Add name
[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 #include <stddef.h>
25 #include "qtypes.h"
26 #include "cmd.h"
27 #include "lhnet.h"
28
29 //
30 // console
31 //
32 extern int con_totallines;
33 extern int con_backscroll;
34 extern qbool con_initialized;
35
36 void Con_Rcon_Redirect_Init(lhnetsocket_t *sock, lhnetaddress_t *dest, qbool proquakeprotocol);
37 void Con_Rcon_Redirect_End(void);
38 void Con_Rcon_Redirect_Abort(void);
39
40 /// If the line width has changed, reformat the buffer.
41 void Con_CheckResize (void);
42 void Con_Init (void);
43 void Con_Init_Commands (void);
44 void Con_Shutdown (void);
45 void Con_DrawConsole (int lines);
46
47 /// Prints to a chosen console target
48 void Con_MaskPrint(int mask, const char *msg);
49
50 // Prints to a chosen console target
51 void Con_MaskPrintf(int mask, const char *fmt, ...) DP_FUNC_PRINTF(2);
52
53 /// Prints to all appropriate console targets, and adds timestamps
54 void Con_Print(const char *txt);
55
56 /// Prints to all appropriate console targets.
57 void Con_Printf(const char *fmt, ...) DP_FUNC_PRINTF(1);
58
59 /// A Con_Print that only shows up if the "developer" cvar is set.
60 void Con_DPrint(const char *msg);
61
62 /// A Con_Printf that only shows up if the "developer" cvar is set
63 void Con_DPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
64 void Con_Clear_f(cmd_state_t *cmd);
65 void Con_DrawNotify (void);
66
67 /// Clear all notify lines.
68 void Con_ClearNotify (void);
69 void Con_ToggleConsole_f(cmd_state_t *cmd);
70
71 qbool GetMapList (const char *s, char *completedname, int completednamebufferlength);
72
73 /// wrapper function to attempt to either complete the command line
74 /// or to list possible matches grouped by type
75 /// (i.e. will display possible variables, aliases, commands
76 /// that match what they've typed so far)
77 int Con_CompleteCommandLine(cmd_state_t *cmd, qbool is_console);
78
79 /// Generic libs/util/console.c function to display a list
80 /// formatted in columns on the console
81 void Con_DisplayList(const char **list);
82
83
84 /*! \name log
85  * @{
86  */
87 void Log_Init (void);
88 void Log_Close (void);
89 void Log_Start (void);
90 void Log_DestBuffer_Flush (void); ///< call this once per frame to send out replies to rcon streaming clients
91
92 void Log_Printf(const char *logfilename, const char *fmt, ...) DP_FUNC_PRINTF(2);
93 //@}
94
95 #define CON_WARN "^3"
96 #define CON_ERROR "^1"
97
98 // CON_MASK_PRINT is the default (Con_Print/Con_Printf)
99 // CON_MASK_DEVELOPER is used by Con_DPrint/Con_DPrintf
100 #define CON_MASK_HIDENOTIFY 128
101 #define CON_MASK_CHAT 1
102 #define CON_MASK_INPUT 2
103 #define CON_MASK_DEVELOPER 4
104 #define CON_MASK_PRINT 8
105
106 typedef struct con_lineinfo_s
107 {
108         char *start;
109         size_t len;
110         int mask;
111
112         /// used only by console.c
113         double addtime;
114         int height; ///< recalculated line height when needed (-1 to unset)
115 }
116 con_lineinfo_t;
117
118 typedef struct conbuffer_s
119 {
120         qbool active;
121         int textsize;
122         char *text;
123         int maxlines;
124         con_lineinfo_t *lines;
125         int lines_first;
126         int lines_count; ///< cyclic buffer
127 }
128 conbuffer_t;
129
130 #define CONBUFFER_LINES(buf, i) (buf)->lines[((buf)->lines_first + (i)) % (buf)->maxlines]
131 #define CONBUFFER_LINES_COUNT(buf) ((buf)->lines_count)
132 #define CONBUFFER_LINES_LAST(buf) CONBUFFER_LINES(buf, CONBUFFER_LINES_COUNT(buf) - 1)
133
134 void ConBuffer_Init(conbuffer_t *buf, int textsize, int maxlines, mempool_t *mempool);
135 void ConBuffer_Clear (conbuffer_t *buf);
136 void ConBuffer_Shutdown(conbuffer_t *buf);
137
138 /*! Notifies the console code about the current time
139  * (and shifts back times of other entries when the time
140  * went backwards)
141  */
142 void ConBuffer_FixTimes(conbuffer_t *buf);
143
144 /// Deletes the first line from the console history.
145 void ConBuffer_DeleteLine(conbuffer_t *buf);
146
147 /// Deletes the last line from the console history.
148 void ConBuffer_DeleteLastLine(conbuffer_t *buf);
149
150 /// Appends a given string as a new line to the console.
151 void ConBuffer_AddLine(conbuffer_t *buf, const char *line, int len, int mask);
152 int ConBuffer_FindPrevLine(conbuffer_t *buf, int mask_must, int mask_mustnot, int start);
153 int ConBuffer_FindNextLine(conbuffer_t *buf, int mask_must, int mask_mustnot, int start);
154 const char *ConBuffer_GetLine(conbuffer_t *buf, int i);
155
156 #endif
157