0.1.4 LineFormatter

This commit is contained in:
rob tillaart 2021-12-20 20:09:13 +01:00
parent 20f3630360
commit 121f872926
12 changed files with 47 additions and 48 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2020-2021 Rob Tillaart Copyright (c) 2020-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,7 +1,7 @@
// //
// FILE: LineFormatter.cpp // FILE: LineFormatter.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.3 // VERSION: 0.1.4
// PURPOSE: Simple positioning wrapper class for Serial // PURPOSE: Simple positioning wrapper class for Serial
// DATE: 2020-05-14 // DATE: 2020-05-14
// URL: https://github.com/RobTillaart/LineFormatter // URL: https://github.com/RobTillaart/LineFormatter
@ -12,7 +12,7 @@
// 0.1.2 2020-12-30 Arduino-ci + unit tests // 0.1.2 2020-12-30 Arduino-ci + unit tests
// 0.1.3 2021-11-06 update Arduino-CI, badges // 0.1.3 2021-11-06 update Arduino-CI, badges
// update readme.md, add reset(); // update readme.md, add reset();
// // 0.1.4 2021-12-20 update library.json, license, minor edits
#include "LineFormatter.h" #include "LineFormatter.h"

View File

@ -2,7 +2,7 @@
// //
// FILE: LineFormatter.h // FILE: LineFormatter.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.3 // VERSION: 0.1.4
// PURPOSE: Simple positioning wrapper class for Serial / Stream // PURPOSE: Simple positioning wrapper class for Serial / Stream
// DATE: 2020-05-14 // DATE: 2020-05-14
// URL: https://github.com/RobTillaart/LineFormatter // URL: https://github.com/RobTillaart/LineFormatter
@ -12,10 +12,10 @@
#include "Print.h" #include "Print.h"
#ifndef MAX_TAB_STOPS #ifndef MAX_TAB_STOPS
#define MAX_TAB_STOPS 12 #define MAX_TAB_STOPS 12
#endif #endif
#define LINEFORMATTER_LIB_VERSION (F("0.1.3")) #define LINEFORMATTER_LIB_VERSION (F("0.1.4"))
class LineFormatter: public Print class LineFormatter: public Print
@ -34,7 +34,7 @@ public:
// 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 n) { while (_pos < n) write(' '); return _pos; }; uint8_t gotoPos(uint8_t pos) { while (_pos < pos) write(' '); return _pos; };
// repeat a char or a "string" n times // repeat a char or a "string" n times

View File

