µGFX  2.9
version 2.9
gwin_console.h
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 /**
9  * @file src/gwin/gwin_console.h
10  * @brief GWIN Graphic window subsystem header file.
11  *
12  * @defgroup Console Console
13  * @ingroup Windows
14  *
15  * @brief Console widget that can be used similar a terminal on a computer.
16  *
17  * @details GWIN allows it to create a console/terminal like window.
18  * You can simply use chprintf() to print to the terminal.
19  *
20  * @pre GFX_USE_GWIN must be set to GFXON in your gfxconf.h
21  * @pre GWIN_NEED_CONSOLE must be set to GFXON in your gfxconf.h
22  *
23  * @{
24  */
25 
26 #ifndef _GWIN_CONSOLE_H
27 #define _GWIN_CONSOLE_H
28 
29 /* This file is included within "src/gwin/gwin.h" */
30 
31 // A console window. Supports wrapped text writing and a cursor.
32 typedef struct GConsoleObject {
33  GWindowObject g;
34  gCoord cx, cy; // Cursor position
35 
36  #if GWIN_CONSOLE_ESCSEQ
37  gU8 startattr; // ANSI-like escape sequences
38  gU8 currattr;
39  gU16 escstate;
40  #endif
41 
42  #if GWIN_CONSOLE_USE_HISTORY
43  char * buffer; // buffer to store console content
44  gMemSize bufsize; // size of buffer
45  gMemSize bufpos; // the position of the next char
46  #endif
47 
48  #if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM
49  struct GConsoleWindowStream_t {
50  const struct GConsoleWindowVMT_t *vmt;
51  _base_asynchronous_channel_data
52  } stream;
53  #endif
54 
55 } GConsoleObject;
56 
57 /**
58  * @brief Create a console window.
59  * @details A console window allows text to be written.
60  * @note Text in a console window supports newlines and will wrap text as required.
61  * @return NULL if there is no resultant drawing area, otherwise a window handle.
62  *
63  * @param[in] g The GDisplay to display this window on
64  * @param[in] gc The GConsoleObject structure to initialise. If this is NULL the structure is dynamically allocated.
65  * @param[in] pInit The initialization parameters to use
66  *
67  * @note The drawing color and the background color get set to the current defaults. If you haven't called
68  * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are GFX_WHITE and GFX_BLACK respectively.
69  * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there
70  * is no default font and text drawing operations will no nothing.
71  * @note On creation even if the window is visible it is not automatically cleared.
72  * You may do that by calling @p gwinClear() (possibly after changing your background color)
73  * @note A console does not save the drawing state. It is not automatically redrawn if the window is moved or
74  * its visibility state is changed.
75  *
76  * @api
77  */
78 GHandle gwinGConsoleCreate(GDisplay *g, GConsoleObject *gc, const GWindowInit *pInit);
79 #define gwinConsoleCreate(gc, pInit) gwinGConsoleCreate(GDISP, gc, pInit)
80 
81 #if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM
82  /**
83  * @brief Get a stream from a console window suitable for use with chprintf().
84  * @return The stream handle or NULL if this is not a console window.
85  *
86  * @param[in] gh The window handle (must be a console window)
87  *
88  * @note Only useful in ChibiOS
89  *
90  * @api
91  */
92  BaseSequentialStream *gwinConsoleGetStream(GHandle gh);
93 #endif
94 
95 #if GWIN_CONSOLE_USE_HISTORY
96  /**
97  * @brief Assign a buffer to keep track of the content while the widget is invisible.
98  * @pre GWIN_CONSOLE_USE_HISTORY must be set to GFXON in your gfxconf.h
99  *
100  * @param[in] gh The window handle (must be a console window)
101  * @param[in] onoff If gTrue a buffer is allocated to maintain console text
102  * when the console is obscured or invisible. If gFalse, then
103  * any existing buffer is deallocated.
104  * @note When the history buffer is turned on, scrolling is implemented using the
105  * history buffer.
106  *
107  * @return gTrue if the history buffer is now turned on.
108  */
109  gBool gwinConsoleSetBuffer(GHandle gh, gBool onoff);
110 #endif
111 
112 /**
113  * @brief Put a character at the cursor position in the window.
114  * @note Uses the current foreground color to draw the character and fills the background using the background drawing color
115  *
116  * @param[in] gh The window handle (must be a console window)
117  * @param[in] c The character to draw
118  *
119  * @api
120  */
121 void gwinPutChar(GHandle gh, char c);
122 
123 /**
124  * @brief Put a string at the cursor position in the window. It will wrap lines as required.
125  * @note Uses the current foreground color to draw the string and fills the background using the background drawing color
126  *
127  * @param[in] gh The window handle (must be a console window)
128  * @param[in] str The string to draw
129  *
130  * @api
131  */
132 void gwinPutString(GHandle gh, const char *str);
133 
134 /**
135  * @brief Put the character array at the cursor position in the window. It will wrap lines as required.
136  * @note Uses the current foreground color to draw the string and fills the background using the background drawing color
137  *
138  * @param[in] gh The window handle (must be a console window)
139  * @param[in] str The string to draw
140  * @param[in] n The number of characters to draw
141  *
142  * @api
143  */
144 void gwinPutCharArray(GHandle gh, const char *str, gMemSize n);
145 
146 /**
147  * @brief Print a formatted string at the cursor position in the window. It will wrap lines as required.
148  * @details This function implements a minimal printf() like functionality
149  * The general parameters format is: %[-][width|*][.precision|*][l|L]p.
150  * The following parameter types (p) are supported:
151  * - <b>x</b> hexadecimal integer.
152  * - <b>X</b> hexadecimal long.
153  * - <b>o</b> octal integer.
154  * - <b>O</b> octal long.
155  * - <b>d</b> decimal signed integer.
156  * - <b>D</b> decimal signed long.
157  * - <b>u</b> decimal unsigned integer.
158  * - <b>U</b> decimal unsigned long.
159  * - <b>c</b> character.
160  * - <b>s</b> string.
161  * @note Uses the current foreground color to draw the string and fills the background using the background drawing color
162  *
163  * @param[in] gh The window handle (must be a console window)
164  * @param[in] fmt The format string (as per printf)
165  * @param[in] ... The format string arguments.
166  *
167  * @api
168  */
169 void gwinPrintf(GHandle gh, const char *fmt, ...);
170 
171 #endif /* _GWIN_CONSOLE_H */
172 /** @} */
GHandle gwinGConsoleCreate(GDisplay *g, GConsoleObject *gc, const GWindowInit *pInit)
Create a console window.
void gwinPutCharArray(GHandle gh, const char *str, gMemSize n)
Put the character array at the cursor position in the window. It will wrap lines as required.
void gwinPutString(GHandle gh, const char *str)
Put a string at the cursor position in the window. It will wrap lines as required.
void gwinPrintf(GHandle gh, const char *fmt,...)
Print a formatted string at the cursor position in the window. It will wrap lines as required.
void gwinPutChar(GHandle gh, char c)
Put a character at the cursor position in the window.
gI16 gCoord
The type for a coordinate or length on the screen.
Definition: gdisp.h:39
The structure to initialise a GWIN.
Definition: gwin.h:75
A window object structure.
Definition: gwin.h:40