PAASS
Software suite to Acquire and Analyze Data from Pixie16
Terminal Class Reference

#include <CTerminal.h>

Collaboration diagram for Terminal:

Public Member Functions

 Terminal ()
 
 ~Terminal ()
 
void Initialize ()
 Initialize the terminal interface. More...
 
bool SetLogFile (std::string logFileName)
 Specify the log file to append. More...
 
void SetDebug (bool debug=true)
 Initalize terminal debug mode. More...
 
void AddStatusWindow (unsigned short numLines=1)
 Initalizes a status window under the input temrinal. More...
 
void SetStatus (std::string status, unsigned short line=0)
 Set the status message. More...
 
void ClearStatus (unsigned short line=0)
 Clear the status line. More...
 
void AppendStatus (std::string status, unsigned short line=0)
 Append some text to the status line. More...
 
void EnableTabComplete (bool enable=true)
 Enable tab auto complete functionlity. More...
 
void TabComplete (const std::string &input_, const std::vector< std::string > &possibilities_)
 Handle tab complete functionality. More...
 
void EnableTimeout (float timeout=0.5)
 Enable a timeout while waiting fro a command. More...
 
void SetCommandHistory (std::string filename, bool overwrite=false)
 Set the command filename for storing previous commands. More...
 
void SetPrompt (const char *input_)
 Set the command prompt. More...
 
void putch (const char input_)
 Force a character to the output screen. More...
 
void pause (bool &flag)
 Disrupt ncurses while boolean is true. More...
 
void flush ()
 Dump all text in the stream to the output screen. More...
 
void PrintCommand (const std::string &cmd_)
 Print a command to the terminal output. More...
 
std::string GetCommand (std::string &args, const int &prev_cmd_return_=0)
 Wait for the user to input a command. More...
 
void Close ()
 Close the window and restore control to the terminal. More...
 

Private Member Functions

void refresh_ ()
 Refresh the terminal. More...
 
void resize_ ()
 Resize the terminal. More...
 
void scroll_ (int numLines)
 Scroll the output by a specified number of lines. More...
 
void update_cursor_ ()
 Update the positions of the physical and logical cursors. More...
 
void clear_ ()
 Clear the command prompt output. More...
 
void in_char_ (const char input_)
 Force a character to the input screen. More...
 
void in_print_ (const char *input_)
 Force a character string to the input screen. More...
 
void init_colors_ ()
 Initialize terminal colors. More...
 
bool LoadCommandFile (const char *filename_)
 Read commands from a command script. More...
 
bool LoadCommandHistory (bool overwrite)
 Load a list of previous commands from a file. More...
 
bool SaveCommandHistory ()
 Save previous commands to a file. More...
 
void print (WINDOW *window, std::string input_)
 Force a character string to the output screen. More...
 
void split_commands (const std::string &input_, std::deque< std::string > &cmds)
 Split a string into multiple commands separated by a ';'. More...
 

Private Attributes

std::map< std::string, int > attrMap
 
std::streambuf * pbuf
 
std::streambuf * original
 
std::stringstream stream
 
std::string historyFilename_
 
WINDOW * main
 
WINDOW * output_window
 
WINDOW * input_window
 
WINDOW * status_window
 
CommandHolder commands
 
std::string cmd
 
bool init
 
int cursX
 
int cursY
 
int offset
 
int _winSizeX
 
int _winSizeY
 
int _statusWindowSize
 
std::vector< std::string > statusStr
 
std::deque< std::string > cmd_queue
 
std::string prompt
 The prompt string. More...
 
bool enableTabComplete
 The tab complete flag. More...
 
float commandTimeout_
 Time in seconds to wait for command. More...
 
bool insertMode_
 
short tabCount
 
bool debug_
 Flag indicating verbose output is enabled. More...
 
std::ofstream logFile
 
bool from_script
 
bool prompt_user
 Set to true if a command is read from a script instead of user input. More...
 
