2022-05-18 23:12:52 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: ConsoleTTY.hpp
|
|
|
|
Date: 2022-5-11
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Aurora::Console::ConsoleTTY
|
|
|
|
{
|
|
|
|
inline bool gTTYConsoleEnabled {};
|
|
|
|
|
2022-08-07 22:35:13 +00:00
|
|
|
void EnterScrollMode();
|
|
|
|
void LeaveScrollMode();
|
|
|
|
|
2023-02-17 19:42:30 +00:00
|
|
|
struct TTYConsole;
|
|
|
|
|
|
|
|
struct TTYConsoleField
|
|
|
|
{
|
|
|
|
TTYConsoleField(TTYConsole *pParent);
|
|
|
|
|
|
|
|
AuString inputField;
|
|
|
|
int noncanonicalCursorPos {};
|
|
|
|
int noncanonicalCursorPosInBytes {};
|
|
|
|
|
|
|
|
void AddString(const AuString &str);
|
|
|
|
bool Backspace();
|
|
|
|
void DirectionalArrow(int iDirection, bool bShift, bool bControl);
|
|
|
|
void Clear();
|
|
|
|
void WriteBuffered(TTYConsole *pConsole, AuPair<AuUInt32, AuUInt32> pos);
|
|
|
|
|
|
|
|
AuOptionalEx<int> highlightStartInBytes {};
|
|
|
|
AuOptionalEx<int> highlightStart {};
|
|
|
|
AuOptionalEx<int> highlightEndInBytes {};
|
|
|
|
AuOptionalEx<int> highlightEndInPos {};
|
|
|
|
int highlightChars {};
|
|
|
|
|
|
|
|
void DoUnselectTick();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void Left();
|
|
|
|
void Right();
|
|
|
|
|
|
|
|
TTYConsole *pParent;
|
|
|
|
bool bIsSelecting {};
|
|
|
|
int iLastDirection {};
|
|
|
|
};
|
|
|
|
|
2022-05-18 23:12:52 +00:00
|
|
|
struct TTYConsole : ITTYConsole
|
|
|
|
{
|
2023-02-17 19:42:30 +00:00
|
|
|
TTYConsole();
|
|
|
|
|
2022-08-02 04:52:17 +00:00
|
|
|
void BufferMessage(const AuConsole::ConsoleMessage &msg) override;
|
2022-12-14 20:08:52 +00:00
|
|
|
void BufferMessage(const AuConsole::ConsoleMessage &msg, const AuString &input) ;
|
|
|
|
|
|
|
|
//
|
2022-05-18 23:12:52 +00:00
|
|
|
void Pump();
|
2022-06-06 21:34:26 +00:00
|
|
|
void PumpHistory();
|
2022-05-18 23:12:52 +00:00
|
|
|
|
|
|
|
bool RedrawWindow();
|
|
|
|
void OnEnter();
|
|
|
|
void Init();
|
|
|
|
void Deinit();
|
|
|
|
|
|
|
|
bool Start() override;
|
|
|
|
void End() override;
|
2023-12-08 18:25:50 +00:00
|
|
|
|
2022-08-07 22:35:13 +00:00
|
|
|
bool uxModeFlipped {};
|
2023-12-08 18:25:50 +00:00
|
|
|
AuUInt64 uxFlipTime {};
|
2022-08-07 22:35:13 +00:00
|
|
|
|
2023-02-17 19:42:30 +00:00
|
|
|
inline void SignalRedraw()
|
|
|
|
{
|
|
|
|
this->bTriggerRedraw = true;
|
|
|
|
}
|
|
|
|
|
2022-05-18 23:12:52 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
bool UTF8();
|
|
|
|
|
|
|
|
void SetHintStrings(const AuList<AuPair<AuString /*autocompletion*/, AuList<AuString/* secondary hint*/>>> &hints);
|
|
|
|
|
|
|
|
void RedrawBorders();
|
|
|
|
void RedrawLogBox();
|
|
|
|
void RedrawHintLine();
|
|
|
|
void RedrawInput(bool clear);
|
|
|
|
void RedrawBanner();
|
|
|
|
|
|
|
|
void BlankLogBox();
|
|
|
|
|
|
|
|
void SetInitialCursorPos();
|
|
|
|
|
|
|
|
bool CheckRedraw();
|
|
|
|
void PostRedraw(bool first);
|
|
|
|
|
|
|
|
bool RegenerateBuffer(bool resChanged, bool &redrawBox);
|
|
|
|
|
2022-08-02 04:52:17 +00:00
|
|
|
bool NoncanonicalMode() override;
|
2022-05-18 23:12:52 +00:00
|
|
|
void NoncanonicalTick();
|
|
|
|
void NoncanonicalSetCursor();
|
|
|
|
void NoncanonicalOnString(const AuString &input);
|
|
|
|
void NoncanonicalOnBackspace();
|
|
|
|
void NoncanonicalOnEnter();
|
2023-02-17 19:42:30 +00:00
|
|
|
void NoncanonicalOnLeft(bool bShift, bool bControl);
|
|
|
|
void NoncanonicalOnRight(bool bShift, bool bControl);
|
2022-05-18 23:12:52 +00:00
|
|
|
|
2022-05-24 05:58:06 +00:00
|
|
|
void NoncanonicalOnPageUp();
|
|
|
|
void NoncanonicalOnPageDown();
|
|
|
|
|
2022-05-18 23:12:52 +00:00
|
|
|
void Scroll(int delta);
|
|
|
|
|
|
|
|
void NoncanonicalOnMenuLeft();
|
|
|
|
void NoncanonicalOnMenuRight();
|
|
|
|
void NoncanonicalOnMenuUp();
|
|
|
|
void NoncanonicalOnMenuDown();
|
|
|
|
|
2022-05-19 03:21:34 +00:00
|
|
|
void NoncanonicalOnHistoryUp();
|
|
|
|
void NoncanonicalOnHistoryDown();
|
|
|
|
|
2022-06-06 21:34:26 +00:00
|
|
|
void HistorySetFile();
|
|
|
|
AuString HistoryGetFile();
|
|
|
|
void HistoryAppendChanges();
|
|
|
|
void HistoryLoad();
|
2022-05-19 03:32:23 +00:00
|
|
|
void HistoryUpdateCursor();
|
|
|
|
|
2022-06-06 21:34:26 +00:00
|
|
|
AuString historyFileName;
|
|
|
|
|
2023-02-17 19:42:30 +00:00
|
|
|
TTYConsoleField inputField;
|
|
|
|
//int noncanonicalCursorPos {};
|
|
|
|
//int noncanonicalCursorPosInBytes {};
|
2022-05-18 23:12:52 +00:00
|
|
|
|
|
|
|
virtual int GetBannerLines();
|
|
|
|
virtual int GetLogBoxLines();
|
|
|
|
virtual int GetHintLines();
|
|
|
|
virtual int GetTextInputLines();
|
|
|
|
|
|
|
|
virtual bool GetLogBoxHintBorder();
|
|
|
|
virtual bool GetBottomBorder() override;
|
|
|
|
|
|
|
|
AuPair<AuUInt32, AuUInt32> GetLogBoxStart();
|
|
|
|
|
|
|
|
AuPair<AuUInt32, AuUInt32> GetHintLine();
|
|
|
|
AuPair<AuUInt32, AuUInt32> GetInputCursor();
|
|
|
|
AuPair<AuUInt32, AuUInt32> GetInitialInputLine();
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool GetBannerFootBorder() override;
|
|
|
|
|
|
|
|
virtual ETTYAlign SetTitleAlignment(ETTYAlign newValue) override;
|
|
|
|
virtual ETTYAlign GetLogBoxTitleAlignment() override;
|
|
|
|
virtual ETTYAlign SetLogBoxTitleAlignment(ETTYAlign newValue) override;
|
|
|
|
|
|
|
|
virtual bool GetTopBorder() override;
|
|
|
|
virtual bool GetLeftBorder() override;
|
|
|
|
virtual bool GetRightBorder() override;
|
|
|
|
|
|
|
|
virtual ETTYAlign GetTitleAlignment() override;
|
|
|
|
|
|
|
|
virtual ETTYAlign GetHeaderAlignment() override;
|
|
|
|
virtual ETTYAlign GetSubheaderAlignment() override;
|
|
|
|
|
|
|
|
virtual AuString GetHeaderBorderTitle() override;
|
|
|
|
virtual AuString GetLogBoxBorderTitle() override;
|
|
|
|
|
|
|
|
virtual AuString GetHeader() override;
|
|
|
|
virtual AuString GetSubHeader() override;
|
|
|
|
|
|
|
|
virtual ETTYAlign SetHeaderAlignment(ETTYAlign newValue) override;
|
|
|
|
virtual ETTYAlign SetSubheaderAlignment(ETTYAlign newValue) override;
|
|
|
|
|
|
|
|
virtual AuString SetHeaderBorderTitle(const AuString &newValue) override;
|
|
|
|
virtual AuString SetLogBoxBorderTitle(const AuString &newValue) override;
|
|
|
|
|
|
|
|
virtual AuString SetHeader(const AuString &newValue) override;
|
|
|
|
virtual AuString SetSubHeader(const AuString &newValue) override;
|
|
|
|
|
|
|
|
virtual bool SetTopBorder(bool newValue) override;
|
|
|
|
virtual bool SetLeftBorder(bool newValue) override;
|
|
|
|
virtual bool SetRightBorder(bool newValue) override;
|
|
|
|
|
2022-06-11 23:01:27 +00:00
|
|
|
virtual AuUInt8 SetPaddingLeftOfLog(AuUInt8 newValue) override;
|
|
|
|
virtual AuUInt8 SetPaddingRightOfLog(AuUInt8 newValue) override;
|
|
|
|
virtual AuUInt8 SetPaddingLeftOfInput(AuUInt8 newValue) override;
|
|
|
|
virtual AuUInt8 SetPaddingTopOfInput(AuUInt8 newValue) override;
|
|
|
|
virtual AuUInt8 SetPaddingTopOfHint(AuUInt8 newValue) override;
|
|
|
|
virtual AuUInt8 SetPaddingTopOfHeader(AuUInt8 newValue) override;
|
|
|
|
virtual AuUInt8 SetPaddingMidOfHeader(AuUInt8 newValue) override;
|
|
|
|
virtual AuUInt8 SetPaddingBottomOfSubheader(AuUInt8 newValue) override;
|
|
|
|
|
|
|
|
virtual AuUInt8 GetPaddingLeftOfLog() override;
|
|
|
|
virtual AuUInt8 GetPaddingRightOfLog() override;
|
|
|
|
virtual AuUInt8 GetPaddingLeftOfInput() override;
|
|
|
|
virtual AuUInt8 GetPaddingTopOfInput() override;
|
|
|
|
virtual AuUInt8 GetPaddingTopOfHint() override;
|
|
|
|
virtual AuUInt8 GetPaddingTopOfHeader() override;
|
|
|
|
virtual AuUInt8 GetPaddingMidOfHeader() override;
|
|
|
|
virtual AuUInt8 GetPaddingBottomOfSubheader() override;
|
|
|
|
|
|
|
|
|
2022-06-14 17:33:34 +00:00
|
|
|
virtual AuUInt8 SetPaddingHeadOfLog(AuUInt8 newValue) override;
|
|
|
|
virtual AuUInt8 SetPaddingTopOfLog(AuUInt8 newValue) override;
|
2022-06-11 23:01:27 +00:00
|
|
|
virtual AuUInt8 GetPaddingHeadOfLog() override;
|
|
|
|
virtual AuUInt8 GetPaddingTopOfLog() override;
|
|
|
|
|
2022-12-14 01:35:18 +00:00
|
|
|
void WriteBufferedEx(AuPair<AuUInt32, AuUInt32> pos, EAnsiColor color, const AuString &in);
|
2022-05-18 23:12:52 +00:00
|
|
|
void WriteBuffered(AuPair<AuUInt32, AuUInt32> pos, const AuString &in);
|
|
|
|
void WriteLine(int Y, const AuString &in);
|
|
|
|
void BlankLine(int Y, bool borders = true);
|
|
|
|
void BlankBordersLine(int Y);
|
|
|
|
|
|
|
|
bool PermitDoubleBuffering();
|
2022-08-07 22:35:13 +00:00
|
|
|
|
2022-05-18 23:12:52 +00:00
|
|
|
private:
|
|
|
|
|
2023-02-17 19:42:30 +00:00
|
|
|
friend struct TTYConsoleField;
|
2022-05-18 23:12:52 +00:00
|
|
|
void DebugLogArea();
|
|
|
|
|
|
|
|
AuList<AuPair<AuString /*autocompletion*/, AuList<AuString/* secondary hint*/>>> hintStrings;
|
|
|
|
|
|
|
|
void Flush();
|
|
|
|
|
|
|
|
int currentWidth {};
|
|
|
|
int currentHeight {};
|
|
|
|
|
|
|
|
int oldWidth {};
|
|
|
|
int oldHeight {};
|
|
|
|
|
2022-05-19 03:21:34 +00:00
|
|
|
int iHistoryPos {-1};
|
2022-06-06 21:34:26 +00:00
|
|
|
int iHistoryWritePos {0};
|
2022-05-19 03:21:34 +00:00
|
|
|
AuList<AuString> history;
|
|
|
|
|
2023-12-26 21:01:29 +00:00
|
|
|
AuRWLock historyLock;
|
2022-06-06 21:34:26 +00:00
|
|
|
|
|
|
|
|
2023-12-26 21:01:29 +00:00
|
|
|
AuMutex messageLock;
|
2022-05-18 23:12:52 +00:00
|
|
|
AuList<AuConsole::ConsoleMessage> messagesPending;
|
|
|
|
|
|
|
|
AuList<AuConsole::ConsoleMessage> messages;
|
2022-12-14 01:35:18 +00:00
|
|
|
AuList<AuPair<AuConsole::EAnsiColor, AuString>> screenBuffer;
|
2022-05-18 23:12:52 +00:00
|
|
|
bool bScreenBufferDoesntMap {};
|
|
|
|
|
|
|
|
int iScrollPos { -1 };
|
|
|
|
|
|
|
|
AuPair<AuUInt32, AuUInt32> cursorPos;
|
|
|
|
|
|
|
|
|
|
|
|
struct AlignedString
|
|
|
|
{
|
|
|
|
AuString str;
|
2022-08-02 04:52:17 +00:00
|
|
|
ETTYAlign align {};
|
2022-05-18 23:12:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AuString tempMemory;
|
|
|
|
|
|
|
|
const AuString &Stringify(const AuString &referenceLine, const AlignedString &string, bool spacing, bool brackets, bool extraPadding);
|
|
|
|
|
|
|
|
|
|
|
|
AlignedString header;
|
|
|
|
AlignedString subheader;
|
|
|
|
|
|
|
|
AlignedString headerTitle;
|
|
|
|
AlignedString logTitle;
|
|
|
|
|
|
|
|
|
|
|
|
bool bTriggerRedraw {};
|
|
|
|
|
|
|
|
bool bRightBorder {true};
|
|
|
|
bool bLeftBorder {true};
|
|
|
|
bool bTopBorder {true};
|
|
|
|
|
2022-08-02 04:52:17 +00:00
|
|
|
bool bShouldShowBorders {};
|
|
|
|
bool bShowingBorders {};
|
2022-05-18 23:12:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool IsShowingHintLine();
|
|
|
|
bool bIsShowingHintLine;
|
|
|
|
|
2022-05-23 15:10:19 +00:00
|
|
|
bool IsWin32UxMode();
|
|
|
|
void UXModeFlip();
|
|
|
|
void UXModeStart();
|
|
|
|
|
2023-02-17 19:42:30 +00:00
|
|
|
//AuString inputField {};
|
2022-05-18 23:12:52 +00:00
|
|
|
|
|
|
|
AuUInt32 lastInputHash {};
|
|
|
|
AuUInt32 lastBorderHash {};
|
|
|
|
|
|
|
|
int leftPadding {1};
|
|
|
|
int rightPadding {1};
|
|
|
|
|
|
|
|
int leftLogPadding {1};
|
|
|
|
int rightLogPadding {1};
|
2022-06-11 23:01:27 +00:00
|
|
|
int topLogPadding {0}; // extra padding, if displaying header ...
|
|
|
|
int topLogPaddingExtra {1}; // this is backwards ...
|
2022-05-18 23:12:52 +00:00
|
|
|
|
|
|
|
int leftInputPadding {0};
|
|
|
|
int topInputPadding {0};
|
|
|
|
|
|
|
|
int topHintPadding {0};
|
|
|
|
int topHeaderPadding {0};
|
|
|
|
int midHeaderPadding {0};
|
|
|
|
|
|
|
|
int bottomSubHeaderPadding {0};
|
|
|
|
|
|
|
|
AuUInt32 oldCP {};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline TTYConsole gTTYConsole;
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
void Pump();
|
|
|
|
void Exit();
|
|
|
|
void OnEnter();
|
|
|
|
void WriteTTYOut(const AuConsole::ConsoleMessage &msg);
|
2022-12-14 20:08:52 +00:00
|
|
|
void WriteTTYOut(const AuConsole::ConsoleMessage &msg, const AuString &input);
|
2022-05-18 23:12:52 +00:00
|
|
|
AUKN_SYM AuSPtr<ITTYConsole> GetTTYConsole();
|
2022-11-30 11:11:18 +00:00
|
|
|
void PumpForce();
|
2022-05-18 23:12:52 +00:00
|
|
|
}
|