cprintf/Examples.md at master · ununhexium/cprintf · GitHub
Skip to content

Latest commit

 

History

History
220 lines (137 loc) · 3.99 KB

File metadata and controls

220 lines (137 loc) · 3.99 KB

At the time of writing these lines, Github doesn't support coloring.

You will need to either

  • checkout this repository, compile and run the demo.sh script
  • check out the Asciinema showcase, but they also have issues with the brighter colors, some styles, ...
  • get a better Markdown reader

Print any string by omitting the format

cprintf '' 'Whatever you want here!'

Whatever you want here!

Print multiple strings by omitting the format

cprintf '' 'Whatever you want here,' ' and there,' ' and some more..'

Whatever you want here, and there, and some more...

Specify a format to use colors with the long or the short notation

cprintf '{index=1 color=red}+{index=2 color=green}={index=3 color=blue}' 1 2 3
cprintf '{#r}+{#g}={#b}' 1 2 3
1+2=3

ANSI rainbow

Use either codes, single letters or words to describe a color.

cprintf '{%1#1}{%1#3}{%1#g}{%1#c}{%1#blue}{%1#magenta}' '█'

ANSI bright colors

Shows the color in a brighter variant.

cprintf '{%1#9}{%1#G}{%1#BLUE}' '█'

Foreground and background colors

cprintf '{#RED/YELLOW}' 'Warning!'
Warning!

Indexed arguments

Change the order of display or re-use a value.

cprintf '{%3}-{%2}={%1}' a b c

c-b=a

cprintf '{%3} {%2} {%1} {%2} {%3}' 1 2 3

3 2 1 2 3

Unordered

The specifiers' order is not important

cprintf '{#red%1}' 'RED'

and

cprintf '{%1#red}' 'RED'

Are the same

RED

Unclutter

If the specifier for an item is getting cluttered, for instance

cprintf '{#yellow/magenta%1!strikethrough}' 'foo'

Take a deep breath, relax, and give yourself some space. Tabs are accepted.

cprintf '{ #yellow/magenta   %1   !strikethrough }' 'चक्र'
चक्र

New lines and other c-style escape sequences

cprintf 'a\nb\nc'
a
b
c

Literal brackets

cprintf '\{{#cyan}\}' 'value'
{value}

cprintf '{}' '{}'

{}


cprintf '\{}'

{}

Styles

Bold

cprintf '{style=bold}' BOLD
BOLD

Dimmed

cprintf '{style=dim}' dimmed
dimmed

Italic

cprintf '{style=italic}' Italic
Italic

Underline

cprintf '{style=underline}' '_-^Underlined^-_'
_-^Underlined^-_

Blink

This one may not show up as blinking on a web page but it sure blinks in the terminal 🌟

cprintf '{style=blink}' 'Hey!'
Hey!

Reversed

The foreground and background specs are inverted.

cprintf '{style=reverse color=red/yellow}' 'This shows yellow on red instead of red on yellow'
This shows yellow on red instead of red on yellow

Hidden

cprintf '->{style=hidden}<-' 'Hide and seek'
->Hide and seek<-

Strike through

cprintf '{style=strike color=red}' 'Wrong'
Wrong