All: add license comment.
also: change ansi implementation to be slightly less copyright-infringing.master
parent
323845a4f4
commit
2f14fffd5c
@ -1,99 +1,68 @@
|
||||
// https://github.com/iannisdezwart/flow/blob/main/formatting/ansi.hpp
|
||||
/*
|
||||
Terminal output sequences
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2021, Ruthenic
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define ANSI_CURSOR_UP(n) "\x1b[" #n "A"
|
||||
#define ANSI_CURSOR_DOWN(n) "\x1b[" #n "B"
|
||||
#define ANSI_CURSOR_FORWARD(n) "\x1b[" #n "C"
|
||||
#define ANSI_CURSOR_BACK(n) "\x1b[" #n "D"
|
||||
#define ANSI_CURSOR_NEXT_LINE(n) "\x1b[" #n "E"
|
||||
#define ANSI_CURSOR_PREV_LINE(n) "\x1b[" #n "F"
|
||||
#define ANSI_CURSOR_TO_COL(n) "\x1b[" #n "G"
|
||||
#define ANSI_CURSOR_TO(x, y) "\x1b[" #x ";" #y "H"
|
||||
#define ANSI_ERASE_DISPLAY(n) "\x1b[J"
|
||||
#define ANSI_ERASE_LINE(n) "\x1b[K"
|
||||
#define ANSI_SCROLL_UP(n) "\x1b[" #n "S"
|
||||
#define ANSI_SCROLL_DOWN(n) "\x1b[" #n "T"
|
||||
#define ANSI_BASE(n) "\e[" #n "m"
|
||||
|
||||
/*
|
||||
Rendition
|
||||
*/
|
||||
|
||||
// Basic SGR
|
||||
|
||||
#define ANSI_SGR(n) "\x1b[" #n "m"
|
||||
|
||||
// SGR effects
|
||||
#define ANSI_RESET ANSI_BASE(0)
|
||||
#define ANSI_BOLD ANSI_BASE(1)
|
||||
#define ANSI_FAINT ANSI_BASE(2)
|
||||
#define ANSI_ITALIC ANSI_BASE(3)
|
||||
#define ANSI_UNDERLINE ANSI_BASE(4)
|
||||
#define ANSI_BLINK ANSI_BASE(5)
|
||||
#define ANSI_REVERSE ANSI_BASE(7)
|
||||
#define ANSI_CROSSED ANSI_BASE(9)
|
||||
|
||||
#define ANSI_RESET ANSI_SGR(0)
|
||||
#define ANSI_BOLD ANSI_SGR(1)
|
||||
#define ANSI_FAINT ANSI_SGR(2)
|
||||
#define ANSI_ITALIC ANSI_SGR(3)
|
||||
#define ANSI_UNDERLINE ANSI_SGR(4)
|
||||
#define ANSI_BLINK ANSI_SGR(5)
|
||||
#define ANSI_REVERSE ANSI_SGR(7)
|
||||
#define ANSI_CROSSED ANSI_SGR(9)
|
||||
|
||||
// SGR disable effects
|
||||
|
||||
#define ANSI_DOUBLE_UNDERLINE ANSI_SGR(21)
|
||||
#define ANSI_DISABLE_BOLD ANSI_SGR(22)
|
||||
#define ANSI_DOUBLE_UNDERLINE ANSI_BASE(21)
|
||||
#define ANSI_DISABLE_BOLD ANSI_BASE(22)
|
||||
#define ANSI_DISABLE_FAINT ANSI_DISABLE_BOLD
|
||||
#define ANSI_DISABLE_ITALIC ANSI_SGR(23)
|
||||
#define ANSI_DISABLE_UNDERLINE ANSI_SGR(24)
|
||||
#define ANSI_DISABLE_BLINK ANSI_SGR(25)
|
||||
#define ANSI_DISABLE_REVERSE ANSI_SGR(27)
|
||||
#define ANSI_DISABLE_CROSSED ANSI_SGR(29)
|
||||
|
||||
#define ANSI_DEFAULT_FG ANSI_SGR(39)
|
||||
#define ANSI_DEFAULT_BG ANSI_SGR(49)
|
||||
|
||||
// Default foreground colours
|
||||
|
||||
#define ANSI_BLACK ANSI_SGR(30)
|
||||
#define ANSI_RED ANSI_SGR(31)
|
||||
#define ANSI_GREEN ANSI_SGR(32)
|
||||
#define ANSI_YELLOW ANSI_SGR(33)
|
||||
#define ANSI_BLUE ANSI_SGR(34)
|
||||
#define ANSI_MAGENTA ANSI_SGR(35)
|
||||
#define ANSI_CYAN ANSI_SGR(36)
|
||||
#define ANSI_WHITE ANSI_SGR(37)
|
||||
|
||||
// Default background colours
|
||||
|
||||
#define ANSI_BLACK_BG ANSI_SGR(40)
|
||||
#define ANSI_RED_BG ANSI_SGR(41)
|
||||
#define ANSI_GREEN_BG ANSI_SGR(42)
|
||||
#define ANSI_YELLOW_BG ANSI_SGR(43)
|
||||
#define ANSI_BLUE_BG ANSI_SGR(44)
|
||||
#define ANSI_MAGENTA_BG ANSI_SGR(45)
|
||||
#define ANSI_CYAN_BG ANSI_SGR(46)
|
||||
#define ANSI_WHITE_BG ANSI_SGR(47)
|
||||
|
||||
// Bright foreground colours
|
||||
|
||||
#define ANSI_BRIGHT_BLACK ANSI_SGR(90)
|
||||
#define ANSI_BRIGHT_RED ANSI_SGR(91)
|
||||
#define ANSI_BRIGHT_GREEN ANSI_SGR(92)
|
||||
#define ANSI_BRIGHT_YELLOW ANSI_SGR(93)
|
||||
#define ANSI_BRIGHT_BLUE ANSI_SGR(94)
|
||||
#define ANSI_BRIGHT_MAGENTA ANSI_SGR(95)
|
||||
#define ANSI_BRIGHT_CYAN ANSI_SGR(96)
|
||||
#define ANSI_BRIGHT_WHITE ANSI_SGR(97)
|
||||
|
||||
// Bright background colours
|
||||
|
||||
#define ANSI_BRIGHT_BLACK_BG ANSI_SGR(100)
|
||||
#define ANSI_BRIGHT_RED_BG ANSI_SGR(101)
|
||||
#define ANSI_BRIGHT_GREEN_BG ANSI_SGR(102)
|
||||
#define ANSI_BRIGHT_YELLOW_BG ANSI_SGR(103)
|
||||
#define ANSI_BRIGHT_BLUE_BG ANSI_SGR(104)
|
||||
#define ANSI_BRIGHT_MAGENTA_BG ANSI_SGR(105)
|
||||
#define ANSI_BRIGHT_CYAN_BG ANSI_SGR(106)
|
||||
#define ANSI_BRIGHT_WHITE_BG ANSI_SGR(107)
|
||||
|
||||
// 24-bit colour
|
||||
|
||||
#define ANSI_SET_COLOUR(r, g, b) "\x1b[38;2;" #r ";" #g ";" #b "m"
|
||||
#define ANSI_SET_BG_COLOUR(r, g, b) "\x1b[48;2;" #r ";" #g ";" #b "m"
|
||||
#define ANSI_DISABLE_ITALIC ANSI_BASE(23)
|
||||
#define ANSI_DISABLE_UNDERLINE ANSI_BASE(24)
|
||||
#define ANSI_DISABLE_BLINK ANSI_BASE(25)
|
||||
#define ANSI_DISABLE_REVERSE ANSI_BASE(27)
|
||||
#define ANSI_DISABLE_CROSSED ANSI_BASE(29)
|
||||
|
||||
#define ANSI_BLACK ANSI_BASE(30)
|
||||
#define ANSI_RED ANSI_BASE(31)
|
||||
#define ANSI_GREEN ANSI_BASE(32)
|
||||
#define ANSI_YELLOW ANSI_BASE(33)
|
||||
#define ANSI_BLUE ANSI_BASE(34)
|
||||
#define ANSI_MAGENTA ANSI_BASE(35)
|
||||
#define ANSI_CYAN ANSI_BASE(36)
|
||||
#define ANSI_WHITE ANSI_BASE(37)
|
||||
#define ANSI_BRIGHT_BLACK ANSI_BASE(90)
|
||||
#define ANSI_BRIGHT_RED ANSI_BASE(91)
|
||||
#define ANSI_BRIGHT_GREEN ANSI_BASE(92)
|
||||
#define ANSI_BRIGHT_YELLOW ANSI_BASE(93)
|
||||
#define ANSI_BRIGHT_BLUE ANSI_BASE(94)
|
||||
#define ANSI_BRIGHT_MAGENTA ANSI_BASE(95)
|
||||
#define ANSI_BRIGHT_CYAN ANSI_BASE(96)
|
||||
#define ANSI_BRIGHT_WHITE ANSI_BASE(97)
|
||||
|
Loading…
Reference in new issue