Skip to content

Commit

Permalink
0.1.8 ANSI
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Jan 31, 2023
1 parent c18b6e9 commit 6d60974
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 63 deletions.
2 changes: 1 addition & 1 deletion libraries/ANSI/.github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
Expand Down
2 changes: 1 addition & 1 deletion libraries/ANSI/.github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
Expand Down
2 changes: 1 addition & 1 deletion libraries/ANSI/.github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
Expand Down
17 changes: 13 additions & 4 deletions libraries/ANSI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.1.7] - 2022-110-28
## [0.1.8] - 2023-01-31
- update readme.md
- update GitHub actions
- update license 2023
- minor edit unit test
- add example ansi_clock.ino
- add example ansi_132_columns.ino
- minor edits


## [0.1.7] - 2022-10-28
- add RP2040 to build-CI
- minor edits
- start simplifying changelog
- minor change unit test


## [0.1.6] - 2022-04-11
- add CHANGELOG.md
- add **int deviceType()**
Expand All @@ -37,9 +46,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.1] - 2020-05-27
- update library.json


## [0.1.0] - 2020-04-28
- initial release

Based upon my VT100 library (from 2013) which is now obsolete.
This vt100 lib had just a list of escape sequences #defined.


2 changes: 1 addition & 1 deletion libraries/ANSI/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2022 Rob Tillaart
Copyright (c) 2020-2023 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
116 changes: 98 additions & 18 deletions libraries/ANSI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ Arduino library with basic ANSI display codes for terminal applications.

# Description

ANSI codes are special codes that are send to a terminal e.g. VT100 to add
attributes to displayed characters.
Typical examples are bold, blink or colour.
Also known as escape codes the set of codes is large, however not
all terminal types do support all codes.
ANSI codes are special codes that are send to a terminal e.g. VT100 to add
attributes to displayed characters.
Typical examples are bold, blink or colour. ANSI codes are also known as escape codes.
The set of codes is large, however not all terminal types do support all codes.

Sending these ANSI codes to a simple ASCII only terminal like the one in the Arduino
IDE might result in garbage. So use with care.


## Terminals tested

Tests are done with
Tests are done with
- TeraTerm 4.102 + 4.106 (VT100, VT202, VT525 mode)
- Putty 0.71
- Putty 0.71

Other terminal program's exist so please let me know if yours is working too.
If not, please open an issue.
Expand All @@ -38,33 +37,114 @@ If not, please open an issue.
See examples


## Performance
## Interface

```cpp
#include "ansi.h"
```

#### Constructor

- **ANSI(Stream \* stream = &Serial)** wrapper around Serial.
Can be a software serial too.


#### Stream interface

- **int available()**
- **int read()**
- **int peek()**
- **void flush()**

Stream interface also includes print(), println(), write().


#### Character modi

- **void normal()** idem.
- **void bold()** idem.
- **void low()** idem.
- **void underline()** idem.
- **void blink()** idem.
- **void reverse()** idem.


#### Colour

- **void foreground(uint8_t fgcolor)**
- **void background(uint8_t bgcolor)**
- **void color(uint8_t fgcolor, uint8_t bgcolor)**
- **uint8_t gray2color(uint8_t gray)**
- **uint8_t grey2color(uint8_t grey)** idem
- **uint8_t rgb2color(uint8_t r, uint8_t g, uint8_t b)**


todo colour table

Since 0.1.5 there is some focus on performance.
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)**.

#### Positioning

## Experimental 0.1.6
- **void clearScreen()**
- **void clearLine(uint8_t clear = toEnd)** toEnd = 0,
toStart = 1,en tireLine = 2,
- **void home()** go to 0,0
- **void gotoXY(uint8_t x, uint8_t y)**
- **void cursorUp(uint8_t x)**
- **void cursorDown(uint8_t x)**
- **void cursorForward(uint8_t x)**
- **void cursorBack(uint8_t x)**


#### Experimental

look into **ansi.h** for experimental functions and notes.

Version 0.1.6 added a number of experimental function that need more testing.
Some are working, others are unclear, but the user can uncomment these and
experiment with them if needed.
Some are working with Teraterm, others are unclear of fail.
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
Also added is the **int deviceType()** function which also need more testing.

As always, constructive feedback is welcome.


## Performance

Since 0.1.5 there is some focus on performance.
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)**.


## Future

#### Must

- improve documentation
- elaborate interface
- colour info

#### Should

- test experimental functions
- test more terminal programs (Linux mac)
- write more examples
- add examples
- DOS emulator?
- experimental section

#### Could

- increase functionality
- which codes are useful ?
- investigate performance. (first step made in 0.1.5 but more possible)
- which codes are generic / useful ?
- investigate performance.
- first step made in 0.1.5 but more possible
- add line buffer in write(c) to improve throughput?
- need for flush() with line buffer?
- rewrite functions, replace print() by **\_stream->write()** calls? (effect on size?)
- move static strings to PROGMEM? as defines?
roughly ~20 bytes progmem for 4 bytes RAM...
- print(char) iso print(string) where possible


#### Wont


26 changes: 16 additions & 10 deletions libraries/ANSI/ansi.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
//
// FILE: ansi.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.7
// VERSION: 0.1.8
// PURPOSE: Arduino library to send ANSI escape sequences
// DATE: 2020-04-28
// URL: https://github.com/RobTillaart/ANSI
//
// HISTORY: See CHANGELOG.md


#include "ansi.h"
Expand Down Expand Up @@ -37,6 +35,7 @@ int ANSI::peek()

void ANSI::clearScreen()
{
// print(F("\033[2J\033[H"));
print("\033[2J");
home();
}
Expand All @@ -50,6 +49,13 @@ void ANSI::clearLine(uint8_t clear)
}


void ANSI::home()
{
print("\033[H");
};



// ANSI has three different color spaces: 4-bit color, 8-bit color, and 24-bit color
// These are rendered with SGR 30-37,90-97/40-47,100-107, SGR 38;5/48;5, and SGR 38;2/48;2, respectively
// The 4-bit color space is the most widely compatible and the most compactly transmitted
Expand Down Expand Up @@ -97,8 +103,8 @@ void ANSI::color(uint8_t fgcolor, uint8_t bgcolor)

uint8_t ANSI::rgb2color(uint8_t r, uint8_t g, uint8_t b) {
return 16 +
36 * (uint16_t(r) * 6 / 256) +
6 * (uint16_t(g) * 6 / 256) +
36 * (uint16_t(r) * 6 / 256) +
6 * (uint16_t(g) * 6 / 256) +
(uint16_t(b) * 6 / 256);
}

Expand Down Expand Up @@ -149,7 +155,7 @@ int ANSI::deviceType(uint32_t timeout)
{
int type = -1; // -1 = unknown
print("\033[0c");

uint32_t start = millis();
int read_len = 0;
char buffer[8];
Expand All @@ -161,8 +167,8 @@ int ANSI::deviceType(uint32_t timeout)
{
type = buffer[2] - '0';
}
// Serial.write(buffer, 3);
// Serial.println();
// Serial.write(buffer, 3);
// Serial.println();
}
return type;
}
Expand All @@ -174,7 +180,7 @@ int ANSI::deviceType(uint32_t timeout)
//
size_t ANSI::write(uint8_t c)
{
// TODO add line buffer? - interference with write(array, length) !?
// add line buffer? - interference with write(array, length) !?
return _stream->write(c);
}

Expand Down Expand Up @@ -222,5 +228,5 @@ void ANSI::color8(uint8_t base, uint8_t color) {
}


// -- END OF FILE --
// -- END OF FILE --

0 comments on commit 6d60974

Please sign in to comment.