GY-63_MS5611/libraries/LineFormatter
2021-12-20 20:09:13 +01:00
..
.github/workflows 0.1.3 LineFormatter 2021-11-06 17:49:23 +01:00
examples 0.1.4 LineFormatter 2021-12-20 20:09:13 +01:00
test 0.1.4 LineFormatter 2021-12-20 20:09:13 +01:00
.arduino-ci.yml 0.1.3 LineFormatter 2021-11-06 17:49:23 +01:00
keywords.txt 0.1.4 LineFormatter 2021-12-20 20:09:13 +01:00
library.json 0.1.4 LineFormatter 2021-12-20 20:09:13 +01:00
library.properties 0.1.4 LineFormatter 2021-12-20 20:09:13 +01:00
LICENSE 0.1.4 LineFormatter 2021-12-20 20:09:13 +01:00
LineFormatter.cpp 0.1.4 LineFormatter 2021-12-20 20:09:13 +01:00
LineFormatter.h 0.1.4 LineFormatter 2021-12-20 20:09:13 +01:00
README.md 0.1.4 LineFormatter 2021-12-20 20:09:13 +01:00

Arduino CI Arduino-lint JSON check License: MIT GitHub release

LineFormatter

Arduino library to enhance the layout of tabular data on serial output,

Description

LineFormatter is a wrapper class for Serial (and other streams) to enhance layout of tabular data.

The class intercepts the TAB characters printed and replaces them with spaces to the next defined tab-position. These positions can be created with addTab(n) for absolute positions and andRelTab(n) for relative positions.

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 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.

Tab positions can be cleared by clearTabs(). This removes all tabs in one call.

The function autoNewLine(n) prints a newline after every n lines. This makes it easier to count the lines in a table. Setting n to 0 disables this function.

The function gotoPos(n) prints spaces until the cursor is on position n. Besides for tabular data, this function can be used to make simple text based graphs, e.g. a histogram (see examples).

The function repeat(n, s, nl) which repeats a certain character or a string n times. This is followed by nl newlines which is zero by default. repeat() is useful to make separator lines or to print several newlines at once.

The function setMaxLength(n) to cut off (brute force, no intelligence) lines after n characters by injecting an extra newline. This prevents scrolling hundreds of positions to the right e.g. when copying a file from disk to Serial. Setting the value to 0 results in no maximum line length. Note: the maximum value is 255.

Interface

  • LineFormatter(Print* stream = &Serial) constructor
  • reset() reset internal variables to start over again.

Printing

  • size_t write(uint8_t c) implements print.
  • 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, const char* str, uint8_t newLine = 0) repeat a "string" n times.

Tab configuration

  • 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.
  • void clearTabs() remove all the tabs.
  • void tab(uint8_t n = 1) print zero or more tabs, similar as e.g. "\t\t\t"

Line configuration

  • void setMaxLength(uint8_t maxPos) set the maximum line length - bold cut off.
  • uint8_t getMaxLength() return max line length set.
  • void setAutoNewLine(uint8_t n) n = 0 switches autoNewLine off.
  • uint8_t getAutoNewLine() returns number of newlines.

Debugging

For debugging purposes there are the following functions:

  • uint8_t getPos() returns current position.
  • void resetLineCount() sets internal lineCounter to zero.
  • uint16_t getLineCount() returns current line number (since last reset).
  • uint8_t getTabCount() get the number of tab positions added.
  • 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.

Operational

See examples

Future

  • improve documentation
  • add examples
  • add reset();
  • set defaults for functions
  • add rmTab(position)

Wont

  • check if print interface is completely covered.
    • due to tab parsing it is, so no speed up.