matyalatte / tuw

Tiny GUI wrapper for command-line tools
MIT License
23 stars 2 forks source link

Support colorized outputs on Linux #44

Closed matyalatte closed 2 weeks ago

matyalatte commented 3 weeks ago

Related to #35. Added support for some ANSI escape sequences (\e[XXm) on GTK window. You can use bold, italic, underline, strikethrough, and colors.

ANSI on Linux

#!/bin/bash
# test.sh

cases=(
  $'\033[1mBold text\033[0m'                             # Bold text
  $'\033[3mItalic text\033[0m'                           # Italic text
  $'\033[4mUnderlined text\033[0m'                       # Underlined text
  $'\033[9mStrikethrough text\033[0m'                    # Strikethrough text
  $'\033[31mRed foreground\033[0m'                       # Red foreground
  $'\033[44mBlue background\033[0m'                      # Blue background
  $'\033[1;32mBold Green foreground\033[0m'              # Bold + Green foreground
  $'\033[1;41mBold Red on Red background\033[0m'         # Bold + Red background
  $'\033[1;3;4;9;34mBold Italic Underlined Strikethrough Blue\033[0m'  # Multiple styles
  $'Regular text with \033[1msome bold\033[0m and \033[4munderline\033[0m.' # Mixed styles
  $'\033[31mRed & Blue\033[34m combination\033[0m'       # Mixed colors
  $'Special characters: & < > \' "'                      # Special characters that need escaping
  $'\033[31mRed multiline'
  $'Red multiline\033[0m'
)

for case in "${cases[@]}"; do
  echo "$case"
  sleep 0.1
done