Skip to content

Commit 6d60974

Browse files
committed
0.1.8 ANSI
1 parent c18b6e9 commit 6d60974

File tree

15 files changed

+386
-63
lines changed

15 files changed

+386
-63
lines changed

libraries/ANSI/.github/workflows/arduino-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v3
1010
- uses: arduino/arduino-lint-action@v1
1111
with:
1212
library-manager: update

libraries/ANSI/.github/workflows/arduino_test_runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212
- uses: ruby/setup-ruby@v1
1313
with:
1414
ruby-version: 2.6

libraries/ANSI/.github/workflows/jsoncheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414
- name: json-syntax-check
1515
uses: limitusus/json-syntax-check@v1
1616
with:

libraries/ANSI/CHANGELOG.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9-
## [0.1.7] - 2022-110-28
9+
## [0.1.8] - 2023-01-31
10+
- update readme.md
11+
- update GitHub actions
12+
- update license 2023
13+
- minor edit unit test
14+
- add example ansi_clock.ino
15+
- add example ansi_132_columns.ino
16+
- minor edits
17+
18+
19+
## [0.1.7] - 2022-10-28
1020
- add RP2040 to build-CI
1121
- minor edits
1222
- start simplifying changelog
1323
- minor change unit test
1424

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

40-
4149
## [0.1.0] - 2020-04-28
4250
- initial release
43-
51+
Based upon my VT100 library (from 2013) which is now obsolete.
52+
This vt100 lib had just a list of escape sequences #defined.
4453

4554

libraries/ANSI/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020-2022 Rob Tillaart
3+
Copyright (c) 2020-2023 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/ANSI/README.md

Lines changed: 98 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@ Arduino library with basic ANSI display codes for terminal applications.
1313

1414
# Description
1515

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

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

2524

2625
## Terminals tested
2726

28-
Tests are done with
27+
Tests are done with
2928
- TeraTerm 4.102 + 4.106 (VT100, VT202, VT525 mode)
30-
- Putty 0.71
29+
- Putty 0.71
3130

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

4039

41-
## Performance
40+
## Interface
41+
42+
```cpp
43+
#include "ansi.h"
44+
```
45+
46+
#### Constructor
47+
48+
- **ANSI(Stream \* stream = &Serial)** wrapper around Serial.
49+
Can be a software serial too.
50+
51+
52+
#### Stream interface
53+
54+
- **int available()**
55+
- **int read()**
56+
- **int peek()**
57+
- **void flush()**
58+
59+
Stream interface also includes print(), println(), write().
60+
61+
62+
#### Character modi
63+
64+
- **void normal()** idem.
65+
- **void bold()** idem.
66+
- **void low()** idem.
67+
- **void underline()** idem.
68+
- **void blink()** idem.
69+
- **void reverse()** idem.
70+
71+
72+
#### Colour
73+
74+
- **void foreground(uint8_t fgcolor)**
75+
- **void background(uint8_t bgcolor)**
76+
- **void color(uint8_t fgcolor, uint8_t bgcolor)**
77+
- **uint8_t gray2color(uint8_t gray)**
78+
- **uint8_t grey2color(uint8_t grey)** idem
79+
- **uint8_t rgb2color(uint8_t r, uint8_t g, uint8_t b)**
80+
81+
82+
todo colour table
4283

43-
Since 0.1.5 there is some focus on performance.
44-
Using **ansi.print()** and **ansi.println()** for printing text and numbers is
45-
improved a bit since 0.1.4 by adding the private **write(array, length)**.
4684

85+
#### Positioning
4786

48-
## Experimental 0.1.6
87+
- **void clearScreen()**
88+
- **void clearLine(uint8_t clear = toEnd)** toEnd = 0,
89+
toStart = 1,en tireLine = 2,
90+
- **void home()** go to 0,0
91+
- **void gotoXY(uint8_t x, uint8_t y)**
92+
- **void cursorUp(uint8_t x)**
93+
- **void cursorDown(uint8_t x)**
94+
- **void cursorForward(uint8_t x)**
95+
- **void cursorBack(uint8_t x)**
96+
97+
98+
#### Experimental
99+
100+
look into **ansi.h** for experimental functions and notes.
49101

50102
Version 0.1.6 added a number of experimental function that need more testing.
51-
Some are working, others are unclear, but the user can uncomment these and
52-
experiment with them if needed.
103+
Some are working with Teraterm, others are unclear of fail.
104+
The user can uncomment these and verify if these work with their terminal.
53105

