2010-06-11 15:38:22 +00:00
# ifndef DEBUGGER_CONSOLE_H
# define DEBUGGER_CONSOLE_H
2016-09-10 12:46:09 +00:00
# include <cstdarg>
2022-02-17 22:12:04 +00:00
# include "StrFormat.h"
2010-06-11 15:38:22 +00:00
enum
{
2011-01-30 17:39:19 +00:00
// Basic Symbol table has > 600 symbols
// Lines, was 128, but need ~ 256+16 for PROFILE LIST
// Output
CONSOLE_HEIGHT = 768 ,
2010-06-11 15:38:22 +00:00
CONSOLE_WIDTH = 80 ,
// need min 256+ lines for "profile list"
2010-12-18 16:05:20 +00:00
CONSOLE_BUFFER_HEIGHT = CONSOLE_HEIGHT ,
2010-06-11 15:38:22 +00:00
2011-01-30 17:39:19 +00:00
// Input
2010-06-11 15:38:22 +00:00
HISTORY_HEIGHT = 128 ,
HISTORY_WIDTH = 128 ,
CONSOLE_FIRST_LINE = 1 , // where ConsoleDisplay is pushed up from
} ;
// Color ____________________________________________________________________
// typedef unsigned char conchar_t;
typedef short conchar_t ;
2010-12-18 15:02:19 +00:00
// NOTE: Keep in sync ConsoleColors_e g_anConsoleColor !
2010-06-11 15:38:22 +00:00
enum ConsoleColors_e
{
CONSOLE_COLOR_K , // 0
CONSOLE_COLOR_x = 0 , // default console foreground
2010-12-18 15:02:19 +00:00
CONSOLE_COLOR_R , // 1 Red
CONSOLE_COLOR_G , // 2 Green
CONSOLE_COLOR_Y , // 3 Yellow
CONSOLE_COLOR_B , // 4 Blue
CONSOLE_COLOR_M , // 5 Magenta/Purple
CONSOLE_COLOR_C , // 6 Cyan
CONSOLE_COLOR_W , // 7 White
CONSOLE_COLOR_O , // 8 Orange
2010-06-11 15:38:22 +00:00
CONSOLE_COLOR_k , // 9 Grey
2014-12-01 02:39:04 +00:00
CONSOLE_COLOR_b , // : Light Blue
2010-06-11 15:38:22 +00:00
NUM_CONSOLE_COLORS
} ;
extern COLORREF g_anConsoleColor [ NUM_CONSOLE_COLORS ] ;
// Note: THe ` ~ key should always display ~ to prevent rendering errors
# define CONSOLE_COLOR_ESCAPE_CHAR '`'
# define _CONSOLE_COLOR_MASK 0x7F
/* Help Colors
*/
# if 1 // USE_APPLE_FONT
2010-12-18 15:02:19 +00:00
// TODO: char *g_aColorTextStrings[] = ""
// TODO: replace with CT_STRINGS[0]
// TODO: CT_COMMA
// TODO: CT_COLON
// TODO: CT_PAREN_L
// TODO: CT_PAREN_R
2010-06-11 15:38:22 +00:00
// Console Help Color
# define CHC_DEFAULT "`0"
# define CHC_USAGE "`3"
2023-04-28 15:28:49 +00:00
# define CHC_CATEGORY "`6" // Cyan
2010-12-18 15:02:19 +00:00
# define CHC_COMMAND "`2" // Green
2014-12-01 02:39:04 +00:00
# define CHC_KEY "`1" // Red
2010-06-11 15:38:22 +00:00
# define CHC_ARG_MAND "`7" // < >
# define CHC_ARG_OPT "`4" // [ ]
# define CHC_ARG_SEP "`9" // | grey
2022-01-04 06:18:12 +00:00
# define CHC_NUM_DEC "`:" // Lite Blue looks better then yellow (_SearchMemoryDisplay), S D000:FFFF A9 00, PROFILE, HELP BP
2010-06-11 15:38:22 +00:00
# define CHC_NUM_HEX "`3"
2010-12-18 15:02:19 +00:00
# define CHC_SYMBOL "`2" // Symbols
# define CHC_ADDRESS "`8" // Hex Address
2014-12-01 02:39:04 +00:00
# define CHC_ERROR "`1" // Red
2022-01-04 06:15:41 +00:00
# define CHC_WARNING "`8" // Orange
2014-12-01 02:39:04 +00:00
# define CHC_INFO "`3" // Yellow
# define CHC_STRING "`6" //
2010-12-18 15:02:19 +00:00
# define CHC_EXAMPLE "`:"
2014-12-01 02:39:04 +00:00
# define CHC_PATH "`:" // Light Blue
2023-03-26 17:54:30 +00:00
# define CHC_REGS "`6" // Cyan
2010-06-11 15:38:22 +00:00
# else
# define CHC_DEFAULT ""
# define CHC_USAGE ""
# define CHC_COMMAND ""
# define CHC_KEY ""
# define CHC_ARG_MAND ""
# define CHC_ARG_OPT ""
# define CHC_ARG_SEP ""
# define CHC_NUMBER ""
# define CHC_SYMBOL ""
# define CHC_ADDRESS ""
# define CHC_ERROR ""
# define CHC_STRING ""
# define CHC_EXAMPLE ""
# endif
// ascii markup
inline bool ConsoleColor_IsCharMeta ( unsigned char c )
{
if ( CONSOLE_COLOR_ESCAPE_CHAR = = c )
return true ;
return false ;
}
inline bool ConsoleColor_IsCharColor ( unsigned char c )
{
if ( ( c > = ' 0 ' ) & & ( ( c - ' 0 ' ) < NUM_CONSOLE_COLORS ) )
return true ;
return false ;
}
// Console "Native" Chars
//
// There are a few different ways of encoding color chars & mouse text
// Simplist method is to use a user-defined ESCAPE char to shift
// into color mode, or mouse text mode. The other solution
// is to use a wide-char, simulating unicode16.
//
// C1C0 char16 of High Byte (c1) and Low Byte (c0)
// 1) --?? Con: Colors chars take up extra chars.
// Con: String Length is complicated.
// Pro: simple to parse
//
// <-- WE USE THIS
// 2) ccea Pro: Efficient packing of plain text and mouse text
// Pro: Color is optional (only record new color)
// Con: need to provide char8 and char16 API
// Con: little more difficult to parse/convert plain text
// i.e.
// ea = 0x20 - 0x7F ASCII
// 0x80 - 0xFF Mouse Text '@'-'Z' -> 0x00 - 0x1F
// cc = ASCII '0' - '9' (color)
// 3) ??cc Con: Colors chars take up extra chars
// 4) f?? Con: Colors chars take up extra chars
//
// Legend:
// f Flag
// -- Not Applicable (n/a)
// ?? ASCII (0x20 - 0x7F)
// ea Extended ASCII with High-Bit representing Mouse Text
// cc Encoded Color / Mouse Text
//
inline bool ConsoleColor_IsColorOrMouse ( conchar_t g )
{
if ( g > _CONSOLE_COLOR_MASK )
return true ;
return false ;
}
inline bool ConsoleColor_IsColor ( conchar_t g )
{
return ConsoleColor_IsCharColor ( g > > 8 ) ;
}
inline COLORREF ConsoleColor_GetColor ( conchar_t g )
{
const int iColor = ( g > > 8 ) - ' 0 ' ;
if ( iColor < NUM_CONSOLE_COLORS )
return g_anConsoleColor [ iColor ] ;
return g_anConsoleColor [ 0 ] ;
}
inline char ConsoleColor_GetMeta ( conchar_t g )
{
return ( ( g > > 8 ) & _CONSOLE_COLOR_MASK ) ;
}
inline char ConsoleChar_GetChar ( conchar_t g )
{
return ( g & _CONSOLE_COLOR_MASK ) ;
}
inline char ConsoleColor_MakeMouse ( unsigned char c )
{
return ( ( c - ' @ ' ) + ( _CONSOLE_COLOR_MASK + 1 ) ) ;
}
inline conchar_t ConsoleColor_MakeMeta ( unsigned char c )
{
conchar_t g = ( ConsoleColor_MakeMouse ( c ) < < 8 ) ;
return g ;
}
inline conchar_t ConsoleColor_MakeColor ( unsigned char color , unsigned char text )
{
conchar_t g = ( color < < 8 ) | text ;
return g ;
}
2014-12-01 01:47:26 +00:00
// Return the string length without the markup
inline int ConsoleColor_StringLength ( const char * pText )
{
const char * pSrc = pText ;
/* */ int nLen = 0 ;
2022-03-27 19:48:26 +00:00
if ( pText )
2014-12-01 01:47:26 +00:00
{
2022-03-27 19:48:26 +00:00
while ( * pSrc )
2014-12-01 01:47:26 +00:00
{
2022-03-27 19:48:26 +00:00
if ( ConsoleColor_IsCharMeta ( * pSrc ) )
2014-12-01 01:47:26 +00:00
pSrc + + ;
else
nLen + + ;
pSrc + + ;
}
}
return nLen ;
}
2010-06-11 15:38:22 +00:00
// Globals __________________________________________________________________
// Buffer
extern bool g_bConsoleBufferPaused ;
extern int g_nConsoleBuffer ;
2014-08-14 19:29:01 +00:00
extern conchar_t g_aConsoleBuffer [ CONSOLE_BUFFER_HEIGHT ] [ CONSOLE_WIDTH ] ; // TODO: std::vector< line_t >
2010-06-11 15:38:22 +00:00
// Cursor
extern char g_sConsoleCursor [ ] ;
// Display
extern char g_aConsolePrompt [ ] ; // = TEXT(">!"); // input, assembler // NUM_PROMPTS
extern char g_sConsolePrompt [ ] ; // = TEXT(">"); // No, NOT Integer Basic! The nostalgic '*' "Monitor" doesn't look as good, IMHO. :-(
extern int g_nConsolePromptLen ;
extern bool g_bConsoleFullWidth ; // = false;
extern int g_iConsoleDisplayStart ; // to allow scrolling
extern int g_nConsoleDisplayTotal ; // number of lines added to console
extern int g_nConsoleDisplayLines ;
extern int g_nConsoleDisplayWidth ;
extern conchar_t g_aConsoleDisplay [ CONSOLE_HEIGHT ] [ CONSOLE_WIDTH ] ;
// Input History
extern int g_nHistoryLinesStart ; // = 0;
extern int g_nHistoryLinesTotal ; // = 0; // number of commands entered
extern char g_aHistoryLines [ HISTORY_HEIGHT ] [ HISTORY_WIDTH ] ; // = {TEXT("")};
// Input Line
// Raw input Line (has prompt)
extern char g_aConsoleInput [ CONSOLE_WIDTH ] ;
// Cooked input line (no prompt)
2023-04-25 03:00:08 +00:00
extern int g_nConsoleInputChars ;
extern char * g_pConsoleInput ; // points to past prompt
extern int g_nConsoleInputMaxLen ; // = g_nConsoleDisplayWidth-1 = 78 // Maximum number of characters allowed on input line
extern int g_nConsoleInputScrollWidth ; // = g_nConsoleDisplayWidth-1 = 78 // Maximum number of characters for the horizontol scrolling window on the input line
extern const char * g_pConsoleFirstArg ; // points to first arg
extern bool g_bConsoleInputQuoted ;
2010-06-11 15:38:22 +00:00
extern char g_nConsoleInputSkip ;
// Prototypes _______________________________________________________________
// Console
// Buffered
2022-02-17 22:12:04 +00:00
void ConsolePrint ( const char * pText ) ;
inline void ConsolePrintVa ( const char * pFormat , va_list va )
2016-09-10 12:46:09 +00:00
{
2022-02-17 22:12:04 +00:00
std : : string strText = StrFormatV ( pFormat , va ) ;
ConsolePrint ( strText . c_str ( ) ) ;
2016-09-10 12:46:09 +00:00
}
2022-02-26 17:15:09 +00:00
inline void ConsolePrintFormat ( const char * pFormat , . . . ) ATTRIBUTE_FORMAT_PRINTF ( 1 , 2 ) ;
inline void ConsolePrintFormat ( const char * pFormat , . . . )
2016-09-10 12:46:09 +00:00
{
va_list va ;
va_start ( va , pFormat ) ;
2022-02-17 22:12:04 +00:00
ConsolePrintVa ( pFormat , va ) ;
2016-09-10 12:46:09 +00:00
va_end ( va ) ;
}
2022-02-17 22:12:04 +00:00
void ConsoleBufferToDisplay ( ) ;
const conchar_t * ConsoleBufferPeek ( ) ;
void ConsoleBufferPop ( ) ;
void ConsoleBufferPush ( const char * pString ) ;
inline void ConsoleBufferPushVa ( const char * pFormat , va_list va )
{
std : : string strText = StrFormatV ( pFormat , va ) ;
ConsoleBufferPush ( strText . c_str ( ) ) ;
}
2022-02-26 17:15:09 +00:00
inline void ConsoleBufferPushFormat ( const char * pFormat , . . . ) ATTRIBUTE_FORMAT_PRINTF ( 1 , 2 ) ;
inline void ConsoleBufferPushFormat ( const char * pFormat , . . . )
2016-09-10 12:46:09 +00:00
{
va_list va ;
va_start ( va , pFormat ) ;
2022-02-17 22:12:04 +00:00
ConsoleBufferPushVa ( pFormat , va ) ;
2016-09-10 12:46:09 +00:00
va_end ( va ) ;
}
2022-02-17 22:12:04 +00:00
void ConsoleConvertFromText ( conchar_t * sText , const char * pText ) ;
2016-09-10 12:46:09 +00:00
2022-02-17 22:12:04 +00:00
// Display
Update_t ConsoleDisplayError ( const char * pTextError ) ;
inline Update_t ConsoleDisplayErrorVa ( const char * pFormat , va_list va )
2016-09-10 12:46:09 +00:00
{
2022-02-17 22:12:04 +00:00
std : : string strText = StrFormatV ( pFormat , va ) ;
return ConsoleDisplayError ( strText . c_str ( ) ) ;
2016-09-10 12:46:09 +00:00
}
2022-02-26 17:15:09 +00:00
inline Update_t ConsoleDisplayErrorFormat ( const char * pFormat , . . . ) ATTRIBUTE_FORMAT_PRINTF ( 1 , 2 ) ;
inline Update_t ConsoleDisplayErrorFormat ( const char * pFormat , . . . )
2016-09-10 12:46:09 +00:00
{
va_list va ;
va_start ( va , pFormat ) ;
2022-02-17 22:12:04 +00:00
Update_t const r = ConsoleDisplayErrorVa ( pFormat , va ) ;
2016-09-10 12:46:09 +00:00
va_end ( va ) ;
return r ;
}
2022-02-17 22:12:04 +00:00
void ConsoleDisplayPause ( ) ;
void ConsoleDisplayPush ( const char * pText ) ;
inline void ConsoleDisplayPushVa ( const char * pFormat , va_list va )
{
std : : string strText = StrFormatV ( pFormat , va ) ;
ConsoleDisplayPush ( strText . c_str ( ) ) ;
}
2022-02-26 17:15:09 +00:00
inline void ConsoleDisplayPushFormat ( const char * pFormat , . . . ) ATTRIBUTE_FORMAT_PRINTF ( 1 , 2 ) ;
inline void ConsoleDisplayPushFormat ( const char * pFormat , . . . )
2016-09-10 12:46:09 +00:00
{
va_list va ;
va_start ( va , pFormat ) ;
2022-02-17 22:12:04 +00:00
ConsoleDisplayPushVa ( pFormat , va ) ;
2016-09-10 12:46:09 +00:00
va_end ( va ) ;
}
2010-06-11 15:38:22 +00:00
void ConsoleDisplayPush ( const conchar_t * pText ) ;
Update_t ConsoleUpdate ( ) ;
void ConsoleFlush ( ) ;
// Input
const char * ConsoleInputPeek ( ) ;
bool ConsoleInputClear ( ) ;
bool ConsoleInputBackSpace ( ) ;
2022-02-17 22:12:04 +00:00
bool ConsoleInputChar ( char ch ) ;
2010-06-11 15:38:22 +00:00
void ConsoleInputReset ( ) ;
int ConsoleInputTabCompletion ( ) ;
void ConsoleUpdateCursor ( char ch ) ;
Update_t ConsoleBufferTryUnpause ( int nLines ) ;
// Scrolling
Update_t ConsoleScrollHome ( ) ;
Update_t ConsoleScrollEnd ( ) ;
Update_t ConsoleScrollUp ( int nLines ) ;
Update_t ConsoleScrollDn ( int nLines ) ;
Update_t ConsoleScrollPageUp ( ) ;
Update_t ConsoleScrollPageDn ( ) ;
# endif