46#include "freertos/FreeRTOS.h"
47#include "freertos/task.h"
48#include "freertos/timers.h"
49#include "freertos/semphr.h"
715struct TerminalCursorState {
716 TerminalCursorState * next;
720 bool cursorPastLastCol;
722 GlyphOptions glyphOptions;
723 uint8_t characterSetIndex;
724 uint8_t characterSet[4];
761 uint8_t characterSetIndex;
764 uint8_t characterSet[4];
766 Color foregroundColor;
767 Color backgroundColor;
773 bool cursorPastLastCol;
780 int scrollingRegionTop;
781 int scrollingRegionDown;
786 bool cursorBlinkingEnabled;
808 KeypadMode keypadMode;
814 int conformanceLevel;
821 bool allow132ColumnMode;
823 bool reverseWraparoundMode;
826 bool backarrowKeyMode;
832 bool VT52GraphicsMode;
835 int allowFabGLSequences;
842 virtual size_t write(uint8_t) = 0;
843 virtual size_t write(
const uint8_t * buffer,
size_t size);
844 size_t write(
const char *str) {
847 return write((
const uint8_t *)str, strlen(str));
849 void printf(
const char * format, ...) {
851 va_start(ap, format);
852 int size = vsnprintf(
nullptr, 0, format, ap) + 1;
855 va_start(ap, format);
857 auto l = vsnprintf(buf, size, format, ap);
858 write((uint8_t*)buf, l);
864struct Stream :
public Print{
1136 void logFmt(
const char * format, ...);
1137 void log(
const char * txt);
1150 void loadFont(FontInfo
const * font);
1195 void clear(
bool moveCursor =
true);
1203 void flush(
bool waitVSync);
1280 int read(
int timeOutMS);
1292 bool waitFor(
int value,
int timeOutMS = -1);
1330 size_t write(
const uint8_t * buffer,
size_t size);
1341 size_t write(uint8_t c);
1350 void send(uint8_t c);
1357 void send(
char const * str);
1453 bool CTSStatus() {
return m_ctsPin != GPIO_UNUSED ? gpio_get_level(m_ctsPin) == 0 :
false; }
1535 void clearMap(uint32_t * map);
1538 void freeTabStops();
1539 void freeGlyphsMap();
1541 void set132ColumnMode(
bool value);
1545 void move(
int offset);
1546 void setCursorPos(
int X,
int Y);
1547 int getAbsoluteRow(
int Y);
1549 void int_setBackgroundColor(
Color color);
1550 void int_setForegroundColor(
Color color);
1552 void syncDisplayController();
1556 void setTabStop(
int column,
bool set);
1557 void resetTabStops();
1561 void scrollDownAt(
int startingRow);
1563 void scrollUpAt(
int startingRow);
1564 void setScrollingRegion(
int top,
int down,
bool resetCursorPos =
true);
1565 void updateCanvasScrollingRegion();
1568 void saveCursorState();
1569 void restoreCursorState();
1570 void clearSavedCursorStates();
1572 void erase(
int X1,
int Y1,
int X2,
int Y2, uint8_t c,
bool maintainDoubleWidth,
bool selective);
1574 void consumeInputQueue();
1578 void consumeFabGLSeq();
1579 void consumeFabGLGraphicsSeq();
1580 void consumeCSIQUOT(
int * params,
int paramsCount);
1581 void consumeCSISPC(
int * params,
int paramsCount);
1582 uint8_t consumeParamsAndGetCode(
int * params,
int * paramsCount,
bool * questionMarkFound);
1583 void consumeDECPrivateModes(
int const * params,
int paramsCount, uint8_t c);
1585 void execSGRParameters(
int const * params,
int paramsCount);
1586 void consumeESCVT52();
1588 void execCtrlCode(uint8_t c);
1590 static void charsConsumerTask(
void * pvParameters);
1591 static void keyboardReaderTask(
void * pvParameters);
1593 static void blinkTimerFunc(TimerHandle_t xTimer);
1595 bool enableBlinkingText(
bool value);
1597 bool int_enableCursor(
bool value);
1599 static void IRAM_ATTR uart_isr(
void *arg);
1601 uint8_t getNextCode(
bool processCtrlCodes);
1603 bool setChar(uint8_t c);
1606 void insertAt(
int column,
int row,
int count);
1607 void deleteAt(
int column,
int row,
int count);
1609 bool multilineInsertChar(
int charsToMove);
1610 void multilineDeleteChar(
int charsToMove);
1612 void reverseVideo(
bool value);
1615 void refresh(
int X,
int Y);
1616 void refresh(
int X1,
int Y1,
int X2,
int Y2);
1618 void setLineDoubleWidth(
int row,
int value);
1619 int getCharWidthAt(
int row);
1620 int getColumnsAt(
int row);
1622 void useAlternateScreenBuffer(
bool value);
1627 void sendCursorKeyCode(uint8_t c);
1628 void sendKeypadCursorKeyCode(uint8_t applicationCode,
const char * numericCode);
1633 void convHandleTranslation(uint8_t c,
bool fromISR);
1634 void convSendCtrl(ConvCtrl ctrl,
bool fromISR);
1635 void convQueue(
const char * str,
bool fromISR);
1638 bool addToInputQueue(uint8_t c,
bool fromISR);
1639 bool insertToInputQueue(uint8_t c,
bool fromISR);
1641 void write(uint8_t c,
bool fromISR);
1645 void uartCheckInputQueueForFlowControl();
1647 void enableFabGLSequences(
bool value);
1649 void int_setTerminalType(
TermType value);
1650 void int_setTerminalType(TermInfo
const * value);
1652 void sound(
int waveform,
int frequency,
int duration,
int volume);
1654 uint8_t extGetByteParam();
1655 int extGetIntParam();
1656 void extGetCmdParam(
char * cmd);
1660 uint32_t makeGlyphItem(uint8_t c,
GlyphOptions * glyphOptions,
Color * newForegroundColor);
1663 static Terminal * s_activeTerminal;
1668 bool m_bitmappedDisplayController;
1672 Stream * m_logStream;
1676 GlyphsBuffer m_glyphsBuffer;
1679 uint32_t * m_alternateMap;
1682 bool m_alternateScreenBuffer;
1685 int m_alternateCursorX;
1686 int m_alternateCursorY;
1687 int m_alternateScrollingRegionTop;
1688 int m_alternateScrollingRegionDown;
1689 bool m_alternateCursorBlinkingEnabled;
1696 EmuState m_emuState;
1698 Color m_defaultForegroundColor;
1699 Color m_defaultBackgroundColor;
1702 bool m_prevCursorEnabled;
1703 bool m_prevBlinkingTextEnabled;
1706 TaskHandle_t m_charsConsumerTaskHandle;
1709 TaskHandle_t m_keyboardReaderTaskHandle;
1712 volatile bool m_cursorState;
1715 TimerHandle_t m_blinkTimer;
1718 volatile SemaphoreHandle_t m_mutex;
1720 volatile bool m_blinkingTextVisible;
1721 volatile bool m_blinkingTextEnabled;
1723 volatile int m_columns;
1724 volatile int m_rows;
1734 HardwareSerial * m_serialPort;
1740 volatile bool m_uart;
1743 volatile bool m_uartRXEnabled;
1746 volatile QueueHandle_t m_inputQueue;
1749 QueueHandle_t m_outputQueue;
1752 TerminalCursorState * m_savedCursorStateList;
1755 bool m_resetRequested;
1758 volatile bool m_sentXOFF;
1759 volatile bool m_recvXOFF;
1762 gpio_num_t m_rtsPin;
1763 gpio_num_t m_ctsPin;
1769 uint8_t m_convMatchedCount;
1770 uint8_t m_convMatchedChars[EmuTerminalMaxChars];
1771 TermInfoVideoConv
const * m_convMatchedItem;
1772 TermInfo
const * m_termInfo;
1775 volatile uint8_t m_lastWrittenChar;
1778 volatile bool m_writeDetectedFabGLSeq;
1788 bool m_coloredAttributesMaintainStyle;
1789 int m_coloredAttributesMask;
1790 Color m_coloredAttributesColor[4];
1997 void waitFor(
int value);
1998 void write(uint8_t c);
1999 void write(
char const * str);
2072 void setText(
char const * text,
bool moveCursor =
true);
2084 void setText(
char const * text,
int length,
bool moveCursor =
true);
2104 char const *
edit(
int maxLength = 0);
2111 char const *
get() {
return m_text; }
2172 void setLength(
int newLength);
2174 void write(uint8_t c);
2177 void performCursorUp();
2178 void performCursorDown();
2179 void performCursorLeft();
2180 void performCursorRight();
2181 void performCursorHome();
2182 void performCursorEnd();
2183 void performDeleteRight();
2184 void performDeleteLeft();
This file contains fabgl::Canvas definition.
Represents the base abstract class for all display controllers.
A class with a set of drawing methods.
The PS2 Keyboard controller class.
char const * edit(int maxLength=0)
Reads user input and return the inserted line.
Delegate< LineEditorSpecialChar > onSpecialChar
A delegate called whenever a special character has been pressed.
void setInsertMode(bool value)
Sets insert mode state.
void setText(char const *text, bool moveCursor=true)
Sets initial text.
LineEditor(Terminal *terminal)
Object constructor.
Delegate< int * > onChar
A delegate called whenever a character has been received.
Delegate< int * > onRead
Read character delegate.
void typeText(char const *text)
Simulates user typing.
Delegate< int > onWrite
Write character delegate.
Delegate< int * > onCarriageReturn
A delegate called whenever carriage return has been pressed.
char const * get()
Gets current content.
LineEditor is a single-line / multiple-rows editor which uses the Terminal object as input and output...
SoundGenerator handles audio output.
void connectLocally()
Permits using of terminal locally.
TermInfo const & terminalType()
Determines current terminal type.
void setRTSStatus(bool value)
Sets RTS signal status.
void pollSerialPort()
Pools the serial port for incoming data.
int getRows()
Returns the number of lines.
bool waitFor(int value, int timeOutMS=-1)
Wait for a specific code from keyboard, discarding all previous codes.
void clear(bool moveCursor=true)
Clears the screen.
Delegate< VirtualKey *, bool > onVirtualKey
Delegate called whenever a new virtual key is received from keyboard.
int available()
Gets the number of codes available in the keyboard queue.
void setLogStream(Stream &stream)
Sets the stream where to output debugging logs.
void disableSerialPortRX(bool value)
Disables/Enables serial port RX.
bool RTSStatus()
Reports current RTS signal status.
int getColumns()
Returns the number of columns.
void loadFont(FontInfo const *font)
Sets the font to use.
static int keyboardReaderTaskStackSize
Stack size of the task that reads keys from keyboard and send ANSI/VT codes to output stream in Termi...
size_t write(const uint8_t *buffer, size_t size)
Sends specified number of codes to the display.
void localInsert(uint8_t c)
Injects keys into the keyboard queue.
void localWrite(uint8_t c)
Injects keys into the keyboard queue.
Canvas * canvas()
Gets associated canvas object.
void deactivate()
Deactivates this terminal.
Keyboard * keyboard()
Gets associated keyboard object.
static int inputQueueSize
Number of characters the terminal can "write" without pause (increase if you have loss of characters ...
int availableForWrite()
Determines number of codes that the display input queue can still accept.
int peek()
Reads a code from the keyboard without advancing to the next one.
void connectSerialPort(HardwareSerial &serialPort, bool autoXONXOFF=true)
Connects a remote host using the specified serial port.
bool isActive()
Determines if this terminal is active or not.
void disconnectLocally()
Avoids using of terminal locally.
int read()
Reads codes from keyboard.
void activate(TerminalTransition transition=TerminalTransition::None)
Activates this terminal for input and output.
void enableCursor(bool value)
Enables or disables cursor.
static int inputConsumerTaskStackSize
Stack size of the task that processes Terminal input stream.
void end()
Finalizes the terminal.
Delegate< VirtualKeyItem * > onVirtualKeyItem
Delegate called whenever a new virtual key is received from keyboard, including shift states.
SoundGenerator * soundGenerator()
Gets embedded sound generator.
void send(uint8_t c)
Like localWrite() but sends also to serial port if connected.
bool CTSStatus()
Reports current CTS signal status.
bool flowControl()
Checks whether host can receive data.
void flush()
Waits for all codes sent to the display has been processed.
void setColorForAttribute(CharStyle attribute, Color color, bool maintainStyle)
Selects a color for the specified attribute.
void setTerminalType(TermType value)
Sets the terminal type to emulate.
bool XOFFStatus()
Reports whether TX is active.
void setBackgroundColor(Color color, bool setAsDefault=true)
Sets the background color.
bool begin(BaseDisplayController *displayController, int maxColumns=-1, int maxRows=-1, Keyboard *keyboard=nullptr)
Initializes the terminal.
Delegate< char const * > onUserSequence
Delegate called whenever a new user sequence has been received.
void setForegroundColor(Color color, bool setAsDefault=true)
Sets the foreground color.
void unRead(uint8_t c)
Injects keys into the keyboard queue.
void cursorRight(int count)
Moves cursor to the right.
void disableFabGLSequences()
Disables FabGL specific sequences.
void cursorLeft(int count)
Moves cursor to the left.
void multilineDeleteChar(int charsToMove)
Deletes a character moving specified amount of characters to the left.
bool isVKDown(VirtualKey vk)
Checks if a virtual key is currently down.
bool multilineInsertChar(int charsToMove)
Inserts a blank character and move specified amount of characters to the right.
int getCursorCol()
Gets current cursor column.
bool setChar(uint8_t c)
Sets a raw character at current cursor position.
void setTerminal(Terminal *terminal=nullptr)
Sets destination terminal.
Delegate< int * > onRead
Read character delegate.
int getCursorRow()
Gets current cursor row.
Delegate< int > onWrite
Write character delegate.
void getCursorPos(int *col, int *row)
Gets current cursor position.
void enableCursor(bool value)
Enables/disables cursor.
void setBackgroundColor(Color value)
Sets background color.
TerminalController(Terminal *terminal=nullptr)
Object constructor.
void clear()
Clears screen.
void setCursorPos(int col, int row)
Sets current cursor position.
void setTerminalType(TermType value)
Sets the terminal type to emulate.
void setForegroundColor(Color value)
Sets foreground color.
void setCharStyle(CharStyle style, bool enabled)
Enables or disables specified character style.
TerminalController allows direct controlling of the Terminal object without using escape sequences.
An ANSI-VT100 compatible display terminal.
GlyphOptions & Underline(bool value)
Helper method to set or reset underlined.
GlyphOptions & Italic(bool value)
Helper method to set or reset italic.
GlyphOptions & Bold(bool value)
Helper method to set or reset bold.
GlyphOptions & Blank(uint8_t value)
Helper method to set or reset foreground and background swapping.
This file contains FabGL library configuration settings, like number of supported colors,...
TerminalTransition
This enum defines terminal transition effect.
CharStyle
This enum defines a character style.
TermType
This enum defines supported terminals.
LineEditorSpecialChar
Special character specified in on values from LineEditor::onSpecialChar delegate.
Color
This enum defines named colors.
VirtualKey
Represents each possible real or derived (SHIFT + real) key.
FlowControl
This enum defines various serial port flow control methods.
This file contains fabgl::Keyboard definition.
This file contains all classes related to FabGL Sound System.
Specifies general paint options.
A struct which contains a virtual key, key state and associated scan code.
This file contains terminal emulation definitions.
Specifies various glyph painting options.