amath  1.8.5
Simple command line calculator
ConsoleBase Class Referenceabstract

Abstract base class encapsulating console logic. More...

#include <console.h>

Inheritance diagram for ConsoleBase:

Public Member Functions

 ConsoleBase (const char *prompt)
 
virtual ~ConsoleBase ()
 
const char * GetName ()
 
virtual bool Open ()
 
virtual void Close ()
 
virtual void Start ()=0
 
virtual void Exit ()=0
 
virtual void Clear ()
 
virtual void ShowHelp ()
 
virtual void ShowAbout ()
 
virtual void ShowLicense ()
 
virtual void ShowVersion ()
 
virtual void SetPrompt (const char *string)
 
virtual void WriteString (const char *string)=0
 
virtual bool SetAnsiMode (bool value)
 
virtual void ResetConsole ()
 

Protected Member Functions

virtual void StartMessage ()
 
void Prompt ()
 
const char * GetVersionText ()
 
const char * GetCompilerText ()
 

Protected Attributes

char * prompt
 
bool ansiMode
 

Private Member Functions

void AnsiItalics ()
 
void AnsiBold ()
 

Detailed Description

Abstract base class encapsulating console logic.

Definition at line 43 of file console.h.

Constructor & Destructor Documentation

◆ ConsoleBase()

ConsoleBase::ConsoleBase ( const char *  prompt)
explicit

Definition at line 75 of file console.cpp.

References AllocAndCopy(), and prompt.

76 {
77  AllocAndCopy(&this->prompt, prompt);
78 }
char * prompt
Definition: console.h:68
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
Here is the call graph for this function:

◆ ~ConsoleBase()

ConsoleBase::~ConsoleBase ( )
virtual

Definition at line 80 of file console.cpp.

References prompt.

81 {
82  delete prompt;
83 }
char * prompt
Definition: console.h:68

Member Function Documentation

◆ AnsiBold()

void ConsoleBase::AnsiBold ( )
private

Definition at line 124 of file console.cpp.

References ansiMode, and WriteString().

Referenced by ShowAbout(), ShowLicense(), and ShowVersion().

125 {
126  if (ansiMode)
127  {
128  static const char *bold = "\x1B[1m";
129  WriteString(bold);
130  }
131 }
virtual void WriteString(const char *string)=0
bool ansiMode
Definition: console.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AnsiItalics()

void ConsoleBase::AnsiItalics ( )
private

Definition at line 133 of file console.cpp.

References ansiMode, and WriteString().

Referenced by ShowLicense().

134 {
135  if (ansiMode)
136  {
137  static const char *italics = "\x1B[3m";
138  WriteString(italics);
139  }
140 }
virtual void WriteString(const char *string)=0
bool ansiMode
Definition: console.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void ConsoleBase::Clear ( )
virtual

Definition at line 142 of file console.cpp.

References ansiMode, ResetConsole(), and WriteString().

Referenced by ClearStatement::Execute().

143 {
144  if (ansiMode)
145  {
146  static const char *clear = "\x1B[1;1H\x1B[J";
147  WriteString(clear);
148  ResetConsole();
149  }
150  else
151  {
152  static const char *msg = "Screen can only be cleared in ANSI mode.";
153  WriteString(msg);
155  }
156 }
#define NEWLINE
Definition: amath.h:222
virtual void ResetConsole()
Definition: console.cpp:115
virtual void WriteString(const char *string)=0
bool ansiMode
Definition: console.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Close()

void ConsoleBase::Close ( )
virtual

Definition at line 105 of file console.cpp.

Referenced by StandardProgram::~StandardProgram().

106 {
107 }
Here is the caller graph for this function:

◆ Exit()

virtual void ConsoleBase::Exit ( )
pure virtual

Implemented in StandardConsole.

Referenced by Program::Exit().

Here is the caller graph for this function:

◆ GetCompilerText()

const char * ConsoleBase::GetCompilerText ( )
protected

Definition at line 95 of file console.cpp.

References compiler.

96 {
97  return compiler;
98 }
static const char * compiler
Definition: console.cpp:37

◆ GetName()

const char * ConsoleBase::GetName ( )

Definition at line 85 of file console.cpp.

86 {
87  return CPROCNAME;
88 }
#define CPROCNAME
Definition: amath.h:293

◆ GetVersionText()

const char * ConsoleBase::GetVersionText ( )
protected

Definition at line 90 of file console.cpp.

References version.

91 {
92  return version;
93 }
static const char * version
Definition: console.cpp:36

◆ Open()

bool ConsoleBase::Open ( )
virtual

Definition at line 100 of file console.cpp.

Referenced by StandardProgram::Start().

101 {
102  return true;
103 }
Here is the caller graph for this function:

◆ Prompt()

void ConsoleBase::Prompt ( )
protected

Definition at line 207 of file console.cpp.

References prompt, ResetConsole(), and WriteString().

208 {
209  ResetConsole();
211  ResetConsole();
212 }
char * prompt
Definition: console.h:68
virtual void ResetConsole()
Definition: console.cpp:115
virtual void WriteString(const char *string)=0
Here is the call graph for this function:

◆ ResetConsole()