int _scrollbackBufferSize
 Set to true if the user should be prompted with a yes/no question. More...
 
int _scrollPosition
 Number of lines scrolled back. More...
 

Detailed Description

Definition at line 111 of file CTerminal.h.

Constructor & Destructor Documentation

§ Terminal()

Terminal::Terminal ( )

Definition at line 518 of file CTerminal.cpp.

§ ~Terminal()

Terminal::~Terminal ( )

Definition at line 541 of file CTerminal.cpp.

Here is the call graph for this function:

Member Function Documentation

§ AddStatusWindow()

void Terminal::AddStatusWindow ( unsigned short  numLines = 1)

Initalizes a status window under the input temrinal.

Creates a status window and the refreshes the output. Takes an optional number of lines, defaulted to 1.

Parameters
[in]numLinesVertical size of status window.

Definition at line 307 of file CTerminal.cpp.

Here is the caller graph for this function:

§ AppendStatus()

void Terminal::AppendStatus ( std::string  status,
unsigned short  line = 0 
)

Append some text to the status line.

Definition at line 333 of file CTerminal.cpp.

§ clear_()

void Terminal::clear_ ( )
private

Clear the command prompt output.

Definition at line 292 of file CTerminal.cpp.

Here is the caller graph for this function:

§ ClearStatus()

void Terminal::ClearStatus ( unsigned short  line = 0)

Clear the status line.

Definition at line 328 of file CTerminal.cpp.

§ Close()

void Terminal::Close ( )

Close the window and restore control to the terminal.

Definition at line 1093 of file CTerminal.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

§ EnableTabComplete()

void Terminal::EnableTabComplete ( bool  enable = true)

Enable tab auto complete functionlity.

By enabling tab autocomplete the current typed command is returned via GetCommand() with a trailing tab character.

Parameters
[in]enableState of tab complete.

Definition at line 717 of file CTerminal.cpp.

Here is the caller graph for this function:

§ EnableTimeout()

void Terminal::EnableTimeout ( float  timeout = 0.5)

Enable a timeout while waiting fro a command.

By enabling the timeout the GetCommand() routine returns after a set timesout period has passed. The current typed text is stored for the next GetCommand call.

Parameters
[in]timeoutThe amount of time to wait before timeout in seconds defaults to 0.5 s.

Definition at line 728 of file CTerminal.cpp.

Here is the caller graph for this function:

§ flush()

void Terminal::flush ( )

Dump all text in the stream to the output screen.

Definition at line 690 of file CTerminal.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

§ GetCommand()

std::string Terminal::GetCommand ( std::string &  args,
const int &  prev_cmd_return_ = 0 
)

Wait for the user to input a command.

Definition at line 822 of file CTerminal.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

§ in_char_()

void Terminal::in_char_ ( const char  input_)
private

Force a character to the input screen.

Definition at line 339 of file CTerminal.cpp.

Here is the caller graph for this function:

§ in_print_()

void Terminal::in_print_ ( const char *  input_)
private

Force a character string to the input screen.

Definition at line 349 of file CTerminal.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

§ init_colors_()

void Terminal::init_colors_ ( )
private

Initialize terminal colors.

Definition at line 356 of file CTerminal.cpp.

Here is the caller graph for this function:

§ Initialize()

void Terminal::Initialize ( )

Initialize the terminal interface.

Definition at line 548 of file CTerminal.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

§ LoadCommandFile()

bool Terminal::LoadCommandFile ( const char *  filename_)
private

Read commands from a command script.

Read commands from a command script. param[in] filename_ : The relative path to the file containing CTerminal commands. Returns true if the file opened successfully and false otherwise.

An example CTerminal script is given below. Comments are denoted by a #.

Tell the user something about this script.

.echo This script is intended to be used to test the script reader (i.e. '.cmd').

Issue the user a prompt asking if they would like to continue.

If the user types anything other than 'yes' or 'y', the script will abort.

.prompt WARNING! This script will do something. Are you sure you wish to proceed?

