0.1.5 LineFormetter

This commit is contained in:
rob tillaart 2022-11-14 20:50:36 +01:00
parent ef767f15cd
commit 702efe4213
10 changed files with 118 additions and 40 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -9,6 +24,7 @@ compile:
- esp32
# - esp8266
# - mega2560
- rpipico
libraries:
- "Ethernet"
- "SD"

View File

@ -0,0 +1,38 @@
# Change Log lineFormatter
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.5] - 2022-11-14
- Add RP2040 support to build-CI.
- Add CHANGELOG.md
- update readme.md
- minor edits unit tests
- bump version to 0.1.5.
- fix build-CI for examples.
## [0.1.4] - 2021-12-20
- not released (why?)
- update library.json
- update license
- minor edits
## [0.1.3] - 2021-11-06
- update Arduino-CI, badges
- update readme.md
- add reset();
## [0.1.2] - 2020-12-30
- Arduino-ci + unit tests
## [0.1.1] - 2020-06-19
- fix library.json
## [0.1.0] - 2020-05-14
- initial version

View File

@ -1,18 +1,12 @@
//
// FILE: LineFormatter.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.4
// VERSION: 0.1.5
// PURPOSE: Simple positioning wrapper class for Serial
// DATE: 2020-05-14
// URL: https://github.com/RobTillaart/LineFormatter
//
// HISTORY:
// 0.1.0 2020-05-14 initial version
// 0.1.1 2020-06-19 fix library.json
// 0.1.2 2020-12-30 Arduino-ci + unit tests
// 0.1.3 2021-11-06 update Arduino-CI, badges
// update readme.md, add reset();
// 0.1.4 2021-12-20 update library.json, license, minor edits
// HISTORY: see changelog.md
#include "LineFormatter.h"
@ -38,17 +32,17 @@ void LineFormatter::reset()
///////////////////////////////////////////
//
// WRITE - the core
// WRITE - the core
//
size_t LineFormatter::write(uint8_t c)
{
// handle tabs.
// handle tabs.
if (_tabCount && c == '\t')
{
write(' ');
for (int i = 0; i < _tabCount; i++)
{
if (_tabStop[i] > _pos + 1) // assume sorted
if (_tabStop[i] > _pos + 1) // assume sorted
{
gotoPos(_tabStop[i] - 1);
break;
@ -61,7 +55,7 @@ size_t LineFormatter::write(uint8_t c)
_pos++;
}
// handle return
// handle return
if (c == '\n')
{
_pos = 0;
@ -69,13 +63,13 @@ size_t LineFormatter::write(uint8_t c)
_anl++;
}
// handle maxpos
// handle maxpos
if (_maxPos && _pos == _maxPos)
{
write('\n');
}
// handle autoNewLine
// handle autoNewLine
if (_autoNewLine && (_anl == _autoNewLine))
{
write('\n');
@ -87,7 +81,7 @@ size_t LineFormatter::write(uint8_t c)
///////////////////////////////////////////
//
// REPEAT
// REPEAT
//
void LineFormatter::repeat(uint8_t n, char c, uint8_t newLine)
{
@ -105,7 +99,7 @@ void LineFormatter::repeat(uint8_t n, const char* str, uint8_t newLine)
///////////////////////////////////////////
//
// AUTONEWLINE
// AUTONEWLINE
//
void LineFormatter::setAutoNewLine(uint8_t n)
{
@ -116,7 +110,7 @@ void LineFormatter::setAutoNewLine(uint8_t n)
///////////////////////////////////////////
//
// TAB
// TAB
//
void LineFormatter::clearTabs()
{
@ -149,12 +143,12 @@ bool LineFormatter::addRelTab(uint8_t n)
///////////////////////////////////////////
//
// DEBUGGING
// DEBUGGING
//
void LineFormatter::printRuler(uint8_t n)
{
// for (int i = 0; i < _tabCount; i++) _stream->println(_tabStop[i]);
// return;
// for (int i = 0; i < _tabCount; i++) _stream->println(_tabStop[i]);
// return;
uint8_t t = 0;
for (int i = 1; i <= n; i++)

View File

@ -2,7 +2,7 @@
//
// FILE: LineFormatter.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.4
// VERSION: 0.1.5
// PURPOSE: Simple positioning wrapper class for Serial / Stream
// DATE: 2020-05-14
// URL: https://github.com/RobTillaart/LineFormatter
@ -15,7 +15,7 @@
#define MAX_TAB_STOPS 12
#endif
#define LINEFORMATTER_LIB_VERSION (F("0.1.4"))
#define LINEFORMATTER_LIB_VERSION (F("0.1.5"))
class LineFormatter: public Print
@ -28,36 +28,36 @@ public:
size_t write(uint8_t c);
// set the maximum line length - bold cut off
// set the maximum line length - bold cut off
void setMaxLength(uint8_t maxPos) { _maxPos = maxPos; };
uint8_t getMaxLength() { return _maxPos; };
// if position is smaller than n, move to the right
// if position is smaller than n, move to the right
uint8_t gotoPos(uint8_t pos) { while (_pos < pos) write(' '); return _pos; };
// repeat a char or a "string" n times
// followed by 0 or more newlines.
// repeat a char or a "string" n times
// followed by 0 or more newlines.
void repeat(uint8_t n, char c, uint8_t newLine = 0);
void repeat(uint8_t n, const char* str, uint8_t newLine = 0);
// n = 0 switches autoNewLine off
// n = 0 switches autoNewLine off
void setAutoNewLine(uint8_t n);
uint8_t getAutoNewLine() { return _autoNewLine; };
// Add a tab at (absolute/relative) position
// returns true on success
// Add a tab at (absolute/relative) position
// returns true on success
bool addTab(uint8_t n);
bool addRelTab(uint8_t n);
// remove all the tabs,
// remove all the tabs,
void clearTabs();
// print zero or more tabs, similar as e.g. "\t\t\t"
// print zero or more tabs, similar as e.g. "\t\t\t"
void tab(uint8_t n = 1) { while (n--) write('\t'); };
// DEBUGGING
// DEBUGGING
uint8_t getPos() { return _pos; };
void resetLineCount() { _lineCount = 0; };
uint16_t getLineCount() { return _lineCount; };

View File

@ -94,15 +94,17 @@ See examples
## Future
#### must
- improve documentation
#### should
- add examples
- add reset();
- set defaults for functions
- add **rmTab(position)**
-
#### could
- set defaults for functions
#### Wont
- check if print interface is completely covered.
- due to tab parsing it is, so no speed up.

View File

@ -0,0 +1,14 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
# - esp32 # has other server code
# - esp8266
# - mega2560
libraries:
- "Ethernet"
- "SD"

View File

@ -0,0 +1,14 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
# - esp32 # has other server code
# - esp8266
# - mega2560
libraries:
- "Ethernet"
- "SD"

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/LineFormatter.git"
},
"version": "0.1.4",
"version": "0.1.5",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=LineFormatter
version=0.1.4
version=0.1.5
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Wrapper class for Serial to enhance layout of tabular data.

View File

@ -95,9 +95,9 @@ unittest(test_tab)
fprintf(stderr, "tab test - !! cur position is one before tab position\n");
for (int i = 0; i < Line.getTabCount(); i++)
{
fprintf(stderr, "%d\t", 8 + i*8); // tab positions
fprintf(stderr, "%d\t", 8 + i*8); // tab positions
Line.write('\t');
assertEqual(8 + i*8, (int)Line.getPos() + 1 ); // current position is just before tab
assertEqual(8 + i*8, (int)Line.getPos() + 1 ); // current position is just before tab
}
}