Shellminator  V1.1.1
Simple Terminal
Loading...
Searching...
No Matches
Shellminator.hpp
Go to the documentation of this file.
1/*
2 * Created on Aug 10 2020
3 *
4 * Copyright (c) 2020 - Daniel Hajnal
5 * hajnal.daniel96@gmail.com
6 * This file is part of the Shellminator project.
7 * Modified 2022.05.08
8*/
9
10/*
11MIT License
12
13Copyright (c) 2020 Daniel Hajnal
14
15Permission is hereby granted, free of charge, to any person obtaining a copy
16of this software and associated documentation files (the "Software"), to deal
17in the Software without restriction, including without limitation the rights
18to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19copies of the Software, and to permit persons to whom the Software is
20furnished to do so, subject to the following conditions:
21
22The above copyright notice and this permission notice shall be included in all
23copies or substantial portions of the Software.
24
25THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31SOFTWARE.
32*/
33
34
35#ifndef SHELLMINATOR_HPP_
36#define SHELLMINATOR_HPP_
37
39#include "Shellminator-IO.hpp"
40
41#ifdef ARDUINO
42#include "Arduino.h"
43#endif
44
45#ifdef SHELLMINATOR_USE_WIFI_CLIENT
46 #ifdef ESP8266
47 #include <ESP8266WiFi.h>
48 #endif
49
50 #ifdef ESP32
51 #include <WiFi.h>
52 #endif
53#endif
54
55#ifdef __has_include
56 #if __has_include ("Commander-API.hpp")
57 #include "Commander-API.hpp"
58 #endif
59#endif
60
61#ifdef COMMANDER_API_VERSION
62#include "Commander-API.hpp"
63#endif
64
65#include <stdio.h>
66#include <stdint.h>
67#include <string.h>
68
75
76#ifdef SHELLMINATOR_ENABLE_QR_SUPPORT
77
78#include "qrcodegen.h"
79
80#endif
81
84#ifndef SHELLMINATOR_BUFF_LEN
85#define SHELLMINATOR_BUFF_LEN 20
86#endif
87
92#ifndef SHELLMINATOR_BUFF_DIM
93#define SHELLMINATOR_BUFF_DIM 5
94#endif
95
98#ifndef SHELLMINATOR_BANNER_LEN
99#define SHELLMINATOR_BANNER_LEN 20
100#endif
101
103#define SHELLMINATOR_VERSION "1.1.1"
104
107#ifndef SHELLMINATOR_LOGO_FONT_STYLE
108#define SHELLMINATOR_LOGO_FONT_STYLE BOLD
109#endif
110
111#ifndef SHELLMINATOR_LOGO_COLOR
112#define SHELLMINATOR_LOGO_COLOR RED
113#endif
114
122
123public:
124
128 enum {
129 BLACK = 30,
130 RED = 31,
131 GREEN = 32,
132 YELLOW = 33,
133 BLUE = 34,
135 CYAN = 36,
136 WHITE = 37
137 };
138
142 enum {
144 BOLD = 1,
151 INVISIBLE = 8
152 };
153
155 static const char *version;
156
157#ifdef SHELLMINATOR_USE_ARDUINO_SERIAL
162 Shellminator( HardwareSerial *serialPort_p );
163
169 Shellminator( HardwareSerial *serialPort_p, void( *execution_fn_p )( char* ) );
170#endif
171
172#ifdef SHELLMINATOR_USE_ARDUINO_32U4_SERIAL
177 Shellminator( Serial_ *serialPort_p );
178
184 Shellminator( Serial_ *serialPort_p, void( *execution_fn_p )( char* ) );
185#endif
186
187#ifdef SHELLMINATOR_USE_WIFI_CLIENT
192 Shellminator( WiFiClient *resp );
193
199 Shellminator( WiFiClient *resp, void( *execution_fn_p )( char* ) );
200#endif
201
206 void addExecFunc( void( *execution_fn_p )( char* ) );
207
214 void begin( char* banner_p );
215
222 void begin( const char* banner_p );
223
228 void sendBackspace();
229
233 void clear();
234
240 void update();
241
248 void setTerminalCharacterColor( uint8_t style, uint8_t color );
249
258 static void setTerminalCharacterColor( HardwareSerial *serialPort, uint8_t style, uint8_t color );
259
263 void drawLogo();
264
269 void setBannerText( char* banner_p );
270
278 void attachLogo( char* logo_p );
279
287 void attachLogo( const char* logo_p );
288
295 void overrideUpArrow( void( *func )( void ) );
296
303 void overrideDownArrow( void( *func )( void ) );
304
311 void overrideLeftArrow( void( *func )( void ) );
312
319 void overrideRightArrow( void( *func )( void ) );
320
328 void overrideAbortKey( void( *func )( void ) );
329
335 void freeUpArrow();
336
342 void freeDownArrow();
343
349 void freeLeftArrow();
350
356 void freeRightArrow();
357
363 void freeAbortKey();
364
368 bool enableFormatting = true;
369
370 #ifdef COMMANDER_API_VERSION
371
372 void attachCommander( Commander* commander_p );
373
374 #endif
375
376 // Configuration for QR code specific parts.
377 #ifdef SHELLMINATOR_ENABLE_QR_SUPPORT
378
386 void generateQRText( char* text );
387
395 void generateQRText( const char* text );
396
404 void generateQRText( char* text, enum qrcodegen_Ecc ecc );
405
413 void generateQRText( const char* text, enum qrcodegen_Ecc ecc );
414
415 #endif
416
417private:
418
424 char *logo = NULL;
425
428 void( *execution_fn )( char* );
429
441 char cmd_buff[ SHELLMINATOR_BUFF_DIM ][ SHELLMINATOR_BUFF_LEN ] = { { 0 } };
442
444 uint32_t cmd_buff_dim = 1;
445
447 uint32_t cmd_buff_cntr = 0;
448
450 uint32_t cursor = 0;
451
453 uint32_t escape_state = 0;
454
456 char banner[ SHELLMINATOR_BANNER_LEN ] = { '\0' };
457
459 void( *upArrowOverrideFunc )( void ) = NULL;
460
462 void( *downArrowOverrideFunc )( void ) = NULL;
463
465 void( *leftArrowOverrideFunc )( void ) = NULL;
466
468 void( *rightArrowOverrideFunc )( void ) = NULL;
469
471 void( *abortKeyFunc )( void ) = NULL;
472
479 void process( char new_char );
480
482 void printBanner();
483
485 void redrawLine();
486
487 //---- Communication channels ----//
488
490 shellminatorChannel defaultChannel;
491
492 #ifdef SHELLMINATOR_USE_ARDUINO_SERIAL
494 shellminatorArduinoSerialChannel arduinoSerialChannel;
495 #endif
496
497 #ifdef SHELLMINATOR_USE_ARDUINO_32U4_SERIAL
499 shellminatorArduino32U4SerialChannel arduino32U4SerialChannel;
500 #endif
501
502 #ifdef SHELLMINATOR_USE_WIFI_CLIENT
505 #endif
506
509 shellminatorChannel *channel = &defaultChannel;
510
511 //---- Commander-API support specific part ----//
512 #ifdef COMMANDER_API_VERSION
513
515 Commander* commander = NULL;
516
518 uint32_t commandCheckTimerStart = 0;
519
521 bool commandChecked = false;
522
525 bool commandFound = false;
526
527 #endif
528
529 // QR-code configuration specific parts.
530 #ifdef SHELLMINATOR_ENABLE_QR_SUPPORT
531
532 uint8_t qr_data[ qrcodegen_BUFFER_LEN_MAX ];
533 uint8_t qr_tempBuff[ qrcodegen_BUFFER_LEN_MAX ];
534
535 #endif
536
537};
538
539#endif
#define SHELLMINATOR_BUFF_LEN
+---— Costum configuration ---—+ | | | This is where you have to config | | your defines!...
#define SHELLMINATOR_BANNER_LEN
Maximum length of the banner text.
#define SHELLMINATOR_BUFF_DIM
Definition of the maximum length of the previous command memory.
Shellminator object.
void begin(char *banner_p)
Shellminator initialization function.
void clear()
Clear screen.
void freeLeftArrow()
Reset left arrow key functionality to default.
void overrideUpArrow(void(*func)(void))
Override up arrow key behaviour.
void update()
Update function.
void addExecFunc(void(*execution_fn_p)(char *))
Execution function adder function.
bool enableFormatting
This flag enables or disables character formatting.
void overrideRightArrow(void(*func)(void))
Override right arrow key behaviour.
void freeAbortKey()
Reset abort key functionality to default.
void sendBackspace()
Sends a backspace.
void freeUpArrow()
Reset up arrow key functionality to default.
void overrideDownArrow(void(*func)(void))
Override down arrow key behaviour.
void overrideAbortKey(void(*func)(void))
Override abort key behaviour.
void attachLogo(char *logo_p)
This function attaches a logo to the terminal.
void overrideLeftArrow(void(*func)(void))
Override left arrow key behaviour.
void setTerminalCharacterColor(uint8_t style, uint8_t color)
Bring some color into your code.
void freeRightArrow()
Reset right arrow key functionality to default.
void drawLogo()
Draws the startup logo.
void setBannerText(char *banner_p)
This function sets the banner text.
void freeDownArrow()
Reset down arrow key functionality to default.
static const char * version
String that holds the version information.
Shellminator channel class for Arduino Serial objects.
Shellminator channel class for Arduino Serial objects.
Shellminator channel class.