LineBufferBase Class Reference

Class to enable buffering of a single line of text, with simple editing. More...

#include <LineBuffer.h>

Inheritance diagram for LineBufferBase:

Public Types

enum class  Action {
  none , clear , echo , backspace ,
  submit
}
 Returned from processKey method directing caller. More...
 

Public Member Functions

 LineBufferBase (char *buffer, uint16_t size)
 
Action process (Stream &input, ReadWriteStream &output)
 Process all available data from input More...
 
Action processKey (char key, ReadWriteStream *output=nullptr)
 Process a keypress in a consistent manner for console editing. More...
 
char addChar (char c)
 Add a character to the buffer. More...
 
void clear ()
 Clear contents of buffer. More...
 
 operator bool () const
 
 operator String () const
 Copy buffer contents into a String. More...
 
char * getBuffer ()
 Get the text, nul-terminated. More...
 
unsigned getLength () const
 Get number of characters in the text line. More...
 
bool startsWith (const char *text) const
 Check for matching text at start of line, case-sensitive. More...
 
bool contains (const char *text) const
 Check for matching text anywhere in line, case-sensitive. More...
 
bool backspace ()
 Remove last character from buffer. More...
 
size_t printTo (Print &p) const
 

Detailed Description

Class to enable buffering of a single line of text, with simple editing.

Note
We define this as a template class for simplicity, no need for separate buffer memory management

Member Enumeration Documentation

◆ Action

Returned from processKey method directing caller.

Enumerator
none 

Do nothing, ignore the key.

clear 

Line is cleared: typically perform a carriage return.

echo 

Key should be echoed.

backspace 

Perform backspace edit, e.g. output "\b \b".

submit 

User hit return, process line and clear it.

Constructor & Destructor Documentation

◆ LineBufferBase()

LineBufferBase::LineBufferBase ( char *  buffer,
uint16_t  size 
)
inline

Member Function Documentation

◆ addChar()

char LineBufferBase::addChar ( char  c)

Add a character to the buffer.

Return values
charCharacter added to buffer, '\0' if ignored, '
' if line is complete

◆ backspace()

bool LineBufferBase::backspace ( )

Remove last character from buffer.

Return values
booltrue if character was removed, false if buffer is empty

◆ clear()

void LineBufferBase::clear ( )
inline

Clear contents of buffer.

◆ contains()

bool LineBufferBase::contains ( const char *  text) const

Check for matching text anywhere in line, case-sensitive.

Parameters
text
Return values
booltrue if match found

◆ getBuffer()

char* LineBufferBase::getBuffer ( )
inline

Get the text, nul-terminated.

◆ getLength()

unsigned LineBufferBase::getLength ( ) const
inline

Get number of characters in the text line.

◆ operator bool()

LineBufferBase::operator bool ( ) const
inlineexplicit

◆ operator String()

LineBufferBase::operator String ( ) const
inlineexplicit

Copy buffer contents into a String.

Return values
String

◆ printTo()

size_t LineBufferBase::printTo ( Print p) const
inline

◆ process()

Action LineBufferBase::process ( Stream input,
ReadWriteStream output 
)

Process all available data from input

Parameters
inputSource of keystrokes
outputThe output stream (e.g. Serial) for echoing
Return values
Actionnone, clear or submit

◆ processKey()

Action LineBufferBase::processKey ( char  key,
ReadWriteStream output = nullptr 
)

Process a keypress in a consistent manner for console editing.

Parameters
keyThe keypress value
outputThe output stream (e.g. Serial) for echoing, if required
Return values
Action

◆ startsWith()

bool LineBufferBase::startsWith ( const char *  text) const

Check for matching text at start of line, case-sensitive.

Parameters
text
Return values
booltrue if match found

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