ansi 1.4.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,49 +0,0 @@
1
- = ANSI::Code
2
-
3
- Require the library.
4
-
5
- require 'ansi/code'
6
-
7
- ANSI::Code can be used as a functions module.
8
-
9
- str = ANSI::Code.red + "Hello" + ANSI::Code.blue + "World"
10
- str.assert == "\e[31mHello\e[34mWorld"
11
-
12
- If a block is supplied to each method then yielded value will
13
- be wrapped in the ANSI code and clear code.
14
-
15
- str = ANSI::Code.red{ "Hello" } + ANSI::Code.blue{ "World" }
16
- str.assert == "\e[31mHello\e[0m\e[34mWorld\e[0m"
17
-
18
- More conveniently the ANSI::Code module extends ANSI itself.
19
-
20
- str = ANSI.red + "Hello" + ANSI.blue + "World"
21
- str.assert == "\e[31mHello\e[34mWorld"
22
-
23
- str = ANSI.red{ "Hello" } + ANSI.blue{ "World" }
24
- str.assert == "\e[31mHello\e[0m\e[34mWorld\e[0m"
25
-
26
- In the appropriate context the ANSI::Code module can also be
27
- included, making its methods directly accessible.
28
-
29
- include ANSI::Code
30
-
31
- str = red + "Hello" + blue + "World"
32
- str.assert == "\e[31mHello\e[34mWorld"
33
-
34
- str = red{ "Hello" } + blue{ "World" }
35
- str.assert == "\e[31mHello\e[0m\e[34mWorld\e[0m"
36
-
37
- Along with the single font colors, the library include background colors.
38
-
39
- str = on_red + "Hello"
40
- str.assert == "\e[41mHello"
41
-
42
- As well as combined color methods.
43
-
44
- str = white_on_red + "Hello"
45
- str.assert == "\e[37m\e[41mHello"
46
-
47
- The ANSI::Code module supports most standard ANSI codes, though
48
- not all platforms support every code, so YMMV.
49
-
@@ -1,31 +0,0 @@
1
- = ANSI::Logger
2
-
3
- Require the ANSI::Logger library.
4
-
5
- require 'ansi/logger'
6
-
7
- Create a new ANSI::Logger
8
-
9
- log = ANSI::Logger.new(STDOUT)
10
-
11
- Info logging appears normal.
12
-
13
- log.info{"Info logs are green.\n"}
14
-
15
- Warn logging appears yellow.
16
-
17
- log.warn{"Warn logs are yellow.\n"}
18
-
19
- Debug logging appears cyan.
20
-
21
- log.debug{"Debug logs are cyan.\n"}
22
-
23
- Error logging appears red.
24
-
25
- log.error{"Error logs are red.\n"}
26
-
27
- Fatal logging appears bright red.
28
-
29
- log.fatal{"Fatal logs are bold red!\n"}
30
-
31
- QED.
@@ -1,63 +0,0 @@
1
- = ANSI::Progressbar
2
-
3
- Pretty progress bars are easy to construct.
4
-
5
- require 'ansi/progressbar'
6
-
7
- pbar = ANSI::Progressbar.new("Test Bar", 100)
8
-
9
- Running the bar simply requires calling the #inc method during
10
- a loop and calling #finish when done.
11
-
12
- 100.times do |i|
13
- sleep 0.01
14
- pbar.inc
15
- end
16
- pbar.finish
17
-
18
- We will use this same rountine in all the examples below, so lets
19
- make a quick macro for it. Notice we have to use #reset first
20
- before reusing the same progress bar.
21
-
22
- def run(pbar)
23
- pbar.reset
24
- 100.times do |i|
25
- sleep 0.01
26
- pbar.inc
27
- end
28
- pbar.finish
29
- puts
30
- end
31
-
32
- The progress bar can be stylized in almost any way.
33
- The #format setter provides control over the parts
34
- that appear on the line. For example, by default the
35
- format is:
36
-
37
- pbar.format("%-14s %3d%% %s %s", :title, :percentage, :bar, :stat)
38
-
39
- So lets vary it up to demonstrate the case.
40
-
41
- pbar.format("%-14s %3d%% %s %s", :title, :percentage, :stat, :bar)
42
- run(pbar)
43
-
44
- The progress bar has an extra build in format intended for use with
45
- file downloads called #transer_mode.
46
-
47
- pbar.transfer_mode
48
- run(pbar)
49
-
50
- Calling this methods is the same as calling:
51
-
52
- pbar.format("%-14s %3d%% %s %s",:title, :percentage, :bar, :stat_for_file_transfer)
53
- run(pbar)
54
-
55
- The #style setter allows each part of the line be modified with ANSI codes. And the
56
- #bar_mark writer can be used to change the character used to make the bar.
57
-
58
- pbar.standard_mode
59
- pbar.style(:title => [:red], :bar=>[:blue])
60
- pbar.bar_mark = "="
61
- run(pbar)
62
-
63
- QED.
@@ -1,90 +0,0 @@
1
- = ANSI::Columns
2
-
3
- The +Columns+ class makes it easy to create nice looking text columns,
4
- sorted from top to bottom, right to left (as opposed to the other way
5
- around).
6
-
7
- require 'ansi/columns'
8
-
9
- list = %w{a b c d e f g h i j k l}
10
-
11
- columns = ANSI::Columns.new(list)
12
-
13
- columns.to_s(4)
14
-
15
- The output will be:
16
-
17
- a d g j
18
- b e h k
19
- c f i l
20
-
21
- Besides an array of elements, Columns.new can take a string in which
22
- the elements are divided by newlines characters. The default column
23
- size can also be given to the initializer.
24
-
25
- list = "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl"
26
-
27
- columns = ANSI::Columns.new(list, :columns=>6)
28
-
29
- columns.to_s
30
-
31
- The output will be:
32
-
33
- a c e g i k
34
- b d f h j l
35
-
36
- If the column count is +nil+, then the number of columns will be calculated
37
- as a best fit for the current terminal window.
38
-
39
- == Padding
40
-
41
- Columns can adjust the padding between cells.
42
-
43
- list = %w{a b c d e f g h i j k l}
44
-
45
- columns = ANSI::Columns.new(list, :padding=>2)
46
-
47
- columns.to_s(4)
48
-
49
- The output will be:
50
-
51
- a d g j
52
- b e h k
53
- c f i l
54
-
55
- == Alignment
56
-
57
- Columns can also be aligned either left or right.
58
-
59
- list = %w{xx xx xx yy y yy z zz z}
60
-
61
- columns = ANSI::Columns.new(list, :align=>:right)
62
-
63
- columns.to_s(3)
64
-
65
- The output will be:
66
-
67
- xx yy z
68
- xx y zz
69
- xx yy z
70
-
71
- == Format
72
-
73
- Lastly, columns can be augmented with ANSI codes. This is done through
74
- a formatting block. The block can take up to three parameters, the cell
75
- content, the column and row numbers, or the cell and the column and row
76
- numbers.
77
-
78
- list = %w{a b c d e f g h i j k l}
79
-
80
- columns = ANSI::Columns.new(list){ |c,r| r % 2 == 0 ? :red : :blue }
81
-
82
- out = columns.to_s(4)
83
-
84
- out.assert == (
85
- "\e[31ma \e[0m\e[31md \e[0m\e[31mg \e[0m\e[31mj \e[0m\n" +
86
- "\e[34mb \e[0m\e[34me \e[0m\e[34mh \e[0m\e[34mk \e[0m\n" +
87
- "\e[31mc \e[0m\e[31mf \e[0m\e[31mi \e[0m\e[31ml \e[0m\n"
88
- )
89
-
90
- QED.
@@ -1,28 +0,0 @@
1
- = ANSI::Table
2
-
3
- The ANSI::Table class can be used to output tabular data with nicely
4
- formated ASCII cell borders.
5
-
6
- require 'ansi/table'
7
-
8
- The constructor takes an 2-dimensional array.
9
-
10
- data = [
11
- [ 10, 20, 30 ],
12
- [ 20, 10, 20 ],
13
- [ 50, 40, 20 ]
14
- ]
15
-
16
- table = ANSI::Table.new(data)
17
-
18
- table.to_s
19
-
20
- The output will be:
21
-
22
- +----+----+----+
23
- | 10 | 20 | 30 |
24
- | 20 | 10 | 20 |
25
- | 50 | 40 | 20 |
26
- +----+----+----+
27
-
28
-
@@ -1,47 +0,0 @@
1
- = ANSI::Diff
2
-
3
- require 'ansi/diff'
4
-
5
- a = 'abcYefg'
6
- b = 'abcXefg'
7
-
8
- diff = ANSI::Diff.new(a,b)
9
-
10
- diff.to_s.assert == "\e[31mabc\e[0m\e[33mYefg\e[0m\n\e[31mabc\e[0mXefg"
11
-
12
- Try another.
13
-
14
- a = 'abc'
15
- b = 'abcdef'
16
-
17
- diff = ANSI::Diff.new(a,b)
18
-
19
- diff.to_s.assert == "\e[31mabc\e[0m\n\e[31mabc\e[0mdef"
20
-
21
- And another.
22
-
23
- a = 'abcXXXghi'
24
- b = 'abcdefghi'
25
-
26
- diff = ANSI::Diff.new(a,b)
27
-
28
- diff.to_s.assert == "\e[31mabc\e[0m\e[33mXXXghi\e[0m\n\e[31mabc\e[0mdefghi"
29
-
30
- And another.
31
-
32
- a = 'abcXXXdefghi'
33
- b = 'abcdefghi'
34
-
35
- diff = ANSI::Diff.new(a,b)
36
-
37
- diff.to_s.assert == "\e[31mabc\e[0m\e[33mXXX\e[0m\e[35mdefghi\e[0m\n\e[31mabc\e[0m\e[35mdefghi\e[0m"
38
-
39
- Comparison that is mostly different.
40
-
41
- a = 'abcpppz123'
42
- b = 'abcxyzzz43'
43
-
44
- diff = ANSI::Diff.new(a,b)
45
-
46
- diff.to_s.assert == "\e[31mabc\e[0m\e[33mpppz123\e[0m\n\e[31mabc\e[0mxyzzz43"
47
-
@@ -1,24 +0,0 @@
1
- = ANSI::BBCode
2
-
3
- The BBCode module provides methods for converting between
4
- BBCodes, basic HTML and ANSI codes.
5
-
6
- require 'ansi/bbcode'
7
-
8
- BBCodes are color and style codes in square brackets, quite
9
- popular with on line forums.
10
-
11
- bbcode = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
12
-
13
- We can convert this to ANSI code simply enough:
14
-
15
- ansi = ANSI::BBCode.bbcode_to_ansi(bbcode)
16
-
17
- ansi.assert == "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
18
-
19
- In addition the BBCode module supports conversion to simple HTML.
20
-
21
- html = ANSI::BBCode.bbcode_to_html(bbcode)
22
-
23
- html.assert == "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
24
-
@@ -1,8 +0,0 @@
1
- = ANSI::Terminal
2
-
3
- We should be ables to get the terminal width via the `terminal_width` method.
4
-
5
- width = ANSI::Terminal.terminal_width
6
-
7
- Fixnum.assert === width
8
-