ansi 1.5.0 → 1.6.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9f5b1f6fd3401e6decd1a197dbafccb09c26ef4b
4
- data.tar.gz: 547321348ddb0810254e3eaf637e6946fe9bc9d3
2
+ SHA256:
3
+ metadata.gz: 4a6496d2daa294d5dbb0a2d8d6f0d4f6ccd48138d5f94028b752352318a49223
4
+ data.tar.gz: a521c650775d506060b45d5dce7222f397563f243a33d283e2c8badccb77bec0
5
5
  SHA512:
6
- metadata.gz: 78175712b13ffe59c2a7f306705f10da169e487e51fa954982de920d468b622ca96c6a35cb7fd73585a5c0d8df5ba07fc5ba8eb0731162c4ed09cba01331335f
7
- data.tar.gz: 2355b8d58eb75ccfd4f9e61c4c225358a7362021e14ea6abae99436d91327edc541f877447567573b91f61b77cc7833051d7bd20738ba2d832dab142c8c56815
6
+ metadata.gz: 6e49732e6828f3d2ee511c62ff3bec628acdc10626cf18fa4dd5b88f935ff14985937faca2e646d463cc13e98e5db90079758ae59088e10ff06776cfda0439a1
7
+ data.tar.gz: 4db6103bde45ff0556a917cc851ec1c4dc463d5031813d05dcbf4855f72e7212b2ab6eb0542b360f0ec81e40885f321f00b5a25f5cef868c1b70b63cd9fb5945
data/HISTORY.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # RELEASE HISTORY
2
2
 
