FACT++  1.0
Shell Class Reference

Implementation of a console based user shell with an input and output window. More...

#include <Shell.h>

+ Inheritance diagram for Shell:
+ Collaboration diagram for Shell:

Public Member Functions

 Shell (const char *prgname)
 
 ~Shell ()
 Ends the ncurses environment by calling endwin(). More...
 
bool Resize (int h)
 
void ShowHide (int v)
 
void Refresh ()
 
bool PrintCommands ()
 
bool PrintGeneralHelp ()
 
bool PrintKeyBindings ()
 
bool Process (const std::string &str)
 
void Lock ()
 
void Run (const char *="")
 
void Unlock ()
 
WindowLogGetStreamOut ()
 
WindowLogGetStreamIn ()
 
const WindowLogGetStreamOut () const
 
const WindowLogGetStreamIn () const
 
- Public Member Functions inherited from ReadlineWindow
 ReadlineWindow (const char *prgname)
 
void SetWindow (WINDOW *w)
 
void SetColorPrompt (int col)
 
void RewindCursor () const
 
- Public Member Functions inherited from Readline
 Readline (const char *prgname)
 
virtual ~Readline ()
 
void BindKeySequence (const char *seq, int(*func)(int, int))
 
std::string GetName () const
 
void AddToHistory (const std::string &str, int skip=2)
 
std::vector< const char * > GetHistory () const
 Return a list of pointer to the history contents. More...
 
void SetMaxSize (int lines)
 
void UpdatePrompt (const std::string &prompt) const
 
void UpdatePrompt () const
 
virtual bool PreProcess (const std::string &str)
 
virtual std::string GetUpdatePrompt () const
 
virtual bool PromptEOF (std::string &str)
 
virtual std::string Prompt (const std::string &prompt)
 
virtual bool ExecuteShellCommand (const std::string &cmd)
 
int Execute (const std::string &fname, const std::map< std::string, std::string > &args=std::map< std::string, std::string >())
 
bool IsStopped () const
 
void ProcessLine (const std::string &str)
 
void SetLabel (int l)
 
int GetLine () const
 
virtual std::string GetLinePrompt () const
 
int GetCols () const
 Get the number of cols readline assumes the screen size to be. More...
 
int GetRows () const
 Get the number of rows readline assumes the screen size to be. More...
 

Protected Attributes

WindowLog win
 pointer to our glocal object to get the static member functions into scope More...
 
WindowLog wout
 
- Protected Attributes inherited from Readline
const std::vector< std::string > * fCompletion
 Pointer to a list of possible matched for auto-completion. More...
 

Static Protected Attributes

static ShellThis = 0
 
- Static Protected Attributes inherited from Readline
static ReadlineThis = 0
 
static std::string fScript
 

Private Member Functions

void HandleResize ()
 Non static member function called by HandleResize. More...
 
void CreateWindows (WINDOW *w[3], int all=true)
 Helper for the constructor and window resizing to create the windows and panels. More...
 
void Shutdown (const char *)
 

Static Private Member Functions

static int rl_proc_F1 (int cnt, int key)
 Key binding for F1. Toggles upper panel by calling ShowHide(-1) More...
 
static int rl_scroll_top (int cnt, int key)
 
static int rl_scroll_bot (int cnt, int key)
 
static int rl_top_inc (int cnt, int key)
 
static int rl_top_dec (int cnt, int key)
 
static int rl_top_resize (int cnt, int key)
 
static void HandleResizeImp (int dummy)
 Signal handler for SIGWINCH, calls HandleResize. More...
 

Private Attributes

PANELfPanelIn
 
PANELfPanelFrame
 Pointer to the panel for the input stream. More...
 
PANELfPanelOut
 Pointer to the panel for the frame around the output. More...
 
int fPanelHeight
 Pointer to the panel for the output stream. More...
 
int fIsVisible
 Space between the bottom of the screen and the output panel. More...
 
int fLine
 Flag whether the output panel is visible or not (for toggle operations) More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Readline
static bool RedirectionWrapper (std::ostream &out, bool(*function)())
 
static bool DumpVariables ()
 
static bool DumpFunctions ()
 
static bool DumpFunmap ()
 
static bool DumpHistory ()
 
static bool ClearHistory ()
 
static void Stop ()
 
static void StopScript ()
 
static bool IsScriptStopped ()
 
static int GetScriptDepth ()
 
static void SetScriptDepth (unsigned int d)
 
static void SetExternalInput (const std::string &inp)
 
static std::string GetScript ()
 
static std::string GetExternalInput ()
 
static char * Compare (const std::string &str, const std::string &txt)
 
static char ** CompletionMatches (const char *text, char *(*func)(const char *, int))
 
static FILE * SetStreamOut (FILE *f)
 
static FILE * SetStreamIn (FILE *f)
 
static std::string GetPrompt ()
 
static std::string GetBuffer ()
 
static int GetAbsCursor ()
 return strlen(rl_display_prompt) + rl_point More...
 
static int GetCursor ()
 return rl_point (the current cursor position within the line buffer) More...
 
static int GetBufferLength ()
 
static int GetLineLength ()
 return the length of the prompt plus the length of the line buffer More...
 
static void Resize ()
 
static void Resize (int w, int h)
 
static ReadlineInstance ()
 
static void StaticPushHistory (const std::string &fname)
 
static std::string StaticPrompt (const std::string &prompt)
 
static void StaticPopHistory (const std::string &fname)
 
- Protected Member Functions inherited from ReadlineWindow
void Startup ()
 Color index in which the prompt should be displayed. More...
 
void Redisplay ()
 
void EventHook (bool=false)
 
void CompletionDisplay (char **matches, int num, int max)
 
- Protected Member Functions inherited from Readline
virtual int Getc (FILE *)
 The non static implementations of the callback funtions above. More...
 
virtual char * Complete (const char *text, int state)
 Functions dealing with auto completion. More...
 
virtual char ** Completion (const char *text, int start, int end)
 
void SetCompletion (const std::vector< std::string > *v)
 
char ** Complete (const std::vector< std::string > &v, const char *text)
 
virtual void SetSection (int)
 
virtual void PrintReadlineError (const std::string &str)
 

Detailed Description

Implementation of a console based user shell with an input and output window.

Shell is based on the ReadlineWindow class. It creates two windows (panels) using ncurses which are used for input and output. The output window panel is displayed on top of the input panel, but can be hidden for example by pressing F1.

The idea is that continous messages like logging messages do not interfere with the input area, although one still has both diplayed in the same console window.

To get a list of the command and functions supported by Shell type 'h' or 'help' at a command line prompt.

The usage is quite simple. Instantiate an object of Shell with the programname as an argument. For its meaning see the base class documentation Readline::Readline(). The created input- and output- stream can be accessed through GetStreamIn() and GetStreamOut() whihc are both ostreams, one redirected to the input window and the other one redirected to the output window. Especially, GetStreamIn() should not be used while the Readline prompt is in progress, but can for example be used to display errors about what was entered.

The recommanded way of usage is:

static Shell shell("myprog"); // readline will read the myprog.his history file
while (1)
{
string txt = shell.Prompt("prompt> ");
if (txt=="quit)
break;
// ... do something ...
shell.AddHistory(txt);
}
// On destruction redline will write the current history to the file
// By declaring the Shell static the correct terminal is restored even
// the program got killed (not if killed with SIGABRT)

If for some reason the terminal is not correctly restored type (maybe blindly) reset in your console. This should restor everything back to normal.

References

Todo:
  • Introduce the possibility to scroll in both windows
  • Add redisplay functionality for both panels if the console was resized

Definition at line 12 of file Shell.h.


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