From e4e190afb13fb5da2d3fcfb72d2e484a330a3324 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 18 Jun 2018 23:05:20 +1000 Subject: [PATCH] started working on escape sequences --- README.md | 31 +++++++++++++++++++++++++++++++ test.sh | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5728edf..2d6d71c 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,9 @@ Any donations are appreciated, they give me the time to make this the best resou * [Get the terminal size in lines and columns (*from a script*).](#get-the-terminal-size-in-lines-and-columns-from-a-script) * [Get the terminal size in pixels.](#get-the-terminal-size-in-pixels) * [Get the current cursor position.](#get-the-current-cursor-position) +* [Escape Sequences](#escape-sequences) + * [Text Colors.](#text-colors) + * [Text Attributes.](#text-attributes) * [Colors](#colors) * [Convert a hex color to RGB.](#convert-a-hex-color-to-rgb) * [Convert an RGB color to hex.](#convert-an-rgb-color-to-hex) @@ -1290,6 +1293,34 @@ $ get_cursor_pos 1 8 ``` +# Escape Sequences + +Contrary to popular belief, there's no issue in using raw escape sequences. Using `tput` just abstracts the same ANSI escape sequences. What's worse is that `tput` isn't actually portable, there are a number of different `tput` variants on different Operating Systems each with different commands (*try and run `tput setaf 3` on a FreeBSD system*). The easiest solution ends up being raw ANSI sequences. + +## Text Colors. + +| Sequence | What does it do? | Value | +| -------- | ---------------- | ----- | +| `\e[38;5;m` | Set text foreground color. | `0-255` +| `\e[48;5;m` | Set text background color. | `0-255` +| `\e[38;2;;;m` | Set text foreground color to RGB color. | `R`, `G`, `B` +| `\e[48;2;;;m` | Set text background color to RGB color. | `R`, `G`, `B` + +## Text Attributes. + +| Sequence | What does it do? | +| -------- | ---------------- | +| `\e[m` | Reset text formatting and colors. +| `\e[1m` | Bold text. | +| `\e[2m` | Faint text. | +| `\e[3m` | Italic text. | +| `\e[4m` | Underline text. | +| `\e[5m` | Slow blink. | +| `\e[5m` | Slow blink. | +| `\e[7m` | Swap foreground and background colors. | + + + # Colors ## Convert a hex color to RGB. diff --git a/test.sh b/test.sh index ca72dd3..7797ccd 100755 --- a/test.sh +++ b/test.sh @@ -158,7 +158,7 @@ assert_equals() { else ((fail+=1)) status=$'\e[31m✖' - err="($1 != $2)" + local err="($1 != $2)" fi printf ' %s\e[m | %s\n' "$status" "${FUNCNAME[1]/test_} $err"