3
+ ## 1.6.1 | 2026-11-20
4
+
5
+ Fixes loading on Ruby 4.0, color on Windows, and two wrong codes.
6
+
7
+ Changes:
8
+
9
+ * Stop asking for the win32console gem on Windows. Windows hasn't needed
10
+ it since Ruby 2.0, but without it ANSI printed a warning and turned
11
+ color off. (Darunada, #35; reported in #36)
12
+ * Correct the codes for `inverse_off` and `positive`, now 27, and for
13
+ `conceal_off`, `show` and `reveal`, now 28. They were 26 and 27, so
14
+ `inverse_off` did nothing and `reveal` turned off inverse instead.
15
+ (hurricup, #38)
16
+ * Depend on the `logger` gem. `require 'ansi'` loads `ANSI::Logger`, which
17
+ needs Ruby's `logger` library, and Ruby 4.0 no longer ships that as a
18
+ default gem. Under Bundler on Ruby 4.0, `require 'ansi'` failed with
19
+ "cannot load such file -- logger".
20
+ * Test on Ruby 4.0.
21
+ * Fix a typo in a comment. (eduardoj, #41)
22
+
23
+ ## 1.6.0 | 2026-03-30
24
+
25
+ Maintenance release. Modernized project tooling and cleaned up documentation.
26
+
27
+ Changes:
28
+
29
+ * Replace custom Indexer system with standard gemspec.
30
+ * Replace Travis CI with GitHub Actions.
31
+ * Replace Assembly/detroit/ergo with Rakefile.
32
+ * Simplify version.rb to use a plain constant.
33
+ * Fix Fixnum reference for Ruby 3+ compatibility.
34
+ * Fix typos and update URLs to HTTPS.
35
+ * Move site from gh-pages to docs/.
36
+ * Remove obsolete files.
37
+ * Clean up .gitignore.
38
+
39
+
3
40
  ## 1.5.0 | 2015-01-16
4
41
 
5
42
  ANSI 1.5 introduces one change that is not backward compatiable. The
data/NOTICE.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  ## ANSI
4
4
 
5
- Copyright © 2009 [Rubyworks](http://rubyworks.github.com) ·
5
+ Copyright © 2009 [Rubyworks](http://rubyworks.github.io) ·
6
6
  License [BSD-2-Clause](http://spdx.org/licenses/BSD-2-Clause) ·
7
- Website http://rubyworks.github.com/ansi
7
+ Website http://rubyworks.github.io/ansi
8
8
 
9
9
  Copyright 2009 Rubyworks.
10
10
 
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # ANSI
2
2
 
3
- [HOME](http://rubyworks.github.com/ansi) ·
4
- [API](http://rubydoc.info/gems/ansi/frames) ·
5
- [MAIL](http://googlegroups.com/group/rubyworks-mailinglist) ·
6
- [ISSUES](http://github.com/rubyworks/ansi/issues) ·
7
- [SOURCE](http://github.com/rubyworks/ansi)
3
+ [HOME](https://rubyworks.github.io/ansi) ·
4
+ [API](https://rubydoc.info/gems/ansi) ·
5
+ [ISSUES](https://github.com/rubyworks/ansi/issues) ·
6
+ [SOURCE](https://github.com/rubyworks/ansi)
8
7
 
9
- [![Build Status](https://secure.travis-ci.org/rubyworks/ansi.png)](http://travis-ci.org/rubyworks/ansi)
8
+ [![Gem Version](https://img.shields.io/gem/v/ansi.svg?style=flat)](https://rubygems.org/gems/ansi)
9
+ [![Build Status](https://github.com/rubyworks/ansi/actions/workflows/test.yml/badge.svg)](https://github.com/rubyworks/ansi/actions/workflows/test.yml)
10
10
 
11
11
  <br/>
12
12
 
@@ -34,8 +34,8 @@ device.
34
34
 
35
35
  There are a number of modules and classes provided by the ANSI
36
36
  package. To get a good understanding of them it is best to pursue
37
- the [QED documents](http://github.com/rubyworks/ansi/tree/master/qed/)
38
- or the [API documentation](http://rubyworks.github.com/ansi/api/index.html).
37
+ the [QED documents](https://github.com/rubyworks/ansi/tree/master/demo/)
38
+ or the [API documentation](https://rubydoc.info/gems/ansi).
39
39
 
40
40
  At the heart of all the provided libraries lies the ANSI::Code module
41
41
  which defines ANSI codes as constants and methods. For example:
@@ -56,23 +56,19 @@ the system.
56
56
 
57
57
  ## Installation
58
58
 
59
- ### RubyGems
60
-
61
- To install with RubyGems simply open a console and type:
59
+ ### Bundler
62
60
 
63
- $ sudo gem install ansi
61
+ Add the usual `gem` line to your project's `Gemfile`.
64
62
 
65
- ### Setup.rb (not recommended)
63
+ gem 'ansi'
66
64
 
67
- Local installation requires Setup.rb (gem install setup),
68
- then [download](http://github.com/rubyworks/ansi/download) the tarball package and type:
65
+ And run then `bundle` command.
69
66
 
70
- $ tar -xvzf ansi-1.0.0.tgz
71
- $ cd ansi-1.0.0
72
- $ sudo setup.rb all
67
+ ### RubyGems
73
68
 
74
- Windows users use 'ruby setup.rb all'.
69
+ To install with RubyGems simply open a console and type:
75
70
 
71
+ $ sudo gem install ansi
76
72
 
77
73
  ## Release Notes
78
74
 
@@ -83,7 +79,7 @@ Please see HISTORY.md file.
83
79
 
84
80
  Copyright (c) 2009 Rubyworks
85
81
 
86
- This program is redistributable under the terms of the *FreeBSD* license.
82
+ This program is redistributable under the terms of the *BSD-2-Clause* license.
87
83
 
88
84
  Some pieces of the code are copyrighted by others.
89
85
 
@@ -52,8 +52,8 @@ Calling this methods is the same as calling:
52
52
  pbar.format("%-14s %3d%% %s %s",:title, :percentage, :bar, :stat_for_file_transfer)
53
53
  run(pbar)
54
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.
55
+ The `#style` setter allows each part of the line be modified with ANSI codes.
56
+ And the `#bar_mark` writer can be used to change the character used to make the bar.
57
57
 
58
58
  pbar.standard_mode
59
59
  pbar.style(:title => [:red], :bar=>[:blue])
data/demo/11_terminal.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # ANSI::Terminal
2
2
 
3
- We should be ables to get the terminal width via the `terminal_width` method.
3
+ We should be able to get the terminal width via the `terminal_width` method.
4
4
 
5
5
  width = ANSI::Terminal.terminal_width
6
6
 
7
- Fixnum.assert === width
7
+ Integer.assert === width
8
8
 
data/lib/ansi/bbcode.rb CHANGED
@@ -84,7 +84,7 @@ module ANSI
84
84
 
85
85
  # ---------------------------
86
86
 
87
- # Returns the ANSI sequence for given color, if existant
87
+ # Returns the ANSI sequence for given color, if existent
88
88
  def BBCode.ansi(colorname)
89
89
  colorname.strip!
90
90
  return ANSINAME2CODE[ colorname.downcase ]
data/lib/ansi/chart.rb CHANGED
@@ -48,11 +48,11 @@ module ANSI
48
48
  :fraktur_off => 23,
49
49
  :underline_off => 24,
50
50
  :blink_off => 25,
51
- :inverse_off => 26,
52
- :positive => 26,
53
- :conceal_off => 27,
54
- :show => 27,
55
- :reveal => 27,
51
+ :inverse_off => 27,
52
+ :positive => 27,
53
+ :conceal_off => 28,
54
+ :show => 28,
55
+ :reveal => 28,
56
56
  :crossed_off => 29,
57
57
  :crossed_out_off => 29,
58
58
 
data/lib/ansi/code.rb CHANGED
@@ -6,15 +6,6 @@ module ANSI
6
6
  # NOTE: This has no effect on methods that return ANSI codes.
7
7
  $ansi = true
8
8
 
9
- if RUBY_PLATFORM =~ /(win32|w32)/
10
- begin
11
- require 'Win32/Console/ANSI'
12
- rescue LoadError
13
- warn "ansi: 'gem install win32console' to use color on Windows"
14
- $ansi = false
15
- end
16
- end
17
-
18
9
  require 'ansi/constants'
19
10
 
20
11
  # TODO: up, down, right, left, etc could have yielding methods too?
data/lib/ansi/version.rb CHANGED
@@ -1,15 +1,3 @@
1
1
  module ANSI
2
- # Returns Hash table of project metadata.
3
- def self.metadata
4
- @spec ||= (
5
- require 'yaml'
6
- YAML.load(File.new(File.dirname(__FILE__) + '/../ansi.yml'))
7
- )
8
- end
9
-
10
- # Check metadata for missing constants.
11
- def self.const_missing(name)
12
- metadata[name.to_s.downcase] || super(name)
13
- end
2
+ VERSION = '1.6.1'
14
3
  end
15
-
metadata CHANGED
@@ -1,116 +1,98 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Sawyer
8
8
  - Florian Frank
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-01-17 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: mast
14
+ name: logger
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
- - - '>='
17
+ - - ">="
19
18
  - !ruby/object:Gem::Version
20
19
  version: '0'
21
- type: :development
20
+ type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
- - - '>='
24
+ - - ">="
26
25
  - !ruby/object:Gem::Version
27
26
  version: '0'
28
27
  - !ruby/object:Gem::Dependency
29
- name: indexer
28
+ name: rake
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
- - - '>='
31
+ - - ">="
33
32
  - !ruby/object:Gem::Version
34
- version: '0'
33
+ version: '13'
35
34
  type: :development
36
35
  prerelease: false
37
36
  version_requirements: !ruby/object:Gem::Requirement
38
37
  requirements:
39
- - - '>='
38
+ - - ">="
40
39
  - !ruby/object:Gem::Version
41
- version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: ergo
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - '>='
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
40
+ version: '13'
56
41
  - !ruby/object:Gem::Dependency
57
42
  name: qed
58
43
  requirement: !ruby/object:Gem::Requirement
59
44
  requirements:
60
- - - '>='
45
+ - - ">="
61
46
  - !ruby/object:Gem::Version
62
- version: '0'
47
+ version: '2.9'
63
48
  type: :development
64
49
  prerelease: false
65
50
  version_requirements: !ruby/object:Gem::Requirement
66
51
  requirements:
67
- - - '>='
52
+ - - ">="
68
53
  - !ruby/object:Gem::Version
69
- version: '0'
54
+ version: '2.9'
70
55
  - !ruby/object:Gem::Dependency
71
56
  name: ae
72
57
  requirement: !ruby/object:Gem::Requirement
73
58
  requirements:
74
- - - '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - '>='
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: lemon
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - '>='
59
+ - - ">="
89
60
  - !ruby/object:Gem::Version
90
- version: '0'
61
+ version: '1.8'
91
62
  type: :development
92
63
  prerelease: false
93
64
  version_requirements: !ruby/object:Gem::Requirement
94
65
  requirements:
95
- - - '>='
66
+ - - ">="
96
67
  - !ruby/object:Gem::Version
97
- version: '0'
68
+ version: '1.8'
98
69
  description: The ANSI project is a superlative collection of ANSI escape code related
99
- libraries eabling ANSI colorization and stylization of console output. Byte for
70
+ libraries enabling ANSI colorization and stylization of console output. Byte for
100
71
  byte ANSI is the best ANSI code library available for the Ruby programming language.
101
72
  email:
102
73
  - transfire@gmail.com
103
74
  executables: []
104
75
  extensions: []
105
- extra_rdoc_files:
76
+ extra_rdoc_files: []
77
+ files:
78
+ - HISTORY.md
106
79
  - LICENSE.txt
107
80
  - NOTICE.md
108
81
  - README.md
109
- - HISTORY.md
110
- - DEMO.md
111
- files:
112
- - .index
113
- - .yardopts
82
+ - demo/01_ansicode.md
83
+ - demo/02_core.md
84
+ - demo/03_logger.md
85
+ - demo/04_progressbar.md
86
+ - demo/05_mixin.md
87
+ - demo/06_string.md
88
+ - demo/07_columns.md
89
+ - demo/08_table.md
90
+ - demo/09_diff.md
91
+ - demo/10_bbcode.md
92
+ - demo/11_terminal.md
93
+ - demo/applique/ae.rb
94
+ - demo/applique/output.rb
95
+ - lib/ansi.rb
114
96
  - lib/ansi/bbcode.rb
115
97
  - lib/ansi/chain.rb
116
98
  - lib/ansi/chart.rb
@@ -125,65 +107,31 @@ files:
125
107
  - lib/ansi/progressbar.rb
126
108
  - lib/ansi/string.rb
127
109
  - lib/ansi/table.rb
110
+ - lib/ansi/terminal.rb
128
111
  - lib/ansi/terminal/curses.rb
129
112
  - lib/ansi/terminal/stty.rb
130
113
  - lib/ansi/terminal/termios.rb
131
114
  - lib/ansi/terminal/win32.rb
132
- - lib/ansi/terminal.rb
133
115
  - lib/ansi/version.rb
134
- - lib/ansi.rb
135
- - lib/ansi.yml
136
- - demo/01_ansicode.md
137
- - demo/02_core.md
138
- - demo/03_logger.md
139
- - demo/04_progressbar.md
140
- - demo/05_mixin.md
141
- - demo/06_string.md
142
- - demo/07_columns.md
143
- - demo/08_table.md
144
- - demo/09_diff.md
145
- - demo/10_bbcode.md
146
- - demo/11_terminal.md
147
- - demo/applique/ae.rb
148
- - demo/applique/output.rb
149
- - test/case_ansicode.rb
150
- - test/case_bbcode.rb
151
- - test/case_mixin.rb
152
- - test/case_progressbar.rb
153
- - test/test_helper.rb
154
- - NOTICE.md
155
- - README.md
156
- - HISTORY.md
157
- - DEMO.md
158
- - LICENSE.txt
159
- homepage: http://rubyworks.github.com/ansi
116
+ homepage: https://github.com/rubyworks/ansi
160
117
  licenses:
161
118
  - BSD-2-Clause
162
119
  metadata: {}
163
- post_install_message:
164
120
  rdoc_options: []
165
121
  require_paths:
166
122
  - lib
167
123
  required_ruby_version: !ruby/object:Gem::Requirement
168
124
  requirements:
169
- - - '>='
125
+ - - ">="
170
126
  - !ruby/object:Gem::Version
171
- version: '0'
127
+ version: '3.1'
172
128
  required_rubygems_version: !ruby/object:Gem::Requirement
173
129
  requirements:
174
- - - '>='
130
+ - - ">="
175
131
  - !ruby/object:Gem::Version
176
132
  version: '0'
177
133
  requirements: []
178
- rubyforge_project:
179
- rubygems_version: 2.0.3
180
- signing_key:
134
+ rubygems_version: 3.6.9
181
135
  specification_version: 4
182
136
  summary: ANSI at your fingertips!
183
- test_files:
184
- - test/case_bbcode.rb
185
- - test/case_progressbar.rb
186
- - test/case_ansicode.rb
187
- - test/case_mixin.rb
188
- - test/test_helper.rb
189
- has_rdoc:
137
+ test_files: []
data/.index DELETED
@@ -1,77 +0,0 @@
1
- ---
2
- revision: 2013
3
- type: ruby
4
- sources:
5
- - INDEX.yml
6
- authors:
7
- - name: Thomas Sawyer
8
- email: transfire@gmail.com
9
- - name: Florian Frank
10
- organizations: []
11
- requirements:
12
- - groups:
13
- - build
14
- development: true
15
- name: mast
16
- - groups:
17
- - build
18
- development: true
19
- name: indexer
20
- - groups:
21
- - build
22
- development: true
23
- name: ergo
24
- - groups:
25
- - test
26
- development: true
27
- name: qed
28
- - groups:
29
- - test
30
- development: true
31
- name: ae
32
- - groups:
33
- - test
34
- development: true
35
- name: lemon
36
- conflicts: []
37
- alternatives: []
38
- resources:
39
- - type: home
40
- uri: http://rubyworks.github.com/ansi
41
- label: Homepage
42
- - type: docs
43
- uri: http://rubydoc.info/gems/ansi/frames
44
- label: Documentation
45
- - type: code
46
- uri: http://github.com/rubyworks/ansi
47
- label: Source Code
48
- - type: bugs
49
- uri: http://github.com/rubyworks/ansi/issues
50
- label: Issue Tracker
51
- - type: mail
52
- uri: http://groups.google.com/group/rubyworks-mailinglist
53
- label: Mailing List
54
- repositories:
55
- - name: upstream
56
- scm: git
57
- uri: git://github.com/rubyworks/ansi.git
58
- categories: []
59
- copyrights:
60
- - holder: Rubyworks
61
- year: '2009'
62
- license: BSD-2-Clause
63
- customs: []
64
- paths:
65
- lib:
66
- - lib
67
- name: ansi
68
- title: ANSI
69
- version: 1.5.0
70
- summary: ANSI at your fingertips!
71
- description: The ANSI project is a superlative collection of ANSI escape code related
72
- libraries eabling ANSI colorization and stylization of console output. Byte for
73
- byte ANSI is the best ANSI code library available for the Ruby programming language.
74
- orgranizations:
75
- - Rubyworks
76
- created: '2009-08-01'
77
- date: '2015-01-16'
data/.yardopts DELETED
@@ -1,8 +0,0 @@
1
- --title ANSI
2
- --protected
3
- --private
4
- lib
5
- -
6
- QED.rdoc
7
- [A-Z]*.*
8
-
data/DEMO.md DELETED
@@ -1,451 +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
-
50
-
51
- # String Extensions
52
-
53
- In addition the library offers an extension to String class
54
- called #ansi, which allows some of the ANSI::Code methods
55
- to be called in a more object-oriented fashion.
56
-
57
- require 'ansi/core'
58
-
59
- str = "Hello".ansi(:red) + "World".ansi(:blue)
60
- str.assert == "\e[31mHello\e[0m\e[34mWorld\e[0m"
61
-
62
-
63
- # ANSI::Logger
64
-
65
- Require the ANSI::Logger library.
66
-
67
- require 'ansi/logger'
68
-
69
- Create a new ANSI::Logger
70
-
71
- log = ANSI::Logger.new(STDOUT)
72
-
73
- Info logging appears normal.
74
-
75
- log.info{"Info logs are green.\n"}
76
-
77
- Warn logging appears yellow.
78
-
79
- log.warn{"Warn logs are yellow.\n"}
80
-
81
- Debug logging appears cyan.
82
-
83
- log.debug{"Debug logs are cyan.\n"}
84
-
85
- Error logging appears red.
86
-
87
- log.error{"Error logs are red.\n"}
88
-
89
- Fatal logging appears bright red.
90
-
91
- log.fatal{"Fatal logs are bold red!\n"}
92
-
93
-
94
- # ANSI::Progressbar
95
-
96
- Pretty progress bars are easy to construct.
97
-
98
- require 'ansi/progressbar'
99
-
100
- pbar = ANSI::Progressbar.new("Test Bar", 100)
101
-
102
- Running the bar simply requires calling the #inc method during
103
- a loop and calling #finish when done.
104
-
105
- 100.times do |i|
106
- sleep 0.01
107
- pbar.inc
108
- end
109
- pbar.finish
110
-
111
- We will use this same rountine in all the examples below, so lets
112
- make a quick macro for it. Notice we have to use #reset first
113
- before reusing the same progress bar.
114
-
115
- def run(pbar)
116
- pbar.reset
117
- 100.times do |i|
118
- sleep 0.01
119
- pbar.inc
120
- end
121
- pbar.finish
122
- puts
123
- end
124
-
125
- The progress bar can be stylized in almost any way.
126
- The #format setter provides control over the parts
127
- that appear on the line. For example, by default the
128
- format is:
129
-
130
- pbar.format("%-14s %3d%% %s %s", :title, :percentage, :bar, :stat)
131
-
132
- So lets vary it up to demonstrate the case.
133
-
134
- pbar.format("%-14s %3d%% %s %s", :title, :percentage, :stat, :bar)
135
- run(pbar)
136
-
137
- The progress bar has an extra build in format intended for use with
138
- file downloads called #transer_mode.
139
-
140
- pbar.transfer_mode
141
- run(pbar)
142
-
143
- Calling this methods is the same as calling:
144
-
145
- pbar.format("%-14s %3d%% %s %s",:title, :percentage, :bar, :stat_for_file_transfer)
146
- run(pbar)
147
-
148
- The #style setter allows each part of the line be modified with ANSI codes. And the
149
- #bar_mark writer can be used to change the character used to make the bar.
150
-
151
- pbar.standard_mode
152
- pbar.style(:title => [:red], :bar=>[:blue])
153
- pbar.bar_mark = "="
154
- run(pbar)
155
-
156
-
157
- # ANSI::Mixin
158
-
159
- The ANSI::Mixin module is design for including into
160
- String-like classes. It will support any class that defines
161
- a #to_s method.
162
-
163
- require 'ansi/mixin'
164
-
165
- In this demonstration we will simply include it in the
166
- core String class.
167
-
168
- class ::String
169
- include ANSI::Mixin
170
- end
171
-
172
- Now all strings will have access to ANSI's style and color
173
- codes via simple method calls.
174
-
175
- "roses".red.assert == "\e[31mroses\e[0m"
176
-
177
- "violets".blue.assert == "\e[34mviolets\e[0m"
178
-
179
- "sugar".italic.assert == "\e[3msugar\e[0m"
180
-
181
- The method can be combined, of course.
182
-
183
- "you".italic.bold.assert == "\e[1m\e[3myou\e[0m\e[0m"
184
-
185
- The mixin also supports background methods.
186
-
187
- "envy".on_green.assert == "\e[42menvy\e[0m"
188
-
189
- And it also supports the combined foreground-on-background
190
- methods.
191
-
192
- "b&w".white_on_black.assert == "\e[37m\e[40mb&w\e[0m"
193
-
194
-
195
- # ANSI::String
196
-
197
- The ANSI::String class is a very sophisticated implementation
198
- of Ruby's standard String class, but one that can handle
199
- ANSI codes seamlessly.
200
-
201
- require 'ansi/string'
202
-
203
- flower1 = ANSI::String.new("Roses")
204
- flower2 = ANSI::String.new("Violets")
205
-
206
- Like any other string.
207
-
208
- flower1.to_s.assert == "Roses"
209
- flower2.to_s.assert == "Violets"
210
-
211
- Bet now we can add color.
212
-
213
- flower1.red!
214
- flower2.blue!
215
-
216
- flower1.to_s.assert == "\e[31mRoses\e[0m"
217
- flower2.to_s.assert == "\e[34mViolets\e[0m"
218
-
219
- Despite that the string representation now contains ANSI codes,
220
- we can still manipulate the string in much the same way that
221
- we manipulate an ordinary string.
222
-
223
- flower1.size.assert == 5
224
- flower2.size.assert == 7
225
-
226
- Like ordinary strings we can concatenate the two strings
227
-
228
- flowers = flower1 + ' ' + flower2
229
- flowers.to_s.assert == "\e[31mRoses\e[0m \e[34mViolets\e[0m"
230
-
231
- flowers.size.assert == 13
232
-
233
- Standard case conversion such as #upcase and #downcase work.
234
-
235
- flower1.upcase.to_s.assert == "\e[31mROSES\e[0m"
236
- flower1.downcase.to_s.assert == "\e[31mroses\e[0m"
237
-
238
- Some of the most difficult methods to re-implement were the
239
- substitution methods such as #sub and #gsub. They are still
240
- somewhat more limited than the original string methods, but
241
- their primary functionality should work.
242
-
243
- flower1.gsub('s', 'z').to_s.assert == "\e[31mRozez\e[0m"
244
-
245
- There are still a number of methods that need implementation.
246
- ANSI::String is currently a very partial implementation. But
247
- as you can see from the methods it does currently support,
248
- is it already useful.
249
-
250
-
251
- # ANSI::Columns
252
-
253
- The +Columns+ class makes it easy to create nice looking text columns,
254
- sorted from top to bottom, right to left (as opposed to the other way
255
- around).
256
-
257
- require 'ansi/columns'
258
-
259
- list = %w{a b c d e f g h i j k l}
260
-
261
- columns = ANSI::Columns.new(list)
262
-
263
- columns.to_s(4)
264
-
265
- The output will be:
266
-
267
- a d g j
268
- b e h k
269
- c f i l
270
-
271
- Besides an array of elements, Columns.new can take a string in which
272
- the elements are divided by newlines characters. The default column
273
- size can also be given to the initializer.
274
-
275
- list = "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl"
276
-
277
- columns = ANSI::Columns.new(list, :columns=>6)
278
-
279
- columns.to_s
280
-
281
- The output will be:
282
-
283
- a c e g i k
284
- b d f h j l
285
-
286
- If the column count is +nil+, then the number of columns will be calculated
287
- as a best fit for the current terminal window.
288
-
289
- ## Padding
290
-
291
- Columns can adjust the padding between cells.
292
-
293
- list = %w{a b c d e f g h i j k l}
294
-
295
- columns = ANSI::Columns.new(list, :padding=>2)
296
-
297
- columns.to_s(4)
298
-
299
- The output will be:
300
-
301
- a d g j
302
- b e h k
303
- c f i l
304
-
305
- ## Alignment
306
-
307
- Columns can also be aligned either left or right.
308
-
309
- list = %w{xx xx xx yy y yy z zz z}
310
-
311
- columns = ANSI::Columns.new(list, :align=>:right)
312
-
313
- columns.to_s(3)
314
-
315
- The output will be:
316
-
317
- xx yy z
318
- xx y zz
319
- xx yy z
320
-
321
- ## Format
322
-
323
- Lastly, columns can be augmented with ANSI codes. This is done through
324
- a formatting block. The block can take up to three parameters, the cell
325
- content, the column and row numbers, or the cell and the column and row
326
- numbers.
327
-
328
- list = %w{a b c d e f g h i j k l}
329
-
330
- columns = ANSI::Columns.new(list){ |c,r| r % 2 == 0 ? :red : :blue }
331
-
332
- out = columns.to_s(4)
333
-
334
- out.assert == (
335
- "\e[31ma \e[0m\e[31md \e[0m\e[31mg \e[0m\e[31mj \e[0m\n" +
336
- "\e[34mb \e[0m\e[34me \e[0m\e[34mh \e[0m\e[34mk \e[0m\n" +
337
- "\e[31mc \e[0m\e[31mf \e[0m\e[31mi \e[0m\e[31ml \e[0m\n"
338
- )
339
-
340
-
341
- # ANSI::Table
342
-
343
- The ANSI::Table class can be used to output tabular data with nicely
344
- formated ASCII cell borders.
345
-
346
- require 'ansi/table'
347
-
348
- The constructor takes an 2-dimensional array.
349
-
350
- data = [
351
- [ 10, 20, 30 ],
352
- [ 20, 10, 20 ],
353
- [ 50, 40, 20 ]
354
- ]
355
-
356
- table = ANSI::Table.new(data)
357
-
358
- table.to_s
359
-
360
- The output will be:
361
-
362
- +----+----+----+
363
- | 10 | 20 | 30 |
364
- | 20 | 10 | 20 |
365
- | 50 | 40 | 20 |
366
- +----+----+----+
367
-
368
-
369
-
370
- # ANSI::Diff
371
-
372
- require 'ansi/diff'
373
-
374
- a = 'abcYefg'
375
- b = 'abcXefg'
376
-
377
- diff = ANSI::Diff.new(a,b)
378
-
379
- diff.to_s.assert == "\e[31mabc\e[0m\e[33mYefg\e[0m\n\e[31mabc\e[0mXefg"
380
-
381
- Try another.
382
-
383
- a = 'abc'
384
- b = 'abcdef'
385
-
386
- diff = ANSI::Diff.new(a,b)
387
-
388
- diff.to_s.assert == "\e[31mabc\e[0m\n\e[31mabc\e[0mdef"
389
-
390
- And another.
391
-
392
- a = 'abcXXXghi'
393
- b = 'abcdefghi'
394
-
395
- diff = ANSI::Diff.new(a,b)
396
-
397
- diff.to_s.assert == "\e[31mabc\e[0m\e[33mXXXghi\e[0m\n\e[31mabc\e[0mdefghi"
398
-
399
- And another.
400
-
401
- a = 'abcXXXdefghi'
402
- b = 'abcdefghi'
403
-
404
- diff = ANSI::Diff.new(a,b)
405
-
406
- 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"
407
-
408
- Comparison that is mostly different.
409
-
410
- a = 'abcpppz123'
411
- b = 'abcxyzzz43'
412
-
413
- diff = ANSI::Diff.new(a,b)
414
-
415
- diff.to_s.assert == "\e[31mabc\e[0m\e[33mpppz123\e[0m\n\e[31mabc\e[0mxyzzz43"
416
-
417
-
418
- # ANSI::BBCode
419
-
420
- The BBCode module provides methods for converting between
421
- BBCodes, basic HTML and ANSI codes.
422
-
423
- require 'ansi/bbcode'
424
-
425
- BBCodes are color and style codes in square brackets, quite
426
- popular with on line forums.
427
-
428
- bbcode = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
429
-
430
- We can convert this to ANSI code simply enough:
431
-
432
- ansi = ANSI::BBCode.bbcode_to_ansi(bbcode)
433
-
434
- ansi.assert == "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
435
-
436
- In addition the BBCode module supports conversion to simple HTML.
437
-
438
- html = ANSI::BBCode.bbcode_to_html(bbcode)
439
-
440
- html.assert == "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
441
-
442
-
443
- # ANSI::Terminal
444
-
445
- We should be ables to get the terminal width via the `terminal_width` method.
446
-
447
- width = ANSI::Terminal.terminal_width
448
-
449
- Fixnum.assert === width
450
-
451
-
data/lib/ansi.yml DELETED
@@ -1,77 +0,0 @@
1
- ---
2
- revision: 2013
3
- type: ruby
4
- sources:
5
- - INDEX.yml
6
- authors:
7
- - name: Thomas Sawyer
8
- email: transfire@gmail.com
9
- - name: Florian Frank
10
- organizations: []
11
- requirements:
12
- - groups:
13
- - build
14
- development: true
15
- name: mast
16
- - groups:
17
- - build
18
- development: true
19
- name: indexer
20
- - groups:
21
- - build
22
- development: true
23
- name: ergo
24
- - groups:
25
- - test
26
- development: true
27
- name: qed
28
- - groups:
29
- - test
30
- development: true
31
- name: ae
32
- - groups:
33
- - test
34
- development: true
35
- name: lemon
36
- conflicts: []
37
- alternatives: []
38
- resources:
39
- - type: home
40
- uri: http://rubyworks.github.com/ansi
41
- label: Homepage
42
- - type: docs
43
- uri: http://rubydoc.info/gems/ansi/frames
44
- label: Documentation
45
- - type: code
46
- uri: http://github.com/rubyworks/ansi
47
- label: Source Code
48
- - type: bugs
49
- uri: http://github.com/rubyworks/ansi/issues
50
- label: Issue Tracker
51
- - type: mail
52
- uri: http://groups.google.com/group/rubyworks-mailinglist
53
- label: Mailing List
54
- repositories:
55
- - name: upstream
56
- scm: git
57
- uri: git://github.com/rubyworks/ansi.git
58
- categories: []
59
- copyrights:
60
- - holder: Rubyworks
61
- year: '2009'
62
- license: BSD-2-Clause
63
- customs: []
64
- paths:
65
- lib:
66
- - lib
67
- name: ansi
68
- title: ANSI
69
- version: 1.5.0
70
- summary: ANSI at your fingertips!
71
- description: The ANSI project is a superlative collection of ANSI escape code related
72
- libraries eabling ANSI colorization and stylization of console output. Byte for
73
- byte ANSI is the best ANSI code library available for the Ruby programming language.
74
- orgranizations:
75
- - Rubyworks
76
- created: '2009-08-01'
77
- date: '2015-01-16'
@@ -1,43 +0,0 @@
1
- require 'test_helper'
2
- require 'ansi/code'
3
-
4
- testcase ANSI::Code do
5
-
6
- method :red do
7
- test do
8
- str = ANSI::Code.red
9
- out = "\e[31m"
10
- out.assert == str
11
- end
12
-
13
- test "with block notation" do
14
- str = ANSI::Code.red { "Hello" }
15
- out = "\e[31mHello\e[0m"
16
- out.assert == str
17
- end
18
- end
19
-
20
- method :blue do
21
- test do
22
- str = ANSI::Code.blue
23
- out = "\e[34m"
24
- out.assert == str
25
- end
26
-
27
- test "with block notation" do
28
- str = ANSI::Code.blue { "World" }
29
- out = "\e[34mWorld\e[0m"
30
- out.assert == str
31
- end
32
- end
33
-
34
- method :hex do
35
- test do
36
- str = ANSI::Code.hex("#000000")
37
- out = "0"
38
- out.assert == str
39
- end
40
- end
41
-
42
- end
43
-
data/test/case_bbcode.rb DELETED
@@ -1,35 +0,0 @@
1
- require 'test_helper'
2
- require 'ansi/bbcode'
3
-
4
- testcase ANSI::BBCode do
5
-
6
- class_method :bbcode_to_ansi do
7
- test do
8
- str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
9
- out = "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
10
- out.assert == ANSI::BBCode.bbcode_to_ansi(str)
11
- end
12
- end
13
-
14
- class_method :bbcode_to_html do
15
- test do
16
- str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
17
- out = "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
18
- out.assert == ANSI::BBCode.bbcode_to_html(str)
19
- end
20
- end
21
-
22
- class_method :ansi_to_html do
23
- test do
24
- str = "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n" +
25
- "this is a line without any ansi code\n" +
26
- "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
27
- out = "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n" +
28
- "this is a line without any ansi code<br />\n" +
29
- "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
30
- out.assert == ANSI::BBCode.ansi_to_html(str)
31
- end
32
- end
33
-
34
- end
35
-
data/test/case_mixin.rb DELETED
@@ -1,35 +0,0 @@
1
- require 'test_helper'
2
- require 'ansi/mixin'
3
-
4
- testcase ANSI::Mixin do
5
-
6
- # TODO: subclass
7
- class ::String
8
- include ANSI::Mixin
9
- end
10
-
11
- method :red do
12
- test do
13
- str = "Hello".red
14
- out = "\e[31mHello\e[0m"
15
- out.assert == str
16
- end
17
- end
18
-
19
- method :blue do
20
- test do
21
- str = "World".blue
22
- out = "\e[34mWorld\e[0m"
23
- out.assert == str
24
- end
25
- end
26
-
27
- method :display do
28
- test do
29
- str = "Hello".display(4,10)
30
- out = "\e[s\e[4;10HHello\e[u"
31
- out.assert == str
32
- end
33
- end
34
-
35
- end
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
- require 'stringio'
3
- require 'ansi/progressbar'
4
-
5
- testcase ANSI::Progressbar do
6
-
7
- method :initialize do
8
- test do
9
- stio = StringIO.new
10
- pbar = ANSI::Progressbar.new("Test Bar", 10, stio) do |b|
11
- b.style(:title => [:red], :bar=>[:blue])
12
- end
13
- 10.times do |i|
14
- sleep 0.1
15
- pbar.inc
16
- end
17
- true
18
- end
19
- end
20
-
21
- end
data/test/test_helper.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'lemon'
2
- require 'ae'
3
-