Rudiments
Public Member Functions | List of all members
prompt Class Reference

Inherits object.

Public Member Functions

 prompt ()
 
virtual ~prompt ()
 
void setHistoryFile (const char *filename)
 
const char * getHistoryFile ()
 
void setMaxHistoryLines (uint32_t lines)
 
uint32_t getMaxHistoryLines ()
 
void setMaxHistoryQueue (uint32_t queue)
 
uint32_t getMaxHistoryQueue ()
 
void setPrompt (const char *prompt)
 
const char * getPrompt ()
 
char * read ()
 
void flushHistory ()
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

The prompt class provides methods for displaying a prompt and accepting user input.

Input history and tab-completion are supported if the underlying system supports them. On Unix-like systems, this is enabled by the libedit library. On many Windows systems, this is provided by the OS.

Constructor & Destructor Documentation

◆ prompt()

prompt::prompt ( )

Creates an instance of the prompt class.

◆ ~prompt()

virtual prompt::~prompt ( )
virtual

Deletes this instance of the prompt class.

Calls flushHistory().

Member Function Documentation

◆ flushHistory()

void prompt::flushHistory ( )

Flushes all lines of input history queued in memory to the file configured by setHistoryFile().

◆ getHistoryFile()

const char* prompt::getHistoryFile ( )

Returns the name of the file used to store the input history.

◆ getMaxHistoryLines()

uint32_t prompt::getMaxHistoryLines ( )

Returns the maximum number of lines to store in the input history file.

◆ getMaxHistoryQueue()

uint32_t prompt::getMaxHistoryQueue ( )

Returns the maximum number of lines of input history that will be queued in memory before flushHistory() will be called automatically.

◆ getPrompt()

const char* prompt::getPrompt ( )

Returns the prompt that will be displayed during the next call to read().

◆ read()

char* prompt::read ( )

Displays the prompt configured by setPrompt(), reads a line from standard input, queues the line in memory, and calls flushHistory() if the queue has grown beyond the number of lines configured by getMaxHistoryQueue().

Returns the line that was read from standard input without the trailing carriage return and/or line feed.

Returns an empty string if return/enter is hit by itself.

Returns NULL if ctrl-D was hit.

Note that return value is allocated internally and returned. The calling program must free the buffer.

◆ setHistoryFile()

void prompt::setHistoryFile ( const char *  filename)

Sets the name of the file used to store the input histroy. On Unix-like systems, this is traditionally a dot-file in the user's home directory.

Does nothing if rudiments is compiled without support for libedit.

◆ setMaxHistoryLines()

void prompt::setMaxHistoryLines ( uint32_t  lines)

Sets the maximum number of lines of input history that will be stored in the input history file. The history file will be truncated to this number of lines when flushHistory() is called, either explicitly or implicitly.

Defaults to 1024.

If set to 0 then the input history file will not be truncated during calls to flushHistory().

Does nothing if rudiments is compiled without support for libedit.

◆ setMaxHistoryQueue()

void prompt::setMaxHistoryQueue ( uint32_t  queue)

Sets the maximum number of lines of input history that will be queued in memory before flushHistory() is called automatically.

Defaults to 1024.

If set to 0 then an unlimited number of lines will be queued, and will only be flushed when flushHistory() is called manually, or when the instance of the class is deleted.

Does nothing if rudiments is compiled without support for libedit.

◆ setPrompt()

void prompt::setPrompt ( const char *  prompt)

Sets the prompt that will be displayed during the next call to read().