GY-63_MS5611/libraries/LineFormatter/LineFormatter.h

98 lines
2.3 KiB
C
Raw Normal View History

2020-05-17 04:37:41 -04:00
#pragma once
//
// FILE: LineFormatter.h
// AUTHOR: Rob Tillaart
2024-02-19 14:13:19 -05:00
// VERSION: 0.3.0
2021-11-06 12:49:23 -04:00
// PURPOSE: Simple positioning wrapper class for Serial / Stream
2020-05-17 04:37:41 -04:00
// DATE: 2020-05-14
// URL: https://github.com/RobTillaart/LineFormatter
2023-01-31 07:39:06 -05:00
2020-05-17 04:37:41 -04:00
#include "Arduino.h"
#include "Print.h"
#ifndef MAX_TAB_STOPS
2023-01-31 07:39:06 -05:00
#define MAX_TAB_STOPS 12
2020-05-17 04:37:41 -04:00
#endif
2024-02-19 14:13:19 -05:00
#define LINEFORMATTER_LIB_VERSION (F("0.3.0"))
2021-11-06 12:49:23 -04:00
2020-05-17 04:37:41 -04:00
class LineFormatter: public Print
{
public:
LineFormatter(Print* stream = &Serial);
2021-11-06 12:49:23 -04:00
void reset();
2024-02-19 14:13:19 -05:00
size_t write(uint8_t ch);
2020-05-17 04:37:41 -04:00
2021-11-06 12:49:23 -04:00
2022-11-14 14:50:36 -05:00
// set the maximum line length - bold cut off
2023-01-31 07:39:06 -05:00
void setMaxLength(uint8_t maxPos);
uint8_t getMaxLength();
2020-05-17 04:37:41 -04:00
2021-11-06 12:49:23 -04:00
2022-11-14 14:50:36 -05:00
// if position is smaller than n, move to the right
2024-02-19 14:13:19 -05:00
uint8_t gotoPos(uint8_t position);
2020-05-17 04:37:41 -04:00
2021-11-06 12:49:23 -04:00
2022-11-14 14:50:36 -05:00
// repeat a char or a "string" n times
// followed by 0 or more newlines.
2024-02-19 14:13:19 -05:00
void repeat(uint8_t n, char ch, uint8_t newLine = 0);
2021-01-29 06:31:58 -05:00
void repeat(uint8_t n, const char* str, uint8_t newLine = 0);
2020-05-17 04:37:41 -04:00
2021-11-06 12:49:23 -04:00
2022-11-14 14:50:36 -05:00
// n = 0 switches autoNewLine off
2023-01-31 07:39:06 -05:00
void setAutoNewLine(uint8_t n = 1);
uint8_t getAutoNewLine();
2020-05-17 04:37:41 -04:00
2021-11-06 12:49:23 -04:00
2024-02-19 14:13:19 -05:00
// Set the internal array of tabs at once, easy bulk config,
// positions is an increasing array.
bool setTabs(uint8_t * positions, uint8_t size);
// get array with positions.
uint8_t getTabs(uint8_t * positions);
// Add one tab at (absolute or relative) position
2022-11-14 14:50:36 -05:00
// returns true on success
2024-02-19 14:13:19 -05:00
bool addTab(uint8_t position);
2021-01-29 06:31:58 -05:00
bool addRelTab(uint8_t n);
2022-11-14 14:50:36 -05:00
// remove all the tabs,
2021-01-29 06:31:58 -05:00
void clearTabs();
2024-02-19 14:13:19 -05:00
// remove tab at position position
2023-01-31 07:39:06 -05:00
// returns false if it does not exist.
2024-02-19 14:13:19 -05:00
bool removeTab(uint8_t position);
bool existTab(uint8_t position);
2023-01-31 07:39:06 -05:00
2022-11-14 14:50:36 -05:00
// print zero or more tabs, similar as e.g. "\t\t\t"
2023-01-31 07:39:06 -05:00
// optimized repeat
void tab(uint8_t n = 1);
2020-05-17 04:37:41 -04:00
2023-01-31 07:39:06 -05:00
// MISCELLANEOUS
uint8_t getPos();
void resetLineCount();
uint32_t getLineCount();
uint8_t getTabCount();
uint8_t getTabStop(uint8_t n);
void printRuler(uint8_t length);
2020-05-17 04:37:41 -04:00
2021-11-06 12:49:23 -04:00
2020-05-17 04:37:41 -04:00
private:
Print * _stream;
2021-11-06 12:49:23 -04:00
2021-01-29 06:31:58 -05:00
uint8_t _pos = 0;
uint8_t _maxPos = 0;
2023-01-31 07:39:06 -05:00
uint32_t _lineCount = 0;
uint8_t _anl = 0; // counter
uint8_t _autoNewLine = 0; // position for the newline.
2020-05-17 04:37:41 -04:00
uint8_t _tabStop[MAX_TAB_STOPS];
uint8_t _tabCount = 0;
};
2021-11-06 12:49:23 -04:00
2023-01-31 07:39:06 -05:00
// -- END OF FILE --
2021-11-06 12:49:23 -04:00