@ -22,7 +22,7 @@ for absolute positions and **andRelTab(n)** for relative positions.
Absolute tab positions must be added in increasing order as the class does not Absolute tab positions must be added in increasing order as the class does not
check the input. Also adding same value twice is not checked for. The maximum check the input. Also adding same value twice is not checked for. The maximum
number of tabs is defined by **MAX_TAB_STOPS** == 10 default. This value canbe number of tabs is defined by **MAX_TAB_STOPS** == 12 default. This value can be
overruled by -D compile flag or edited in the LineFormatter.h file. overruled by -D compile flag or edited in the LineFormatter.h file.
Tab positions can be cleared by **clearTabs()**. This removes all tabs in one call. Tab positions can be cleared by **clearTabs()**. This removes all tabs in one call.
@ -54,24 +54,24 @@ Note: the maximum value is 255.
#### Printing #### Printing
- **size_t write(uint8_t c)** implements print. - **size_t write(uint8_t c)** implements print.
- **uint8_t gotoPos(uint8_t n)** if position is smaller than n, move to the right - **uint8_t gotoPos(uint8_t pos)** if position is smaller than pos, move to the right.
- **void repeat(uint8_t n, char c, uint8_t newLine = 0)** repeat a char n times - **void repeat(uint8_t n, char c, uint8_t newLine = 0)** repeat a char n times.
- **void repeat(uint8_t n, const char\* str, uint8_t newLine = 0)** repeat a "string" n times - **void repeat(uint8_t n, const char\* str, uint8_t newLine = 0)** repeat a "string" n times.
#### Tab configuration #### Tab configuration
- **bool addTab(uint8_t n)** Add a tab at an absolute position. returns true on success - **bool addTab(uint8_t n)** Add a tab at an absolute position. Returns true on success.
- **bool addRelTab(uint8_t n)** Add a tab at a relative position. returns true on success - **bool addRelTab(uint8_t n)** Add a tab at a relative position. Returns true on success.
- **void clearTabs()** remove all the tabs. - **void clearTabs()** remove all the tabs.
- **void tab(uint8_t n = 1)** print zero or more tabs, similar as e.g. "\t\t\t" - **void tab(uint8_t n = 1)** print zero or more tabs, similar as e.g. "\t\t\t"
#### Line configuration #### Line configuration
- **void setMaxLength(uint8_t maxPos)** set the maximum line length - bold cut off - **void setMaxLength(uint8_t maxPos)** set the maximum line length - bold cut off.
- **uint8_t getMaxLength()** return max line length set. - **uint8_t getMaxLength()** return max line length set.
- **void setAutoNewLine(uint8_t n)** n = 0 switches autoNewLine off - **void setAutoNewLine(uint8_t n)** n = 0 switches autoNewLine off.
- **uint8_t getAutoNewLine()** returns number of newlines. - **uint8_t getAutoNewLine()** returns number of newlines.
@ -79,11 +79,11 @@ Note: the maximum value is 255.
For debugging purposes there are the following functions: For debugging purposes there are the following functions:
- **uint8_t getPos()** returns current position - **uint8_t getPos()** returns current position.
- **void resetLineCount()** sets internal lineCounter to zero - **void resetLineCount()** sets internal lineCounter to zero.
- **uint16_t getLineCount()** returns current line number (since last reset) - **uint16_t getLineCount()** returns current line number (since last reset).
- **uint8_t getTabCount()** get the number of tab positions added. - **uint8_t getTabCount()** get the number of tab positions added.
- **uint8_t getTabStop(uint8_t n)** - **uint8_t getTabStop(uint8_t n)** returns the n-th tab position.
- **void printRuler()** prints a dotted line with 5 and 10 markers, and # for tab positions. - **void printRuler()** prints a dotted line with 5 and 10 markers, and # for tab positions.
@ -97,7 +97,13 @@ See examples
- improve documentation - improve documentation
- add examples - add examples
- add reset(); - add reset();
- check if print interface is completely covered.
- set defaults for functions - set defaults for functions
- add **rmTab(position)** - add **rmTab(position)**
- -
#### Wont
- check if print interface is completely covered.
- due to tab parsing it is, so no speed up.

View File

@ -1,11 +1,9 @@
// //
// FILE: LineFormatter_Ethernet.ino // FILE: LineFormatter_Ethernet.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo LineFormatter for EthernetClient // PURPOSE: demo LineFormatter for EthernetClient
// DATE: 2020-05-23 // DATE: 2020-05-23
// URL: https://github.com/RobTillaart/LineFormatter // URL: https://github.com/RobTillaart/LineFormatter
//
#include <LineFormatter.h> #include <LineFormatter.h>

View File

@ -1,11 +1,9 @@
// //
// FILE: LineFormatter_SDcard.ino // FILE: LineFormatter_SDcard.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo LineFormatter for SDcard // PURPOSE: demo LineFormatter for SDcard
// DATE: 2020-05-23 // DATE: 2020-05-23
// URL: https://github.com/RobTillaart/LineFormatter // URL: https://github.com/RobTillaart/LineFormatter
//
#include <SPI.h> #include <SPI.h>
@ -15,7 +13,7 @@
// MISO 12 // MISO 12
// CLOCK 13 // CLOCK 13
// CS 10 // CS 10
#define CS 10 // adjust this ChipSelect line if needed ! #define CS 10 // adjust this ChipSelect line if needed !
#include <LineFormatter.h> #include <LineFormatter.h>

View File

