amath  1.8.5
Simple command line calculator
aengine.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2014-2018 Carsten Sonne Larsen <cs@innolan.net>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * Project homepage:
26  * https://amath.innolan.net
27  *
28  */
29 
30 #ifndef AMATH_ANSI_CONSOLE_ENGINE
31 #define AMATH_ANSI_CONSOLE_ENGINE
32 
33 /**
34  * @file aengine.h
35  * @brief ANSI Console Engine
36  */
37 
38 class CharBuffer;
39 class CharValidator;
40 
41 /**
42  * @brief ANSI console controller
43  * @details
44  * More info on the ANSI console is available at Wikipedia:
45  * https://wikipedia.org/wiki/ANSI_escape_code
46  */
48 {
49 public:
50  AnsiConoleEngine(const char* prompt, CharValidator* validator);
52 
53  void StartInput();
54  bool InputDone() const;
55  const char* GetLine() const;
56  void SetPrompt(const char* string);
57  const char* ProcessChar(const unsigned char character);
58  void Enable();
59  void Disable();
60 
61 private:
62  void CopyLine();
63  void ShowLast();
64  void ShowNext();
65 
66  char* prompt;
67  bool enabled;
68 
69  static const int maxLines = 100;
70  static const int lineSize = 1024;
71  char** lines;
74  unsigned int len;
75  char* cursor;
76  char* endpos;
77 
78  int curline; // Index of last (current) line in buffer array
79  int showline; // Index of line being shown in buffer array
80  bool lineswap; // True if array swapped in progress
81  char* editline; // Line being edited (will be next to copy to array)
82 
83  bool escmode;
84  bool csimode;
85  bool delmode;
86  bool linedone;
88 };
89 
90 #endif
char ** lines
Definition: aengine.h:71
bool InputDone() const
Definition: aengine.cpp:380
unsigned int len
Definition: aengine.h:74
const char * GetLine() const
Definition: aengine.cpp:385
char * endpos
Definition: aengine.h:76
CharBuffer * linebuf
Definition: aengine.h:72
ANSI console controller.
Definition: aengine.h:47
AnsiConoleEngine(const char *prompt, CharValidator *validator)
Definition: aengine.cpp:44
CharBuffer * out
Definition: aengine.h:87
void Disable()
Definition: aengine.cpp:84
static const int maxLines
Definition: aengine.h:69
void StartInput()
Definition: aengine.cpp:89
void SetPrompt(const char *string)
Definition: aengine.cpp:390
CharValidator * validator
Definition: aengine.h:73
const char * ProcessChar(const unsigned char character)
Definition: aengine.cpp:104
static const int lineSize
Definition: aengine.h:70
char * prompt
Definition: aengine.h:66
char * cursor
Definition: aengine.h:75
Encapsulate an character array which can be used as a string.
Definition: charbuf.h:44
char * editline
Definition: aengine.h:81