FabGL
ESP32 Display Controller and Graphics Library
fabgl::LineEditor Class Reference

LineEditor is a single-line / multiple-rows editor which uses the Terminal object as input and output. More...

#include <terminal.h>

Public Member Functions

 LineEditor (Terminal *terminal)
 Object constructor. More...
 
char const * edit (int maxLength=0)
 Reads user input and return the inserted line. More...
 
char const * get ()
 Gets current content. More...
 
void setInsertMode (bool value)
 Sets insert mode state. More...
 
void setText (char const *text, bool moveCursor=true)
 Sets initial text. More...
 
void setText (char const *text, int length, bool moveCursor=true)
 Sets initial text specifying length. More...
 
void typeText (char const *text)
 Simulates user typing. More...
 

Public Attributes

Delegate< int * > onCarriageReturn
 A delegate called whenever carriage return has been pressed. More...
 
Delegate< int * > onChar
 A delegate called whenever a character has been received. More...
 
Delegate< int * > onRead
 Read character delegate. More...
 
Delegate< LineEditorSpecialCharonSpecialChar
 A delegate called whenever a special character has been pressed. More...
 
Delegate< int > onWrite
 Write character delegate. More...
 

Detailed Description

LineEditor is a single-line / multiple-rows editor which uses the Terminal object as input and output.

The editor supports following control keys:

  • Left and Right Arrow keys: Move cursor left and right, even across rows
  • CTRL + Left and Right Arrow keys: Move cursor at the begining of prevous or next word
  • Home key: Move cursor at the beginning of the line
  • End key: Move cursor at the end of the line
  • Delete key: Delete character at cursor
  • Insert key: Enable/disable insert mode
  • Backspace key: Delete character at left of the cursor
  • Enter/Return: Move cursor at the beginning of the next line and exit editor

Example:

Terminal.write("> ");  // show prompt
LineEditor ed(&Terminal);
char * txt = ed.get();
Terminal.printf("Your input is: %s\r\n", txt);
Examples:
SSD1306_OLED/128x64/NetworkTerminal/NetworkTerminal.ino, SSD1306_OLED/128x64/RTClock/RTClock.ino, and VGA/NetworkTerminal/NetworkTerminal.ino.

Constructor & Destructor Documentation

◆ LineEditor()

fabgl::LineEditor::LineEditor ( Terminal terminal)

Object constructor.

Parameters
terminalPointer to Terminal object

Member Function Documentation

◆ edit()

char const * fabgl::LineEditor::edit ( int  maxLength = 0)

Reads user input and return the inserted line.

This method returns when user press ENTER/RETURN.

Parameters
maxLengthMaximum amount of character the user can type. 0 = unlimited.
Returns
Returns what user typed and edited.

◆ get()

char const* fabgl::LineEditor::get ( )
inline

Gets current content.

Returns
Returns what user typed.

◆ setInsertMode()

void fabgl::LineEditor::setInsertMode ( bool  value)
inline

Sets insert mode state.

Parameters
valueIf True insert mode is enabled (default), if False insert mode is disabled.

◆ setText() [1/2]

void fabgl::LineEditor::setText ( char const *  text,
bool  moveCursor = true 
)

Sets initial text.

Call this method if the input must have some text already inserted. This method can be also called during editing to replace current text.

Parameters
textInitial text.
moveCursorIf true the cursor is moved at the end of initial text.

Example:

LineEditor ed(&Terminal);
ed.setText("Initial text ");
char * txt = ed.get();
Terminal.printf("Your input is: %s\r\n", txt);

◆ setText() [2/2]

void fabgl::LineEditor::setText ( char const *  text,
int  length,
bool  moveCursor = true 
)

Sets initial text specifying length.

Call this method if the input must have some text already inserted. This method can be also called during editing to replace current text.

Parameters
textInitial text.
lengthText length
moveCursorIf true the cursor is moved at the end of initial text.

◆ typeText()

void fabgl::LineEditor::typeText ( char const *  text)

Simulates user typing.

This method simulates user typing. Unlike setText, this methods allows control characters and generates onChar events.

Parameters
textText to type

Member Data Documentation

◆ onCarriageReturn

Delegate<int *> fabgl::LineEditor::onCarriageReturn

A delegate called whenever carriage return has been pressed.

First parameter specifies the action to perform when ENTER has been pressed:

0 = new line and end editing (default) 1 = end editing 2 = continue editing

◆ onChar

Delegate<int *> fabgl::LineEditor::onChar

A delegate called whenever a character has been received.

First parameter represents a pointer to the receiving character code.

◆ onRead

Delegate<int *> fabgl::LineEditor::onRead

Read character delegate.

This delegate is called whenever a character needs to be read, and no Terminal has been specified. The delegate should block until a character is received.

First parameter represents a pointer to the receiving character code.

◆ onSpecialChar

Delegate<LineEditorSpecialChar> fabgl::LineEditor::onSpecialChar

A delegate called whenever a special character has been pressed.

First parameter receives the special key pressed. The type is LineEditorSpecialChar.

◆ onWrite

Delegate<int> fabgl::LineEditor::onWrite

Write character delegate.

This delegate is called whenever a character needs to be written, and no Terminal has been specified.

First parameter represents the character code to send.


The documentation for this class was generated from the following files: