ansi_utils 0.1.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.
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/ansi_utils.rb +66 -0
- data/test/helper.rb +10 -0
- data/test/test_ansi_utils.rb +5 -0
- metadata +72 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 jugyo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ansi_utils"
|
8
|
+
gem.summary = %Q{ANSI escape code utils.}
|
9
|
+
gem.description = %Q{ANSI escape code utils. Move cursor, Erase data, etc...}
|
10
|
+
gem.email = "jugyo.org@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/jugyo/ansi_utils"
|
12
|
+
gem.authors = ["jugyo"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "ansi_utils #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/ansi_utils.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module AnsiUtils
|
2
|
+
extend self
|
3
|
+
|
4
|
+
' A up
|
5
|
+
B down
|
6
|
+
C forward
|
7
|
+
D back
|
8
|
+
E next_line
|
9
|
+
F prev_line
|
10
|
+
G move_to_column
|
11
|
+
'.strip.split("\n").map{|s| s.split(' ')}.each do |i|
|
12
|
+
code, method = *i
|
13
|
+
class_eval <<-DELIM
|
14
|
+
def #{method}(num = nil)
|
15
|
+
output('#{code}', *[num].compact)
|
16
|
+
end
|
17
|
+
DELIM
|
18
|
+
end
|
19
|
+
|
20
|
+
' 6n status
|
21
|
+
s save_position
|
22
|
+
u restore_position
|
23
|
+
?25l hide_cursor
|
24
|
+
?25h show_cursor
|
25
|
+
'.strip.split("\n").map{|s| s.split(' ')}.each do |i|
|
26
|
+
code, method = *i
|
27
|
+
class_eval <<-DELIM
|
28
|
+
def #{method}
|
29
|
+
output('#{code}')
|
30
|
+
end
|
31
|
+
DELIM
|
32
|
+
end
|
33
|
+
|
34
|
+
# J
|
35
|
+
def erase_screen(type = :after)
|
36
|
+
output('J', erase_type(type))
|
37
|
+
end
|
38
|
+
|
39
|
+
# K
|
40
|
+
def erase_line(type = :after)
|
41
|
+
output('K', erase_type(type))
|
42
|
+
end
|
43
|
+
|
44
|
+
# H
|
45
|
+
def move(col = nil, row = nil)
|
46
|
+
output('H', *[col, row].compact)
|
47
|
+
end
|
48
|
+
|
49
|
+
# m
|
50
|
+
def set_sgr(*args)
|
51
|
+
output('m', *args)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def erase_type(type)
|
57
|
+
@erase_type ||= {:after => 0, :before => 1, :all => 2}
|
58
|
+
raise ArgumentError, "invalid type: #{type}" unless @erase_type.key?(type)
|
59
|
+
@erase_type[type]
|
60
|
+
end
|
61
|
+
|
62
|
+
def output(code, *args)
|
63
|
+
print "\e[#{args.join(';')}#{code}"
|
64
|
+
STDOUT.flush
|
65
|
+
end
|
66
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ansi_utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jugyo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-29 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: ANSI escape code utils. Move cursor, Erase data, etc...
|
26
|
+
email: jugyo.org@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.rdoc
|
37
|
+
- Rakefile
|
38
|
+
- VERSION
|
39
|
+
- lib/ansi_utils.rb
|
40
|
+
- test/helper.rb
|
41
|
+
- test/test_ansi_utils.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/jugyo/ansi_utils
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.5
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: ANSI escape code utils.
|
70
|
+
test_files:
|
71
|
+
- test/helper.rb
|
72
|
+
- test/test_ansi_utils.rb
|