GY-63_MS5611/libraries/ANSI/ansi.h

156 lines
4.0 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: ansi.h
// AUTHOR: Rob Tillaart
2023-01-31 14:16:44 -05:00
// VERSION: 0.1.8
2021-01-29 06:31:58 -05:00
// PURPOSE: Arduino library to send ANSI escape sequences
// DATE: 2020-04-28
// URL: https://github.com/RobTillaart/ANSI
2021-10-18 10:35:48 -04:00
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2023-01-31 14:16:44 -05:00
#define ANSI_LIB_VERSION (F("0.1.8"))
2021-10-18 10:35:48 -04:00
2021-01-29 06:31:58 -05:00
class ANSI : public Stream
{
public:
ANSI(Stream * stream = &Serial);
2022-08-24 05:00:54 -04:00
// Stream interface
2021-01-29 06:31:58 -05:00
int available();
int read();
int peek();
2022-10-29 06:44:27 -04:00
void flush() { return; }; // placeholder to keep CI happy
2021-01-29 06:31:58 -05:00
2021-10-18 10:35:48 -04:00
2022-08-24 05:00:54 -04:00
// CHAR MODES
2021-01-29 06:31:58 -05:00
void normal() { print("\033[0m"); };
void bold() { print("\033[1m"); };
void low() { print("\033[2m"); };
void underline() { print("\033[4m"); };
void blink() { print("\033[5m"); };
void reverse() { print("\033[7m"); };
2021-10-18 10:35:48 -04:00
2022-08-24 05:00:54 -04:00
// COLOR
2021-01-29 06:31:58 -05:00
enum {
black = 0,
red,
green,
yellow,
blue,
magenta,
cyan,
white,
2022-10-29 06:44:27 -04:00
bright, // Add this to any of the previous 8 to get a bright color
2021-01-29 06:31:58 -05:00
};
2022-10-29 06:44:27 -04:00
// foreground, background, and color accept one of the following colors:
// * color name from above: ANSI::red
// * bright color name from above: ANSI::red + ANSI::bright
// * gray color: ANSI::gray2color(gray)
// * RGB color: ANSI::rgb2color(r, g, b)
2021-01-29 06:31:58 -05:00
2022-10-29 06:44:27 -04:00
// Set foreground color
2021-01-29 06:31:58 -05:00
void foreground(uint8_t fgcolor);
2022-10-29 06:44:27 -04:00
// Set background color
2021-01-29 06:31:58 -05:00
void background(uint8_t bgcolor);
2023-01-31 14:16:44 -05:00
// Set foreground and background color
2022-10-29 06:44:27 -04:00
// (for named colors, this is 25% faster than setting one then the other)
2021-01-29 06:31:58 -05:00
void color(uint8_t fgcolor, uint8_t bgcolor);
2022-10-29 06:44:27 -04:00
// Convert gray to ANSI 24-level gray in 4-bit colorspace
// Pass in a gray level from 0 (black) to 255 (white)
2021-01-29 06:31:58 -05:00
uint8_t gray2color(uint8_t gray) { return 232 + uint16_t(gray) * 24 / 256; }
uint8_t grey2color(uint8_t grey) { return this->gray2color(grey); }
2023-01-31 14:16:44 -05:00
2022-10-29 06:44:27 -04:00
// Convert RGB color to ANSI color in 4-bit colorspace
// Pass in a RGB level from 0 (dark) to 255 (light)
2021-01-29 06:31:58 -05:00
uint8_t rgb2color(uint8_t r, uint8_t g, uint8_t b);
2021-10-18 10:35:48 -04:00
2022-08-24 05:00:54 -04:00
// POSITIONING
2021-01-29 06:31:58 -05:00
enum {
toEnd = 0,
toStart = 1,
entireLine = 2,
};
void clearScreen();
void clearLine(uint8_t clear = toEnd);
2023-01-31 14:16:44 -05:00
void home();
2021-10-18 10:35:48 -04:00
2021-01-29 06:31:58 -05:00
void gotoXY(uint8_t x, uint8_t y);
void cursorUp(uint8_t x);
void cursorDown(uint8_t x);
void cursorForward(uint8_t x);
void cursorBack(uint8_t x);
2021-10-18 10:35:48 -04:00
2022-08-24 05:00:54 -04:00
// META
2023-01-31 14:16:44 -05:00
// deviceType is discussed
2022-08-24 05:00:54 -04:00
// - https://github.com/RobTillaart/ANSI/issues/9
2023-01-31 14:16:44 -05:00
// timeout in milliseconds.
2022-08-24 05:00:54 -04:00
// note this function blocks for timeout or less.
2023-01-31 14:16:44 -05:00
// -1 = unknown;
2022-08-24 05:00:54 -04:00
// 1 = VT52, 2 = VT100, 3 = VT220,
int deviceType(uint32_t timeout = 100);
// EXPERIMENTAL SECTION
// use at own risk
2023-01-31 14:16:44 -05:00
// check if it works on your terminal
// TERA
void set132columns() { print("\033[?3h"); }; // +
void set80columns() { print("\033[?3l"); }; // +
void moveWindowDown() { print("\033M"); }; // +
void moveWindowUp() { print("\033D"); }; // +
// PRINTING
void printScreen() { print("\033[i"); }; // +
// RESET terminal to initial state
void reset() { print("\033c"); }; // +
// NOT working on TERA TERM (or need testing)
// use at own risk
// check if it works on your terminal TERA
2022-08-24 05:00:54 -04:00
/*
void setSmoothScroll() { print("\033[?4h"); }; // -
void setJumpScroll() { print("\033[?4l"); }; // -
2023-01-31 14:16:44 -05:00
2022-08-24 05:00:54 -04:00
// to be used for password?
void invisible() { print("\033[8m"); }; // -
// PRINTING
// use at own risk
2023-01-31 14:16:44 -05:00
// check if it works on your terminal TERA
2022-08-24 05:00:54 -04:00
void printLine() { print("\033[1i"); }; // ?
void startPrintLog() { print("\033[4i"); }; // ?
void stopPrintLog() { print("\033[5i"); }; // ?
*/
2023-01-31 14:16:44 -05:00
2021-01-29 06:31:58 -05:00
private:
size_t write(uint8_t c);
2021-12-13 10:45:59 -05:00
size_t write(uint8_t * array, uint8_t length);
2023-01-31 14:16:44 -05:00
2021-01-29 06:31:58 -05:00
void color4(uint8_t base, uint8_t color);
void color4_code(uint8_t base, uint8_t color);
void colors4(uint8_t fgcolor, uint8_t bgcolor);
void color8(uint8_t base, uint8_t color);
2021-10-18 10:35:48 -04:00
Stream * _stream;
2021-01-29 06:31:58 -05:00
};
2022-10-29 06:44:27 -04:00
2023-01-31 14:16:44 -05:00
// -- END OF FILE --
2022-10-29 06:44:27 -04:00