void ConsoleBase::ResetConsole ( )
virtual

Definition at line 115 of file console.cpp.

References ansiMode, and WriteString().

Referenced by Clear(), Prompt(), ShowAbout(), ShowLicense(), ShowVersion(), StandardProgram::Start(), and StartMessage().

116 {
117  if (ansiMode)
118  {
119  static const char *normal = "\x1B[0m";
120  WriteString(normal);
121  }
122 }
virtual void WriteString(const char *string)=0
bool ansiMode
Definition: console.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAnsiMode()

bool ConsoleBase::SetAnsiMode ( bool  value)
virtual

Reimplemented in StandardConsole.

Definition at line 109 of file console.cpp.

References ansiMode.

Referenced by Program::SetAnsiMode().

110 {
111  ansiMode = value;
112  return true;
113 }
bool ansiMode
Definition: console.h:69
Here is the caller graph for this function:

◆ SetPrompt()

void ConsoleBase::SetPrompt ( const char *  string)
virtual

Reimplemented in StandardConsole.

Definition at line 214 of file console.cpp.

References AllocAndCopy(), and prompt.

Referenced by PrefsStatement::Execute(), and Program::SetPrompt().

215 {
216  delete prompt;
217  AllocAndCopy(&prompt, string);
218 }
char * prompt
Definition: console.h:68
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShowAbout()

void ConsoleBase::ShowAbout ( )
virtual

Definition at line 174 of file console.cpp.

References about, AnsiBold(), compiler, ResetConsole(), version, and WriteString().

Referenced by AboutStatement::Execute().

175 {
176  AnsiBold();
178  ResetConsole();
181  ResetConsole();
183  ResetConsole();
184 }
#define NEWLINE
Definition: amath.h:222
void AnsiBold()
Definition: console.cpp:124
static const char * about
Definition: console.cpp:38
virtual void ResetConsole()
Definition: console.cpp:115
virtual void WriteString(const char *string)=0
static const char * compiler
Definition: console.cpp:37
static const char * version
Definition: console.cpp:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShowHelp()

void ConsoleBase::ShowHelp ( )
virtual

Definition at line 158 of file console.cpp.

References help, and WriteString().

Referenced by StandardProgram::Start().

159 {
160  WriteString(help);
161 }
virtual void WriteString(const char *string)=0
static const char * help
Definition: console.cpp:44
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShowLicense()

void ConsoleBase::ShowLicense ( )
virtual

Definition at line 186 of file console.cpp.

References AnsiBold(), AnsiItalics(), copyright, footer, license, ResetConsole(), and WriteString().

Referenced by LicenseStatement::Execute().

187 {
189  AnsiBold();
191  ResetConsole();
194  AnsiItalics();
196  ResetConsole();
199 }
#define NEWLINE
Definition: amath.h:222
static const char * license
Definition: console.cpp:48
void AnsiBold()
Definition: console.cpp:124
virtual void ResetConsole()
Definition: console.cpp:115
static const char * copyright
Definition: console.cpp:46
virtual void WriteString(const char *string)=0
static const char * footer
Definition: console.cpp:73
void AnsiItalics()
Definition: console.cpp:133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShowVersion()

void ConsoleBase::ShowVersion ( )
virtual

Definition at line 163 of file console.cpp.

References AnsiBold(), compiler, ResetConsole(), version, and WriteString().

Referenced by VersionStatement::Execute().

164 {
165  AnsiBold();
167  ResetConsole();
171  ResetConsole();
172 }
#define NEWLINE
Definition: amath.h:222
void AnsiBold()
Definition: console.cpp:124
virtual void ResetConsole()
Definition: console.cpp:115
virtual void WriteString(const char *string)=0
static const char * compiler
Definition: console.cpp:37
static const char * version
Definition: console.cpp:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Start()

virtual void ConsoleBase::Start ( )
pure virtual

Implemented in StandardConsole.

Referenced by StandardProgram::Start().

Here is the caller graph for this function:

◆ StartMessage()

void ConsoleBase::StartMessage ( )
protectedvirtual

Definition at line 201 of file console.cpp.

References ResetConsole(), and WriteString().

202 {
204  ResetConsole();
205 }
#define INTROMSG
Definition: text.h:47
virtual void ResetConsole()
Definition: console.cpp:115
virtual void WriteString(const char *string)=0
Here is the call graph for this function:

◆ WriteString()

virtual void ConsoleBase::WriteString ( const char *  string)
pure virtual

Implemented in StandardConsole.

Referenced by AnsiBold(), AnsiItalics(), Clear(), Prompt(), ResetConsole(), ShowAbout(), ShowHelp(), ShowLicense(), ShowVersion(), StandardProgram::Start(), and StartMessage().

Here is the caller graph for this function:

Member Data Documentation

◆ ansiMode

bool ConsoleBase::ansiMode
protected

Definition at line 69 of file console.h.

Referenced by AnsiBold(), AnsiItalics(), Clear(), ResetConsole(), and SetAnsiMode().

◆ prompt

char* ConsoleBase::prompt
protected

Definition at line 68 of file console.h.

Referenced by ConsoleBase(), Prompt(), SetPrompt(), and ~ConsoleBase().


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