@ -1,18 +1,15 @@
// //
// FILE: LineFormatter_test_repeat.ino // FILE: LineFormatter_test_repeat.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo LineFormatter class // PURPOSE: demo LineFormatter class
// URL: https://github.com/RobTillaart/LineFormatter // URL: https://github.com/RobTillaart/LineFormatter
//
// HISTORY:
// 0.1.0 2020-05-14 initial version
//
#include "LineFormatter.h" #include "LineFormatter.h"
LineFormatter L; LineFormatter L;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -29,17 +26,19 @@ void setup()
L.println("Done..."); L.println("Done...");
} }
void loop() void loop()
{ {
} }
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
void test_repeat() void test_repeat()
{ {
L.println(); L.println();
L.println(__FUNCTION__); L.println(__FUNCTION__);
L.repeat(strlen(__FUNCTION__), "=", 2); L.repeat(strlen(__FUNCTION__), "=", 2);
L.repeat(10, ">"); L.repeat(10, ">");
L.print(" REPEAT DEMO "); L.print(" REPEAT DEMO ");
@ -57,12 +56,12 @@ void test_repeat()
L.repeat(3, '\n'); L.repeat(3, '\n');
} }
void test_graph() void test_graph()
{ {
L.println(); L.println();
L.println(__FUNCTION__); L.println(__FUNCTION__);
L.repeat(strlen(__FUNCTION__), "=", 2); L.repeat(strlen(__FUNCTION__), "=", 2);
for (int i = 0; i < 30; i++) for (int i = 0; i < 30; i++)
{ {
@ -73,11 +72,12 @@ void test_graph()
L.repeat(3, '\n'); L.repeat(3, '\n');
} }
void test_setMaxLength() void test_setMaxLength()
{ {
L.println(); L.println();
L.println(__FUNCTION__); L.println(__FUNCTION__);
L.repeat(strlen(__FUNCTION__), "=", 2); L.repeat(strlen(__FUNCTION__), "=", 2);
L.setMaxLength(20); L.setMaxLength(20);
@ -88,3 +88,4 @@ void test_setMaxLength()
// -- END OF FILE -- // -- END OF FILE --

View File

@ -1,13 +1,8 @@
// //
// FILE: LineFormatter_test_table.ino // FILE: LineFormatter_test_table.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo LineFormatter class // PURPOSE: demo LineFormatter class
// URL: https://github.com/RobTillaart/LineFormatter // URL: https://github.com/RobTillaart/LineFormatter
//
// HISTORY:
// 0.1.0 2020-05-14 initial version
//
#include "LineFormatter.h" #include "LineFormatter.h"
@ -46,7 +41,7 @@ void test_ruler()
{ {
L.println(); L.println();
L.println(__FUNCTION__); L.println(__FUNCTION__);
L.repeat(strlen(__FUNCTION__), "=", 2); L.repeat(strlen(__FUNCTION__), "=", 2);
L.clearTabs(); L.clearTabs();
L.addTab(3); L.addTab(3);
@ -71,7 +66,7 @@ void test_table_1()
{ {
L.println(); L.println();
L.println(__FUNCTION__); L.println(__FUNCTION__);
L.repeat(strlen(__FUNCTION__), "=", 2); L.repeat(strlen(__FUNCTION__), "=", 2);
L.clearTabs(); L.clearTabs();
L.addTab(3); L.addTab(3);
@ -129,7 +124,7 @@ void test_table_2()
{ {
L.println(); L.println();
L.println(__FUNCTION__); L.println(__FUNCTION__);
L.repeat(strlen(__FUNCTION__), "=", 2); L.repeat(strlen(__FUNCTION__), "=", 2);
L.clearTabs(); L.clearTabs();
L.addTab(3); L.addTab(3);

View File

@ -26,6 +26,7 @@ printRuler KEYWORD2
# Constants (LITERAL1) # Constants (LITERAL1)
MAX_TAB_STOPS LITERAL1
LINEFORMATTER_LIB_VERSION LITERAL1 LINEFORMATTER_LIB_VERSION LITERAL1
MAX_TAB_STOPS LITERAL1

View File

@ -15,8 +15,9 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/LineFormatter.git" "url": "https://github.com/RobTillaart/LineFormatter.git"
}, },
"version": "0.1.3", "version": "0.1.4",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*" "platforms": "*",
"headers": "LineFormatter.h"
} }

View File

@ -1,5 +1,5 @@
name=LineFormatter name=LineFormatter
version=0.1.3 version=0.1.4
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=Wrapper class for Serial to enhance layout of tabular data. sentence=Wrapper class for Serial to enhance layout of tabular data.

View File

@ -39,6 +39,7 @@
unittest_setup() unittest_setup()
{ {
fprintf(stderr, "LINEFORMATTER_LIB_VERSION: %s\n", (char*) LINEFORMATTER_LIB_VERSION);
} }
unittest_teardown() unittest_teardown()
@ -48,8 +49,6 @@ unittest_teardown()
unittest(test_constructor) unittest(test_constructor)
{ {
fprintf(stderr, "LINEFORMATTER_LIB_VERSION: %s\n", (char*) LINEFORMATTER_LIB_VERSION);
LineFormatter Line; LineFormatter Line;
assertEqual(0, Line.getMaxLength()); assertEqual(0, Line.getMaxLength());