244 lines
7.0 KiB
C++
244 lines
7.0 KiB
C++
/***
|
|
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 {};
|
|
|
|
struct TTYConsole : ITTYConsole
|
|
{
|
|
void BufferMessage(const AuConsole::ConsoleMessage &msg);
|
|
void Pump();
|
|
|
|
bool RedrawWindow();
|
|
void OnEnter();
|
|
void Init();
|
|
void Deinit();
|
|
|
|
bool Start() override;
|
|
void End() override;
|
|
|
|
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);
|
|
|
|
bool NoncanonicalMode();
|
|
void NoncanonicalTick();
|
|
void NoncanonicalSetCursor();
|
|
void NoncanonicalOnString(const AuString &input);
|
|
void NoncanonicalOnBackspace();
|
|
void NoncanonicalOnEnter();
|
|
void NoncanonicalOnLeft();
|
|
void NoncanonicalOnRight();
|
|
|
|
void Scroll(int delta);
|
|
|
|
void NoncanonicalOnMenuLeft();
|
|
void NoncanonicalOnMenuRight();
|
|
void NoncanonicalOnMenuUp();
|
|
void NoncanonicalOnMenuDown();
|
|
|
|
void NoncanonicalOnHistoryUp();
|
|
void NoncanonicalOnHistoryDown();
|
|
|
|
void HistoryUpdateCursor();
|
|
|
|
int noncanonicalCursorPos {};
|
|
int noncanonicalCursorPosInBytes {};
|
|
|
|
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;
|
|
|
|
AuUInt8 SetPaddingLeftOfLog(AuUInt8 newValue) override;
|
|
AuUInt8 SetPaddingRightOfLog(AuUInt8 newValue) override;
|
|
AuUInt8 SetPaddingLeftOfInput(AuUInt8 newValue) override;
|
|
AuUInt8 SetPaddingTopOfInput(AuUInt8 newValue) override;
|
|
AuUInt8 SetPaddingTopOfHint(AuUInt8 newValue) override;
|
|
AuUInt8 SetPaddingTopOfHeader(AuUInt8 newValue) override;
|
|
AuUInt8 SetPaddingMidOfHeader(AuUInt8 newValue) override;
|
|
AuUInt8 SetPaddingBottomOfSubheader(AuUInt8 newValue) override;
|
|
|
|
|
|
AuUInt8 GetPaddingLeftOfLog() override;
|
|
AuUInt8 GetPaddingRightOfLog() override;
|
|
AuUInt8 GetPaddingLeftOfInput() override;
|
|
AuUInt8 GetPaddingTopOfInput() override;
|
|
AuUInt8 GetPaddingTopOfHint() override;
|
|
AuUInt8 GetPaddingTopOfHeader() override;
|
|
AuUInt8 GetPaddingMidOfHeader() override;
|
|
AuUInt8 GetPaddingBottomOfSubheader() override;
|
|
|
|
|
|
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();
|
|
private:
|
|
|
|
void DebugLogArea();
|
|
|
|
AuList<AuPair<AuString /*autocompletion*/, AuList<AuString/* secondary hint*/>>> hintStrings;
|
|
|
|
void Flush();
|
|
|
|
int currentWidth {};
|
|
int currentHeight {};
|
|
|
|
int oldWidth {};
|
|
int oldHeight {};
|
|
|
|
|
|
int iHistoryPos {-1};
|
|
AuList<AuString> history;
|
|
|
|
AuThreadPrimitives::SpinLock messageLock;
|
|
AuList<AuConsole::ConsoleMessage> messagesPending;
|
|
|
|
AuList<AuConsole::ConsoleMessage> messages;
|
|
AuList<AuString> screenBuffer;
|
|
bool bScreenBufferDoesntMap {};
|
|
|
|
int iScrollPos { -1 };
|
|
|
|
AuPair<AuUInt32, AuUInt32> cursorPos;
|
|
|
|
|
|
struct AlignedString
|
|
{
|
|
AuString str;
|
|
ETTYAlign align;
|
|
};
|
|
|
|
AuString tempMemory;
|
|
|
|
AuUInt32 GuessWidth(const AuString &referenceLine);
|
|
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};
|
|
|
|
bool bShouldShowBorders;
|
|
bool bShowingBorders;
|
|
|
|
|
|
bool IsShowingHintLine();
|
|
bool bIsShowingHintLine;
|
|
|
|
AuString inputField {};
|
|
|
|
AuUInt32 lastInputHash {};
|
|
AuUInt32 lastBorderHash {};
|
|
|
|
int leftPadding {1};
|
|
int rightPadding {1};
|
|
|
|
int leftLogPadding {1};
|
|
int rightLogPadding {1};
|
|
int topLogPadding {0}; // extra padding, if displaying header
|
|
int topLogPaddingExtra {1}; // this is backwards
|
|
|
|
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);
|
|
AUKN_SYM AuSPtr<ITTYConsole> GetTTYConsole();
|
|
} |