Module: FANSI

Defined in:
lib/fansi/core.rb,
lib/fansi/version.rb

Overview

Helper methods to add colour to and manipulate console output. Designed to be mixed in with `include FANSI` or FANSI.method. Most of the methods need a block to be passed that returns a string. Can't handle nesting of text colours or nesting of background colours, for the sake of simplicity.

Constant Summary

CSI =
"\e["
CLR =
CSI + "0m"
CLRTC =
CSI + "39m"
CLRBG =
CSI + "49m"
CLEAR =
CSI + "1J"
SAVE =
CSI + "s"
RESTORE =
CSI + "u"
HIDE =
CSI + "?25l"
SHOW =
CSI + "?25h"
VERSION_MAJOR =
0
VERSION_MINOR =
1
VERSION_PATCH =
6
VERSION_ALIAS =
nil
VERSION =
[VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH]*?.
VERSION_STR =
"fansi " + ( VERSION_ALIAS || VERSION )
@@m =
false

Instance Method Summary (collapse)

Instance Method Details

- (Object) black



25
# File 'lib/fansi/core.rb', line 25

def black()      @@m?yield: CSI+"30m"+yield+CLRTC end


45
# File 'lib/fansi/core.rb', line 45

def blink()      @@m?yield: CSI+"5m"+yield+CSI+"25m" end

- (Object) blue



29
# File 'lib/fansi/core.rb', line 29

def blue()       @@m?yield: CSI+"34m"+yield+CLRTC end

- (Object) bold



43
# File 'lib/fansi/core.rb', line 43

def bold()       @@m?yield: CSI+"1m"+yield+CSI+"22m" end

- (Object) cursorless



49
# File 'lib/fansi/core.rb', line 49

def cursorless() @@m?yield: (print HIDE; yield; print SHOW) end

- (Object) cyan



31
# File 'lib/fansi/core.rb', line 31

def cyan()       @@m?yield: CSI+"36m"+yield+CLRTC end

- (Object) disable_fansi



56
# File 'lib/fansi/core.rb', line 56

def disable_fansi() @@m = true  end

- (Object) down(n = 1)



52
# File 'lib/fansi/core.rb', line 52

def down(n=1)    @@m?'': CSI+"#{n}B" end

- (Object) enable_fansi



57
# File 'lib/fansi/core.rb', line 57

def enable_fansi()  @@m = false end

- (Object) green



27
# File 'lib/fansi/core.rb', line 27

def green()      @@m?yield: CSI+"32m"+yield+CLRTC end

- (Object) insert



48
# File 'lib/fansi/core.rb', line 48

def insert()     @@m?yield: SAVE+yield+RESTORE end

- (Object) left(n = 1)



54
# File 'lib/fansi/core.rb', line 54

def left(n=1)    @@m?'': CSI+"#{n}D" end

- (Object) magenta



30
# File 'lib/fansi/core.rb', line 30

def magenta()    @@m?yield: CSI+"35m"+yield+CLRTC end

- (Object) negative



46
# File 'lib/fansi/core.rb', line 46

def negative()   @@m?yield: CSI+"7m"+yield+CSI+"27m" end

- (Object) on_black



34
# File 'lib/fansi/core.rb', line 34

def on_black()   @@m?yield: CSI+"40m"+yield+CLRBG end

- (Object) on_blue



38
# File 'lib/fansi/core.rb', line 38

def on_blue()    @@m?yield: CSI+"44m"+yield+CLRBG end

- (Object) on_cyan



40
# File 'lib/fansi/core.rb', line 40

def on_cyan()    @@m?yield: CSI+"46m"+yield+CLRBG end

- (Object) on_green



36
# File 'lib/fansi/core.rb', line 36

def on_green()   @@m?yield: CSI+"42m"+yield+CLRBG end

- (Object) on_magenta



39
# File 'lib/fansi/core.rb', line 39

def on_magenta() @@m?yield: CSI+"45m"+yield+CLRBG end

- (Object) on_red



35
# File 'lib/fansi/core.rb', line 35

def on_red()     @@m?yield: CSI+"41m"+yield+CLRBG end

- (Object) on_white



41
# File 'lib/fansi/core.rb', line 41

def on_white()   @@m?yield: CSI+"47m"+yield+CLRBG end

- (Object) on_yellow



37
# File 'lib/fansi/core.rb', line 37

def on_yellow()  @@m?yield: CSI+"43m"+yield+CLRBG end

- (Object) red



26
# File 'lib/fansi/core.rb', line 26

def red()        @@m?yield: CSI+"31m"+yield+CLRTC end

- (Object) right(n = 1)



53
# File 'lib/fansi/core.rb', line 53

def right(n=1)   @@m?'': CSI+"#{n}C" end

- (Object) underline



44
# File 'lib/fansi/core.rb', line 44

def underline()  @@m?yield: CSI+"4m"+yield+CSI+"24m" end

- (Object) up(n = 1)



51
# File 'lib/fansi/core.rb', line 51

def up(n=1)      @@m?'': CSI+"#{n}A" end

- (Object) white



32
# File 'lib/fansi/core.rb', line 32

def white()      @@m?yield: CSI+"37m"+yield+CLRTC end

- (Object) yellow



28
# File 'lib/fansi/core.rb', line 28

def yellow()     @@m?yield: CSI+"33m"+yield+CLRTC end