help # Do something just to test that the script is working.

Definition at line 407 of file CTerminal.cpp.

Here is the caller graph for this function:

§ LoadCommandHistory()

bool Terminal::LoadCommandHistory ( bool  overwrite)
private

Load a list of previous commands from a file.

Definition at line 447 of file CTerminal.cpp.

Here is the caller graph for this function:

§ pause()

void Terminal::pause ( bool &  flag)

Disrupt ncurses while boolean is true.

Definition at line 246 of file CTerminal.cpp.

Here is the caller graph for this function:

§ print()

void Terminal::print ( WINDOW *  window,
std::string  input_ 
)
private

Force a character string to the output screen.

Definition at line 658 of file CTerminal.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

§ PrintCommand()

void Terminal::PrintCommand ( const std::string &  cmd_)

Print a command to the terminal output.

Definition at line 814 of file CTerminal.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

§ putch()

void Terminal::putch ( const char  input_)

Force a character to the output screen.

Definition at line 652 of file CTerminal.cpp.

Here is the call graph for this function:

§ refresh_()

void Terminal::refresh_ ( )
private

Refresh the terminal.

Refreshes the specified window or if none specified all windows.

Parameters
[in]windowThe pointer to the window to be updated.

Definition at line 259 of file CTerminal.cpp.

Here is the caller graph for this function:

§ resize_()

void Terminal::resize_ ( )
private

Resize the terminal.

Definition at line 216 of file CTerminal.cpp.

§ SaveCommandHistory()

bool Terminal::SaveCommandHistory ( )
private

Save previous commands to a file.

Definition at line 493 of file CTerminal.cpp.

Here is the caller graph for this function:

§ scroll_()

void Terminal::scroll_ ( int  numLines)
private

Scroll the output by a specified number of lines.

Definition at line 274 of file CTerminal.cpp.

Here is the caller graph for this function:

§ SetCommandHistory()

void Terminal::SetCommandHistory ( std::string  filename,
bool  overwrite = false 
)

Set the command filename for storing previous commands.

This command will clear all current commands from the history if overwrite is set to true.

Parameters
[in]filenameThe filename for the command history.
[in]overwriteFlag indicating the current commands should be forgotten.

Definition at line 607 of file CTerminal.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

§ SetDebug()

void Terminal::SetDebug ( bool  debug = true)
inline

Initalize terminal debug mode.

Definition at line 202 of file CTerminal.h.

Here is the call graph for this function:
Here is the caller graph for this function:

§ SetLogFile()

bool Terminal::SetLogFile ( std::string  logFileName)

Specify the log file to append.

Definition at line 703 of file CTerminal.cpp.

Here is the caller graph for this function:

§ SetPrompt()

void Terminal::SetPrompt ( const char *  input_)

Set the command prompt.

Definition at line 614 of file CTerminal.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

§ SetStatus()

void Terminal::SetStatus ( std::string  status,
unsigned short  line = 0 
)

Set the status message.

Definition at line 323 of file CTerminal.cpp.

Here is the caller graph for this function:

§ split_commands()

void Terminal::split_commands ( const std::string &  input_,
std::deque< std::string > &  cmds 
)
private

Split a string into multiple commands separated by a ';'.

Split strings into multiple commands separated by ';'.

Parameters
[in]input_The string to be parsed.
[out]cmdsThe vector to populate with sub-commands.

Definition at line 1156 of file CTerminal.cpp.

Here is the caller graph for this function:

§ TabComplete()

void Terminal::TabComplete ( const std::string &  input_,
const std::vector< std::string > &  possibilities_ 
)

Handle tab complete functionality.

Take the list of matching tab complete values and output resulting tab completion. If the list is empty nothing happens, if a unique value is given the command is completed. If there are multiple matches the common part of the matches is determined and printed to the input. If there is no common part of the matches and the tab key has been pressed twice the list of matches is printed for the user to decide.

