Skip to content

Commit

Permalink
refac conio and shell
Browse files Browse the repository at this point in the history
  • Loading branch information
bha-evs committed Aug 20, 2024
1 parent fcac821 commit d252b63
Show file tree
Hide file tree
Showing 12 changed files with 914 additions and 793 deletions.
86 changes: 41 additions & 45 deletions lib/include/bofstd/bofconio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <bofstd/bofpath.h>

BEGIN_BOF_NAMESPACE()
#define PrintfAt(x, y, pFormat, ...) PrintfAtColor(mForeColor_E, x, y, pFormat, ##__VA_ARGS__)
#define PrintfColor(Color, pFormat, ...) PrintfAtColor(Color, 0, 0, pFormat, ##__VA_ARGS__)
// #define PrintfAt(x, y, pFormat, ...) PrintfAtColor(mForeColor_E, x, y, pFormat, ##__VA_ARGS__)
// #define PrintfColor(Color, pFormat, ...) PrintfAtColor(Color, 0, 0, pFormat, ##__VA_ARGS__)

enum CONIO_MODIFIER_KEY_FLAG : uint32_t
{
Expand Down Expand Up @@ -159,54 +159,50 @@ struct BOF_CONIO_PARAM

class BOFSTD_EXPORT BofConio final
{
private:
BOF_CONIO_PARAM mBofConioParam_X;
uint32_t mConsoleWidth_U32 = 0;
uint32_t mConsoleHeight_U32 = 0;

public:
BofConio(const BOF_CONIO_PARAM &_rBofConioParam_X);
virtual ~BofConio();

// delete copy and move constructors and assign operators
BofConio(BofConio const &) = delete; // Copy construct
BofConio(BofConio &&) = delete; // Move construct
BofConio &operator=(BofConio const &) = delete; // Copy assign
BofConio &operator=(BofConio &&) = delete; // Move assign

uint32_t KbHit(uint32_t _TimeOutInMs_U32);
uint32_t GetCh(bool _OnlyModifier_B);
std::string KeyToString(uint32_t _Key_U32);

BOFERR Readline(const std::string &_rPrompt_S, std::string &_rInputLine_S);

BOFERR SetTextAttribute(uint32_t _TextAttributeFlag_U32); // Use CONIO_TEXT_ATTRIBUTE_FLAG enum ored value
BOFERR SetForegroundTextColor(CONIO_TEXT_COLOR _ForegroundColor_E);
BOFERR SetBackgroundTextColor(CONIO_TEXT_COLOR _BackgroundColor_E);
BOFERR SetForegroundTextColor(BOF_RGBA<uint8_t> _ForegroundColor_E);
BOFERR SetBackgroundTextColor(BOF_RGBA<uint8_t> _BackgroundColor_X);

BOFERR SetTextCursorState(CONIO_TEXT_CURSOR_STATE _CursorState_E);
BOFERR SetTextCursorPosition(uint32_t _x_U32, uint32_t _y_U32);
BOFERR GetTextCursorPosition(uint32_t &_rX_U32, uint32_t &_rY_U32);
BOFERR SetTextWindowTitle(const std::string &_rTitle_S);
BOFERR Clear(CONIO_CLEAR _ClearType_E);
/*
create 24 bit color
position cursor
erase terminal
erale line
*/

BOFERR Printf(const char *_pFormat_c, ...);
void PrintfAtColor(CONIO_TEXT_COLOR _ForeColor_E, uint32_t _x_U32, uint32_t _y_U32, const char *_pFormat_c, ...);

BOFERR Reset();
BofConio(const BOF_CONIO_PARAM &_rBofConioParam_X);
virtual ~BofConio();
// delete copy and move constructors and assign operators
BofConio(BofConio const &) = delete; // Copy construct
BofConio(BofConio &&) = delete; // Move construct
BofConio &operator=(BofConio const &) = delete; // Copy assign
BofConio &operator=(BofConio &&) = delete; // Move assign
*/
static bool S_Initialize(const BOF_CONIO_PARAM &_rBofConioParam_X);
static bool S_Shutdown();
static uint32_t S_KbHit(uint32_t _TimeOutInMs_U32);
static uint32_t S_GetCh(bool _OnlyModifier_B);
static std::string S_KeyToString(uint32_t _Key_U32);

static BOFERR S_Readline(const std::string &_rPrompt_S, std::string &_rInputLine_S);

static BOFERR S_SetTextAttribute(uint32_t _TextAttributeFlag_U32); // Use CONIO_TEXT_ATTRIBUTE_FLAG enum ored value
static BOFERR S_SetForegroundTextColor(CONIO_TEXT_COLOR _ForegroundColor_E);
static BOFERR S_SetBackgroundTextColor(CONIO_TEXT_COLOR _BackgroundColor_E);
static BOFERR S_SetForegroundTextColor(BOF_RGBA<uint8_t> _ForegroundColor_E);
static BOFERR S_SetBackgroundTextColor(BOF_RGBA<uint8_t> _BackgroundColor_X);

static BOFERR S_SetTextCursorState(CONIO_TEXT_CURSOR_STATE _CursorState_E);
static BOFERR S_SetTextCursorPosition(uint32_t _x_U32, uint32_t _y_U32);
static BOFERR S_GetTextCursorPosition(uint32_t &_rX_U32, uint32_t &_rY_U32);
static BOFERR S_SetTextWindowTitle(const char *_pTitle_c);
static BOFERR S_Clear(CONIO_CLEAR _ClearType_E);

static BOFERR S_PrintLine(const char *_pFormat_c, ...);
static void S_PrintLineColorAt(CONIO_TEXT_COLOR _ForegroundColor_E, uint32_t _x_U32, uint32_t _y_U32, const char *_pFormat_c, ...);

private:
uint32_t GetChAfterOneChar(bool _OnlyModifier_B, char _FirstChar_c);

CONIO_TEXT_COLOR mForeColor_E = CONIO_TEXT_COLOR::CONIO_TEXT_COLOR_BLACK;
static uint32_t S_GetChAfterOneChar(bool _OnlyModifier_B, char _FirstChar_c);

static BOF_CONIO_PARAM S_mBofConioParam_X;
static uint32_t S_mConsoleWidth_U32;
static uint32_t S_mConsoleHeight_U32;
static char S_mpTextForeAttribute_c[0x40];
static char S_mpTextBackAttribute_c[0x40];
static char S_mpTextAttribute_c[0x40];
};

END_BOF_NAMESPACE()
14 changes: 11 additions & 3 deletions lib/include/bofstd/bofshell.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ ls(true,false,false)
#include <map>

BEGIN_BOF_NAMESPACE()
enum class SHELL_OUTPUT_STREAM
{
SHELL_OUTPUT_STREAM_INPUT,
SHELL_OUTPUT_STREAM_OUTPUT,
SHELL_OUTPUT_STREAM_ERROR,
SHELL_OUTPUT_STREAM_MAX
};

using BOF_SHELL_INPUT_CMD = std::function<BOFERR(const std::string &_rPrompt_S, std::string &_rShellCmd_S)>;
using BOF_SHELL_OUTPUT_RES = std::function<BOFERR(bool _Error_B, const std::string &_rShellRes_S)>;
using BOF_SHELL_OUTPUT_RES = std::function<BOFERR(SHELL_OUTPUT_STREAM _OutputStream_E, const std::string &_rShellRes_S)>;
using BOF_SHELL_CMD_CALLBACK = std::function<BOFERR(void *_pArg, std::string &_rShellRes_S)>; // const std::vector<std::string> &_rCmdArgCollection) > ;

struct BOF_SHELL_CMD
Expand Down Expand Up @@ -162,6 +169,7 @@ class BOFSTD_EXPORT BofShell
BOFERR ShellCmdArg(void *_pArg, std::string &_rShellResult_S);
std::string mEchoText_S;
BOFERR ShellEcho(void *_pArg, std::string &_rShellResult_S);
BOFERR ShellGetCh(void *_pArg, std::string &_rShellResult_S);
BOFERR ShellDoYouWantToContinue(void *_pArg, std::string &_rShellResult_S);
BOF_SHELL_SPAWN_PARAM mSpawnParam_X;
BOFERR ShellSpawn(void *_pArg, std::string &_rShellResult_S);
Expand All @@ -179,6 +187,7 @@ class BOFSTD_EXPORT BofShell

class BOFSTD_EXPORT BofShellConsole
{

private:
BOF_SHELL_CONSOLE_PARAM mShellConsoleParam_X;

Expand All @@ -187,9 +196,8 @@ class BOFSTD_EXPORT BofShellConsole
virtual ~BofShellConsole();

BOFERR InputStream(const std::string &_rPrompt_S, std::string &_rShellCmd_S);
BOFERR OutputStream(bool _Error_B, const std::string &_rShellRes_S);
BOFERR OutputStream(SHELL_OUTPUT_STREAM _ShellOutputStream_E, const std::string &_rShellRes_S);

private:
std::unique_ptr<BOF::BofConio> mpuConio = nullptr;
};
END_BOF_NAMESPACE()
Loading

0 comments on commit d252b63

Please sign in to comment.