0.2.1 ANSI

This commit is contained in:
Rob Tillaart 2023-10-17 14:51:45 +02:00
parent c3bb5e50e1
commit 2d8a4ceff3
8 changed files with 80 additions and 33 deletions

View File

@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.1] - 2023-10-17
- update readme.md (badges)
- fix version in ansi.cpp
- add a derived VT100 class (wrapper for now).
- minor edits
## [0.2.0] - 2023-02-26 ## [0.2.0] - 2023-02-26
- fix #13 gotoXY(column, row) - fix #13 gotoXY(column, row)
- add ansi_gotoXY example. - add ansi_gotoXY example.

View File

@ -2,8 +2,11 @@
[![Arduino CI](https://github.com/RobTillaart/ANSI/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) [![Arduino CI](https://github.com/RobTillaart/ANSI/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/ANSI/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ANSI/actions/workflows/arduino-lint.yml) [![Arduino-lint](https://github.com/RobTillaart/ANSI/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ANSI/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/ANSI/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ANSI/actions/workflows/jsoncheck.yml) [![JSON check](https://github.com/RobTillaart/ANSI/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ANSI/actions/workflows/jsoncheck.yml)
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/ANSI.svg)](https://github.com/RobTillaart/ANSI/issues)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ANSI/blob/master/LICENSE) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ANSI/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ANSI.svg?maxAge=3600)](https://github.com/RobTillaart/ANSI/releases) [![GitHub release](https://img.shields.io/github/release/RobTillaart/ANSI.svg?maxAge=3600)](https://github.com/RobTillaart/ANSI/releases)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/ANSI.svg)](https://registry.platformio.org/libraries/robtillaart/ANSI)
# ANSI # ANSI
@ -54,10 +57,11 @@ See examples
#include "ansi.h" #include "ansi.h"
``` ```
#### Constructor #### Constructors
- **ANSI(Stream \* stream = &Serial)** wrapper around Serial. - **ANSI(Stream \* stream = &Serial)** wrapper around Serial.
Can be a software serial too. Can be a software serial too.
- **VT100(Stream \* stream = &Serial)** derived class (wrapper)
#### Stream interface #### Stream interface
@ -91,8 +95,7 @@ Three helpers to map to the nearest colour.
- **uint8_t grey2color(uint8_t grey)** idem - **uint8_t grey2color(uint8_t grey)** idem
- **uint8_t rgb2color(uint8_t r, uint8_t g, uint8_t b)** - **uint8_t rgb2color(uint8_t r, uint8_t g, uint8_t b)**
- https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
To do colour table
#### Positioning #### Positioning
@ -111,13 +114,26 @@ Note X == row and Y == column. See #13.
#### Experimental #### Experimental
look into **ansi.h** for experimental functions and notes. Look into **ansi.h** for experimental functions and notes.
Version 0.1.6 added a number of experimental function that need more testing. Version 0.1.6 added a number of experimental function that need more testing.
Some are working with Teraterm, others are unclear of fail. Some are working with Teraterm, others are unclear of fail.
The user can uncomment these and verify if these work with their terminal. The user can uncomment these and verify if these work with their terminal.
Also added is the **int deviceType()** function which also need more testing.
##### Experimental device type
The **int deviceType()** function needs more testing.
See - https://github.com/RobTillaart/ANSI/issues/9
| Type | Description |
|:-------:|:--------------|
| -1 | unknown |
| 1 | VT52 |
| 2 | VT100 |
| 3 | VT220 |
| other | unknown |
As always, constructive feedback is welcome. As always, constructive feedback is welcome.
@ -128,7 +144,7 @@ Since 0.1.5 there is some focus on performance.
Using **ansi.print()** and **ansi.println()** for printing text and numbers is Using **ansi.print()** and **ansi.println()** for printing text and numbers is
improved a bit since 0.1.4 by adding the private **write(array, length)**. improved a bit since 0.1.4 by adding the private **write(array, length)**.
Since 0.2.0 the print() statements are replaced by write(). Since 0.2.0 the (internal) print() statements are replaced by write().
Although it are small improvements these add up. Although it are small improvements these add up.
@ -148,7 +164,6 @@ Although it are small improvements these add up.
- DOS emulator? - DOS emulator?
- experimental section - experimental section
- evaluate experimental code - evaluate experimental code
- move code from .h to .cpp
#### Could #### Could
@ -157,9 +172,20 @@ Although it are small improvements these add up.
- investigate performance. - investigate performance.
- add line buffer in write(c) to improve throughput? - add line buffer in write(c) to improve throughput?
- need for flush() with line buffer? - need for flush() with line buffer?
- move code from .h to .cpp
- more derived classes
#### Wont #### Wont
- move static strings to PROGMEM? as defines? - move static strings to PROGMEM? as defines?
roughly ~20 bytes progmem for 4 bytes RAM... roughly ~20 bytes progmem for 4 bytes RAM...
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,

View File

@ -1,7 +1,7 @@
// //
// FILE: ansi.cpp // FILE: ansi.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.8 // VERSION: 0.2.1
// PURPOSE: Arduino library to send ANSI escape sequences // PURPOSE: Arduino library to send ANSI escape sequences
// DATE: 2020-04-28 // DATE: 2020-04-28
// URL: https://github.com/RobTillaart/ANSI // URL: https://github.com/RobTillaart/ANSI
@ -197,7 +197,6 @@ uint8_t ANSI::rgb2color(uint8_t r, uint8_t g, uint8_t b) {
} }
int ANSI::deviceType(uint32_t timeout) int ANSI::deviceType(uint32_t timeout)
{ {
int type = -1; // -1 = unknown int type = -1; // -1 = unknown
@ -223,14 +222,7 @@ int ANSI::deviceType(uint32_t timeout)
////////////////////////////////////////////////// //////////////////////////////////////////////////
// //
// EXPERIMENTAL // PROTECTED
//
//////////////////////////////////////////////////
//
// PRIVATE
// //
size_t ANSI::write(uint8_t c) size_t ANSI::write(uint8_t c)
{ {
@ -245,7 +237,6 @@ size_t ANSI::write(uint8_t * array, uint8_t length)
} }
void ANSI::color4_code(uint8_t base, uint8_t color) { void ANSI::color4_code(uint8_t base, uint8_t color) {
if (color < 8) { if (color < 8) {
print(base + color); print(base + color);
@ -282,5 +273,14 @@ void ANSI::color8(uint8_t base, uint8_t color) {
} }
//////////////////////////////////////////////////////
//
// DERIVED
//
VT100::VT100(Stream * stream) : ANSI(stream)
{
}
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,7 +2,7 @@
// //
// FILE: ansi.h // FILE: ansi.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.2.0 // VERSION: 0.2.1
// PURPOSE: Arduino library to send ANSI escape sequences // PURPOSE: Arduino library to send ANSI escape sequences
// DATE: 2020-04-28 // DATE: 2020-04-28
// URL: https://github.com/RobTillaart/ANSI // URL: https://github.com/RobTillaart/ANSI
@ -10,7 +10,7 @@
#include "Arduino.h" #include "Arduino.h"
#define ANSI_LIB_VERSION (F("0.2.0")) #define ANSI_LIB_VERSION (F("0.2.1"))
class ANSI : public Stream class ANSI : public Stream
@ -81,16 +81,18 @@ public:
// (for named colors, this is 25% faster than setting one then the other) // (for named colors, this is 25% faster than setting one then the other)
void color(uint8_t fgcolor, uint8_t bgcolor); void color(uint8_t fgcolor, uint8_t bgcolor);
// Convert gray to ANSI 24-level gray in 4-bit colorspace // Convert gray to ANSI 24-level gray in 4-bit color space
// Pass in a gray level from 0 (black) to 255 (white) // Pass in a gray level from 0 (black) to 255 (white)
uint8_t gray2color(uint8_t gray) { return 232 + uint16_t(gray) * 24 / 256; } uint8_t gray2color(uint8_t gray) { return 232 + uint16_t(gray) * 24 / 256; }
uint8_t grey2color(uint8_t grey) { return this->gray2color(grey); } uint8_t grey2color(uint8_t grey) { return this->gray2color(grey); }
// Convert RGB color to ANSI color in 4-bit colorspace // Convert RGB color to ANSI color in 4-bit color space
// Pass in a RGB level from 0 (dark) to 255 (light) // Pass in a RGB level from 0 (dark) to 255 (light)
uint8_t rgb2color(uint8_t r, uint8_t g, uint8_t b); uint8_t rgb2color(uint8_t r, uint8_t g, uint8_t b);
// EXPERIMENTAL SECTION
// use at own risk
// META // META
// deviceType is discussed // deviceType is discussed
// - https://github.com/RobTillaart/ANSI/issues/9 // - https://github.com/RobTillaart/ANSI/issues/9
@ -101,10 +103,8 @@ public:
int deviceType(uint32_t timeout = 100); int deviceType(uint32_t timeout = 100);
// EXPERIMENTAL SECTION
// use at own risk
// check if it works on your terminal // check if it works on your terminal
// TERA // TERATERM
void set132columns() { print("\033[?3h"); }; // + void set132columns() { print("\033[?3h"); }; // +
void set80columns() { print("\033[?3l"); }; // + void set80columns() { print("\033[?3l"); }; // +
@ -118,9 +118,9 @@ public:
void reset() { print("\033c"); }; // + void reset() { print("\033c"); }; // +
// NOT working on TERA TERM (or need testing) // NOT working on TERATERM (or need more testing)
// use at own risk // use at own risk
// check if it works on your terminal TERA // check if it works on your terminal TERATERM
/* /*
void setSmoothScroll() { print("\033[?4h"); }; // - void setSmoothScroll() { print("\033[?4h"); }; // -
void setJumpScroll() { print("\033[?4l"); }; // - void setJumpScroll() { print("\033[?4l"); }; // -
@ -130,14 +130,14 @@ public:
// PRINTING // PRINTING
// use at own risk // use at own risk
// check if it works on your terminal TERA // check if it works on your terminal TERATERM
void printLine() { print("\033[1i"); }; // ? void printLine() { print("\033[1i"); }; // ?
void startPrintLog() { print("\033[4i"); }; // ? void startPrintLog() { print("\033[4i"); }; // ?
void stopPrintLog() { print("\033[5i"); }; // ? void stopPrintLog() { print("\033[5i"); }; // ?
*/ */
private: protected:
size_t write(uint8_t c); size_t write(uint8_t c);
size_t write(uint8_t * array, uint8_t length); size_t write(uint8_t * array, uint8_t length);
@ -151,5 +151,16 @@ private:
}; };
//////////////////////////////////////////////////////
//
// DERIVED
//
class VT100 : public ANSI
{
public:
VT100(Stream * stream = &Serial);
};
// -- END OF FILE -- // -- END OF FILE --

View File

@ -3,6 +3,7 @@
# Data types (KEYWORD1) # Data types (KEYWORD1)
ANSI KEYWORD1 ANSI KEYWORD1
VT100 KEYWORD1
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)

View File

@ -15,9 +15,9 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/ANSI.git" "url": "https://github.com/RobTillaart/ANSI.git"
}, },
"version": "0.2.0", "version": "0.2.1",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "*",
"platforms": "*", "platforms": "*",
"headers": "ansi.h" "headers": "ansi.h"
} }

View File

@ -1,5 +1,5 @@
name=ANSI name=ANSI
version=0.2.0 version=0.2.1
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library to send ANSI escape sequences. sentence=Arduino library to send ANSI escape sequences.

View File

@ -40,8 +40,10 @@ unittest_teardown()
unittest(test_constructor) unittest(test_constructor)
{ {
ANSI ansi(&Serial); ANSI ansi(&Serial);
assertEqual(12, ansi.println("1234567890") ); assertEqual(12, ansi.println("1234567890") );
VT100 vt(&Serial);
assertEqual(10, vt.print("1234567890") );
} }