2013-05-03 14:36:17 +00:00
|
|
|
/*
|
2013-06-15 11:09:02 +00:00
|
|
|
* This file is subject to the terms of the GFX License. If a copy of
|
2013-05-03 14:36:17 +00:00
|
|
|
* the license was not distributed with this file, you can obtain one at:
|
|
|
|
*
|
2013-07-21 20:20:37 +00:00
|
|
|
* http://ugfx.org/license.html
|
2013-05-03 14:36:17 +00:00
|
|
|
*/
|
2013-05-06 04:44:47 +00:00
|
|
|
|
|
|
|
/**
|
2014-08-20 07:42:53 +00:00
|
|
|
* @file src/gwin/gwin_console.h
|
2013-05-06 04:44:47 +00:00
|
|
|
* @brief GWIN Graphic window subsystem header file.
|
|
|
|
*
|
|
|
|
* @defgroup Console Console
|
2014-05-20 16:05:38 +00:00
|
|
|
* @ingroup Windows
|
2013-05-06 04:44:47 +00:00
|
|
|
*
|
2015-11-07 15:33:28 +00:00
|
|
|
* @brief Console widget that can be used similar a terminal on a computer.
|
|
|
|
*
|
2013-05-06 04:44:47 +00:00
|
|
|
* @details GWIN allows it to create a console/terminal like window.
|
|
|
|
* You can simply use chprintf() to print to the terminal.
|
|
|
|
*
|
2018-02-27 07:44:21 +00:00
|
|
|
* @pre GFX_USE_GWIN must be set to GFXON in your gfxconf.h
|
|
|
|
* @pre GWIN_NEED_CONSOLE must be set to GFXON in your gfxconf.h
|
2013-05-06 04:44:47 +00:00
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GWIN_CONSOLE_H
|
|
|
|
#define _GWIN_CONSOLE_H
|
|
|
|
|
2015-01-21 07:26:24 +00:00
|
|
|
/* This file is included within "src/gwin/gwin.h" */
|
2013-05-06 04:44:47 +00:00
|
|
|
|
|
|
|
// A console window. Supports wrapped text writing and a cursor.
|
2013-07-07 09:40:37 +00:00
|
|
|
typedef struct GConsoleObject {
|
2013-06-06 04:33:32 +00:00
|
|
|
GWindowObject g;
|
2018-07-08 00:54:19 +00:00
|
|
|
gCoord cx, cy; // Cursor position
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2014-03-04 04:14:15 +00:00
|
|
|
#if GWIN_CONSOLE_ESCSEQ
|
|
|
|
uint8_t startattr; // ANSI-like escape sequences
|
|
|
|
uint8_t currattr;
|
|
|
|
uint16_t escstate;
|
|
|
|
#endif
|
|
|
|
|
2014-01-03 18:14:41 +00:00
|
|
|
#if GWIN_CONSOLE_USE_HISTORY
|
2014-01-17 08:36:28 +00:00
|
|
|
char * buffer; // buffer to store console content
|
|
|
|
size_t bufsize; // size of buffer
|
|
|
|
size_t bufpos; // the position of the next char
|
2013-12-18 15:49:49 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-25 16:06:55 +00:00
|
|
|
#if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM
|
2013-05-24 15:26:52 +00:00
|
|
|
struct GConsoleWindowStream_t {
|
|
|
|
const struct GConsoleWindowVMT_t *vmt;
|
|
|
|
_base_asynchronous_channel_data
|
2013-12-17 15:48:03 +00:00
|
|
|
} stream;
|
2013-05-24 15:26:52 +00:00
|
|
|
#endif
|
2013-05-06 04:44:47 +00:00
|
|
|
|
2013-12-17 15:48:03 +00:00
|
|
|
} GConsoleObject;
|
2013-05-06 04:44:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Create a console window.
|
2013-07-07 09:40:37 +00:00
|
|
|
* @details A console window allows text to be written.
|
|
|
|
* @note Text in a console window supports newlines and will wrap text as required.
|
2013-05-06 04:44:47 +00:00
|
|
|
* @return NULL if there is no resultant drawing area, otherwise a window handle.
|
|
|
|
*
|
2013-10-24 08:36:11 +00:00
|
|
|
* @param[in] g The GDisplay to display this window on
|
2013-05-06 04:44:47 +00:00
|
|
|
* @param[in] gc The GConsoleObject structure to initialise. If this is NULL the structure is dynamically allocated.
|
2013-06-24 12:58:37 +00:00
|
|
|
* @param[in] pInit The initialization parameters to use
|
2013-06-06 04:33:32 +00:00
|
|
|
*
|
2013-06-07 16:27:59 +00:00
|
|
|
* @note The drawing color and the background color get set to the current defaults. If you haven't called
|
2018-03-10 10:36:12 +00:00
|
|
|
* @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are GFX_WHITE and GFX_BLACK respectively.
|
2013-06-07 16:27:59 +00:00
|
|
|
* @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there
|
|
|
|
* is no default font and text drawing operations will no nothing.
|
2013-06-24 12:58:37 +00:00
|
|
|
* @note On creation even if the window is visible it is not automatically cleared.
|
|
|
|
* You may do that by calling @p gwinClear() (possibly after changing your background color)
|
2013-06-07 16:27:59 +00:00
|
|
|
* @note A console does not save the drawing state. It is not automatically redrawn if the window is moved or
|
|
|
|
* its visibility state is changed.
|
2013-05-06 04:44:47 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-10-24 08:36:11 +00:00
|
|
|
GHandle gwinGConsoleCreate(GDisplay *g, GConsoleObject *gc, const GWindowInit *pInit);
|
|
|
|
#define gwinConsoleCreate(gc, pInit) gwinGConsoleCreate(GDISP, gc, pInit)
|
2013-05-06 04:44:47 +00:00
|
|
|
|
2013-05-25 16:06:55 +00:00
|
|
|
#if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM
|
2013-05-24 15:26:52 +00:00
|
|
|
/**
|
|
|
|
* @brief Get a stream from a console window suitable for use with chprintf().
|
|
|
|
* @return The stream handle or NULL if this is not a console window.
|
|
|
|
*
|
|
|
|
* @param[in] gh The window handle (must be a console window)
|
|
|
|
*
|
|
|
|
* @note Only useful in ChibiOS
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-07-07 09:40:37 +00:00
|
|
|
BaseSequentialStream *gwinConsoleGetStream(GHandle gh);
|
2013-05-24 15:26:52 +00:00
|
|
|
#endif
|
2013-05-06 04:44:47 +00:00
|
|
|
|
2014-01-03 18:14:41 +00:00
|
|
|
#if GWIN_CONSOLE_USE_HISTORY
|
2013-12-18 15:49:49 +00:00
|
|
|
/**
|
2014-01-17 08:36:28 +00:00
|
|
|
* @brief Assign a buffer to keep track of the content while the widget is invisible.
|
2018-02-27 07:44:21 +00:00
|
|
|
* @pre GWIN_CONSOLE_USE_HISTORY must be set to GFXON in your gfxconf.h
|
2013-12-18 15:49:49 +00:00
|
|
|
*
|
|
|
|
* @param[in] gh The window handle (must be a console window)
|
2018-06-23 03:02:07 +00:00
|
|
|
* @param[in] onoff If gTrue a buffer is allocated to maintain console text
|
|
|
|
* when the console is obscured or invisible. If gFalse, then
|
2014-01-17 08:36:28 +00:00
|
|
|
* any existing buffer is deallocated.
|
|
|
|
* @note When the history buffer is turned on, scrolling is implemented using the
|
|
|
|
* history buffer.
|
2013-12-18 15:49:49 +00:00
|
|
|
*
|
2018-06-23 03:02:07 +00:00
|
|
|
* @return gTrue if the history buffer is now turned on.
|
2014-01-17 08:36:28 +00:00
|
|
|
*/
|
2018-06-23 03:02:07 +00:00
|
|
|
gBool gwinConsoleSetBuffer(GHandle gh, gBool onoff);
|
2013-12-18 15:49:49 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-06 04:44:47 +00:00
|
|
|
/**
|
|
|
|
* @brief Put a character at the cursor position in the window.
|
|
|
|
* @note Uses the current foreground color to draw the character and fills the background using the background drawing color
|
|
|
|
*
|
|
|
|
* @param[in] gh The window handle (must be a console window)
|
|
|
|
* @param[in] c The character to draw
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void gwinPutChar(GHandle gh, char c);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Put a string at the cursor position in the window. It will wrap lines as required.
|
|
|
|
* @note Uses the current foreground color to draw the string and fills the background using the background drawing color
|
|
|
|
*
|
|
|
|
* @param[in] gh The window handle (must be a console window)
|
|
|
|
* @param[in] str The string to draw
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void gwinPutString(GHandle gh, const char *str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Put the character array at the cursor position in the window. It will wrap lines as required.
|
|
|
|
* @note Uses the current foreground color to draw the string and fills the background using the background drawing color
|
|
|
|
*
|
|
|
|
* @param[in] gh The window handle (must be a console window)
|
|
|
|
* @param[in] str The string to draw
|
|
|
|
* @param[in] n The number of characters to draw
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void gwinPutCharArray(GHandle gh, const char *str, size_t n);
|
|
|
|
|
2013-05-25 16:06:55 +00:00
|
|
|
/**
|
|
|
|
* @brief Print a formatted string at the cursor position in the window. It will wrap lines as required.
|
|
|
|
* @details This function implements a minimal printf() like functionality
|
|
|
|
* The general parameters format is: %[-][width|*][.precision|*][l|L]p.
|
|
|
|
* The following parameter types (p) are supported:
|
|
|
|
* - <b>x</b> hexadecimal integer.
|
|
|
|
* - <b>X</b> hexadecimal long.
|
|
|
|
* - <b>o</b> octal integer.
|
|
|
|
* - <b>O</b> octal long.
|
|
|
|
* - <b>d</b> decimal signed integer.
|
|
|
|
* - <b>D</b> decimal signed long.
|
|
|
|
* - <b>u</b> decimal unsigned integer.
|
|
|
|
* - <b>U</b> decimal unsigned long.
|
|
|
|
* - <b>c</b> character.
|
|
|
|
* - <b>s</b> string.
|
|
|
|
* @note Uses the current foreground color to draw the string and fills the background using the background drawing color
|
|
|
|
*
|
|
|
|
* @param[in] gh The window handle (must be a console window)
|
|
|
|
* @param[in] fmt The format string (as per printf)
|
|
|
|
* @param[in] ... The format string arguments.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void gwinPrintf(GHandle gh, const char *fmt, ...);
|
|
|
|
|
2013-05-06 04:44:47 +00:00
|
|
|
#endif /* _GWIN_CONSOLE_H */
|
|
|
|
/** @} */
|