Parameters
[in]input_The string to complete.
[in]possibilities_A vector of strings of possible values.

Definition at line 740 of file CTerminal.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

§ update_cursor_()

void Terminal::update_cursor_ ( )
private

Update the positions of the physical and logical cursors.

Definition at line 285 of file CTerminal.cpp.

Here is the caller graph for this function:

Field Documentation

§ _scrollbackBufferSize

int Terminal::_scrollbackBufferSize
private

Set to true if the user should be prompted with a yes/no question.

Size of the scroll back buffer in lines.

Definition at line 146 of file CTerminal.h.

§ _scrollPosition

int Terminal::_scrollPosition
private

Number of lines scrolled back.

Definition at line 149 of file CTerminal.h.

§ _statusWindowSize

int Terminal::_statusWindowSize
private

Definition at line 127 of file CTerminal.h.

§ _winSizeX

int Terminal::_winSizeX
private

Definition at line 126 of file CTerminal.h.

§ _winSizeY

int Terminal::_winSizeY
private

Definition at line 126 of file CTerminal.h.

§ attrMap

std::map< std::string, int > Terminal::attrMap
private

Definition at line 113 of file CTerminal.h.

§ cmd

std::string Terminal::cmd
private

Definition at line 122 of file CTerminal.h.

§ cmd_queue

std::deque<std::string> Terminal::cmd_queue
private

Definition at line 129 of file CTerminal.h.

§ commands

CommandHolder Terminal::commands
private

Definition at line 121 of file CTerminal.h.

§ commandTimeout_

float Terminal::commandTimeout_
private

Time in seconds to wait for command.

Definition at line 134 of file CTerminal.h.

§ cursX

int Terminal::cursX
private

Definition at line 124 of file CTerminal.h.

§ cursY

int Terminal::cursY
private

Definition at line 124 of file CTerminal.h.

§ debug_

bool Terminal::debug_
private

Flag indicating verbose output is enabled.

Definition at line 138 of file CTerminal.h.

§ enableTabComplete

bool Terminal::enableTabComplete
private

The tab complete flag.

Definition at line 133 of file CTerminal.h.

§ from_script

bool Terminal::from_script
private

Definition at line 142 of file CTerminal.h.

§ historyFilename_

std::string Terminal::historyFilename_
private

Definition at line 116 of file CTerminal.h.

§ init

bool Terminal::init
private

Definition at line 123 of file CTerminal.h.

§ input_window

WINDOW* Terminal::input_window
private

Definition at line 119 of file CTerminal.h.

§ insertMode_

bool Terminal::insertMode_
private

Definition at line 135 of file CTerminal.h.

§ logFile

std::ofstream Terminal::logFile
private

Definition at line 140 of file CTerminal.h.

§ main

WINDOW* Terminal::main
private

Definition at line 117 of file CTerminal.h.

§ offset

int Terminal::offset
private

Definition at line 125 of file CTerminal.h.

§ original

std::streambuf * Terminal::original
private

Definition at line 114 of file CTerminal.h.

§ output_window

WINDOW* Terminal::output_window
private

Definition at line 118 of file CTerminal.h.

§ pbuf

std::streambuf* Terminal::pbuf
private

Definition at line 114 of file CTerminal.h.

§ prompt

std::string Terminal::prompt
private

The prompt string.

The queue of commands read from a command script.

Definition at line 131 of file CTerminal.h.

§ prompt_user

bool Terminal::prompt_user
private

Set to true if a command is read from a script instead of user input.

Definition at line 143 of file CTerminal.h.

§ status_window

WINDOW* Terminal::status_window
private

Definition at line 120 of file CTerminal.h.

§ statusStr

std::vector<std::string> Terminal::statusStr
private

Definition at line 128 of file CTerminal.h.

§ stream

std::stringstream Terminal::stream
private

Definition at line 115 of file CTerminal.h.

§ tabCount

short Terminal::tabCount
private

Definition at line 137 of file CTerminal.h.


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