54-
Also added is the **int deviceType()** function which also need more testing
106+
Also added is the **int deviceType()** function which also need more testing.
55107

56108
As always, constructive feedback is welcome.
57109

58110

111+
## Performance
112+
113+
Since 0.1.5 there is some focus on performance.
114+
Using **ansi.print()** and **ansi.println()** for printing text and numbers is
115+
improved a bit since 0.1.4 by adding the private **write(array, length)**.
116+
117+
59118
## Future
60119

120+
#### Must
121+
122+
- improve documentation
123+
- elaborate interface
124+
- colour info
125+
126+
#### Should
127+
128+
- test experimental functions
61129
- test more terminal programs (Linux mac)
62-
- write more examples
130+
- add examples
63131
- DOS emulator?
132+
- experimental section
133+
134+
#### Could
135+
64136
- increase functionality
65-
- which codes are useful ?
66-
- investigate performance. (first step made in 0.1.5 but more possible)
137+
- which codes are generic / useful ?
138+
- investigate performance.
139+
- first step made in 0.1.5 but more possible
67140
- add line buffer in write(c) to improve throughput?
68141
- need for flush() with line buffer?
69142
- rewrite functions, replace print() by **\_stream->write()** calls? (effect on size?)
143+
- move static strings to PROGMEM? as defines?
144+
roughly ~20 bytes progmem for 4 bytes RAM...
145+
- print(char) iso print(string) where possible
146+
147+
148+
#### Wont
149+
70150

libraries/ANSI/ansi.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
//
22
// FILE: ansi.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.7
4+
// VERSION: 0.1.8
55
// PURPOSE: Arduino library to send ANSI escape sequences
66
// DATE: 2020-04-28
77
// URL: https://github.com/RobTillaart/ANSI
8-
//
9-
// HISTORY: See CHANGELOG.md
108

119

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

3836
void ANSI::clearScreen()
3937
{
38+
// print(F("\033[2J\033[H"));
4039
print("\033[2J");
4140
home();
4241
}
@@ -50,6 +49,13 @@ void ANSI::clearLine(uint8_t clear)
5049
}
5150

5251

52+
void ANSI::home()
53+
{
54+
print("\033[H");
55+
};
56+
57+
58+
5359
// ANSI has three different color spaces: 4-bit color, 8-bit color, and 24-bit color
5460
// 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
5561
// The 4-bit color space is the most widely compatible and the most compactly transmitted
@@ -97,8 +103,8 @@ void ANSI::color(uint8_t fgcolor, uint8_t bgcolor)
97103

98104
uint8_t ANSI::rgb2color(uint8_t r, uint8_t g, uint8_t b) {
99105
return 16 +
100-
36 * (uint16_t(r) * 6 / 256) +
101-
6 * (uint16_t(g) * 6 / 256) +
106+
36 * (uint16_t(r) * 6 / 256) +
107+
6 * (uint16_t(g) * 6 / 256) +
102108
(uint16_t(b) * 6 / 256);
103109
}
104110

@@ -149,7 +155,7 @@ int ANSI::deviceType(uint32_t timeout)
149155
{
150156
int type = -1; // -1 = unknown
151157
print("\033[0c");
152-
158+
153159
uint32_t start = millis();
154160
int read_len = 0;
155161
char buffer[8];
@@ -161,8 +167,8 @@ int ANSI::deviceType(uint32_t timeout)
161167
{
162168
type = buffer[2] - '0';
163169
}
164-
// Serial.write(buffer, 3);
165-
// Serial.println();
170+
// Serial.write(buffer, 3);
171+
// Serial.println();
166172
}
167173
return type;
168174
}
@@ -174,7 +180,7 @@ int ANSI::deviceType(uint32_t timeout)
174180
//
175181
size_t ANSI::write(uint8_t c)
176182
{
177-
// TODO add line buffer? - interference with write(array, length) !?
183+
// add line buffer? - interference with write(array, length) !?
178184
return _stream->write(c);
179185
}
180186

@@ -222,5 +228,5 @@ void ANSI::color8(uint8_t base, uint8_t color) {
222228
}
223229

224230

225-
// -- END OF FILE --
231+
// -- END OF FILE --
226232

0 commit comments

Comments
 (0)