//----------------------------------------------------------------------------- // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- #ifndef __ANSI_H #define __ANSI_H // Not ANSI but dirty trick to specify we don't want a \n #define NOLF "\xff" #define AEND "\x1b[0m" #define _CLEAR_ "\x1b[2J" #define _CLEAR_SCROLLBACK_ "\x1b[3J" #define _TOP_ "\x1b[1;1f" // erase from cursor to end of line #define _CLR_ "\x1b[0K" // erase the entire current line, cursor column is unchanged #define _CLR_LINE_ "\x1b[2K" // erase from cursor to end of screen #define _CLR_EOS_ "\x1b[J" // cursor control. The ones taking a count / row are format strings and need an int arg #define _CURSOR_HIDE_ "\x1b[?25l" #define _CURSOR_SHOW_ "\x1b[?25h" #define _CURSOR_HOME_ "\x1b[H" // move to row 1, col 1 #define _CURSOR_ROW_ "\x1b[%d;1H" // move to row %d, col 1 #define _CURSOR_UP_ "\x1b[%dA" // move up %d rows // DEC private mode 2026, synchronized output. Terminals which support it hold // the frame back until _SYNC_OFF_, terminals which don't ignore both #define _SYNC_ON_ "\x1b[?2026h" #define _SYNC_OFF_ "\x1b[?2026l" #define ANSI_BOLD "\x1b[1m" #define ANSI_DIM "\x1b[2m" #define ANSI_BLACK "\x1b[30m" #define ANSI_RED "\x1b[31m" #define ANSI_GREEN "\x1b[32m" #define ANSI_YELLOW "\x1b[33m" #define ANSI_BLUE "\x1b[34m" #define ANSI_MAGENTA "\x1b[35m" #define ANSI_CYAN "\x1b[36m" #define ANSI_WHITE "\x1b[37m" #define _BLACK_(s) ANSI_BLACK s AEND #define _RED_(s) ANSI_RED s AEND #define _GREEN_(s) ANSI_GREEN s AEND #define _YELLOW_(s) ANSI_YELLOW s AEND #define _BLUE_(s) ANSI_BLUE s AEND #define _MAGENTA_(s) ANSI_MAGENTA s AEND #define _CYAN_(s) ANSI_CYAN s AEND #define _WHITE_(s) ANSI_WHITE s AEND #define ANSI_BRIGHT_BLACK "\x1b[30;1m" #define ANSI_BRIGHT_RED "\x1b[31;1m" #define ANSI_BRIGHT_GREEN "\x1b[32;1m" #define ANSI_BRIGHT_YELLOW "\x1b[33;1m" #define ANSI_BRIGHT_BLUE "\x1b[34;1m" #define ANSI_BRIGHT_MAGENTA "\x1b[35;1m" #define ANSI_BRIGHT_CYAN "\x1b[36;1m" #define ANSI_BRIGHT_WHITE "\x1b[37;1m" // 24-bit truecolor foreground, needs three int args (r, g, b) #define ANSI_FG_RGB "\x1b[38;2;%d;%d;%dm" #define _BRIGHT_BLACK_(s) ANSI_BRIGHT_BLACK s AEND #define _BRIGHT_RED_(s) ANSI_BRIGHT_RED s AEND #define _BRIGHT_GREEN_(s) ANSI_BRIGHT_GREEN s AEND #define _BRIGHT_YELLOW_(s) ANSI_BRIGHT_YELLOW s AEND #define _BRIGHT_BLUE_(s) ANSI_BRIGHT_BLUE s AEND #define _BRIGHT_MAGENTA_(s) ANSI_BRIGHT_MAGENTA s AEND #define _BRIGHT_CYAN_(s) ANSI_BRIGHT_CYAN s AEND #define _BRIGHT_WHITE_(s) ANSI_BRIGHT_WHITE s AEND #define _BACK_BLACK_(s) "\x1b[40m" s AEND #define _BACK_RED_(s) "\x1b[41m" s AEND #define _BACK_GREEN_(s) "\x1b[42m" s AEND #define _BACK_YELLOW_(s) "\x1b[43m" s AEND #define _BACK_BLUE_(s) "\x1b[44m" s AEND #define _BACK_MAGENTA_(s) "\x1b[45m" s AEND #define _BACK_CYAN_(s) "\x1b[46m" s AEND #define _BACK_WHITE_(s) "\x1b[47m" s AEND #define _BACK_BRIGHT_BLACK_(s) "\x1b[40;1m" s AEND #define _BACK_BRIGHT_RED_(s) "\x1b[41;1m" s AEND #define _BACK_BRIGHT_GREEN_(s) "\x1b[42;1m" s AEND #define _BACK_BRIGHT_YELLOW_(s) "\x1b[43;1m" s AEND #define _BACK_BRIGHT_BLUE_(s) "\x1b[44;1m" s AEND #define _BACK_BRIGHT_MAGENTA_(s) "\x1b[45;1m" s AEND #define _BACK_BRIGHT_CYAN_(s) "\x1b[46;1m" s AEND #define _BACK_BRIGHT_WHITE_(s) "\x1b[47;1m" s AEND #if defined(HAVE_READLINE) // https://wiki.hackzine.org/development/misc/readline-color-prompt.html // Applications may indicate that the prompt contains // characters that take up no physical screen space when displayed by // bracketing a sequence of such characters with the special markers // RL_PROMPT_START_IGNORE = '\001' and RL_PROMPT_END_IGNORE = '\002' #define RL_ESC(a) "\001" a "\002" #else #define RL_ESC(a) a #endif // HAVE_READLINE #define _RL_RED_(s) RL_ESC("\x1b[31m") s RL_ESC(AEND) #define _RL_GREEN_(s) RL_ESC("\x1b[32m") s RL_ESC(AEND) #define _RL_BOLD_RED_(s) RL_ESC("\x1b[1;31m") s RL_ESC(AEND) #define _RL_BOLD_GREEN_(s) RL_ESC("\x1b[1;32m") s RL_ESC(AEND) #define _URL_(url, text) "\x1b]8;;" url "\x1b\\" text "\x1b]8;;\x1b\\" #endif