term2irc 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b36873b2402ea8ebf83d2d339a4e9b78950b6a5
4
+ data.tar.gz: c7fc3066c9f8d52dbaf03cceec98b006860cf5b4
5
+ SHA512:
6
+ metadata.gz: 617226e1904df3b3286d6bab963ca49002fd5d6c1c7b83218b0445b1bcf1e9ea7f20ac28eaca87e7e55b90c2532706fa7d10d4c026055abebc5ce997175537e7
7
+ data.tar.gz: 29b596e8ee8557a23eba03bc57aadcfd0af082d9c0c7cfc271cf6127fb323ec1c83fdf0aba7ad9df00e4bb48d239f9dd9434b5e3288896129f52c34c1fb94705
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in term2irc.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Uchio KONDO
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Term2irc
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'term2irc'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install term2irc
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/term2irc/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,84 @@
1
+ require "term2irc/version"
2
+
3
+ # FIXME: This module breaks some termi ANSI pattern,
4
+ # such as: "\e[31;0;42mhello, world\e[0m"
5
+ # This must remain string green-backgrounded,
6
+ # but currently it would truncate all the color info.
7
+
8
+ module Term2IRC
9
+ ATTRIBUTE_TABLE = {
10
+ :reset => ["0", "\x0f"],
11
+ :bold => ["1", "\x02"],
12
+ :underline => ["4", "\x1f"],
13
+ }
14
+ ATTRIBUTE_T2I_TABLE = Hash[ATTRIBUTE_TABLE.map{|r| r[1] }]
15
+ ATTRIBUTE_I2T_TABLE = Hash[ATTRIBUTE_TABLE.map{|r| r[1].reverse }]
16
+
17
+ COLOR_TABLE = {
18
+ :black => ["0", "1"],
19
+ :red => ["1", "4"],
20
+ :green => ["2", "3"],
21
+ :yellow => ["3", "8"],
22
+ :blue => ["4", "12"],
23
+ :magenta => ["5", "13"],
24
+ :cyan => ["6", "11"],
25
+ :white => ["7", "0"],
26
+ }
27
+ COLOR_T2I_TABLE = Hash[COLOR_TABLE.map{|r| r[1] }]
28
+ COLOR_I2T_TABLE = Hash[COLOR_TABLE.map{|r| r[1].reverse }]
29
+
30
+ RE_TERMINAL_SEQUENCE = /(\e\[(?:\d+(?:;\d+)*)m)/
31
+
32
+ extend self
33
+ def t2i(str)
34
+ str.gsub(RE_TERMINAL_SEQUENCE) do |part|
35
+ meta_to_irc(term_ansi_to_meta(part))
36
+ end
37
+ end
38
+
39
+ def term_ansi_to_meta(part)
40
+ meta = {}
41
+ sequences = part.tr("\e[m", '').split(';')
42
+ sequences.each do |sequence|
43
+ # TODO: DRY...
44
+ case sequence
45
+ when "0"
46
+ meta[:reset] = true
47
+ when "1"
48
+ meta[:bold] = true
49
+ when "4"
50
+ meta[:underline] = true
51
+ when /^3[0-7]$/
52
+ meta[:foreground] = sequence[1]
53
+ when /^4[0-7]$/
54
+ meta[:background] = sequence[1]
55
+ end
56
+ end
57
+ return meta
58
+ end
59
+
60
+ def meta_to_irc(meta)
61
+ words = ""
62
+ if meta[:reset]
63
+ words << ATTRIBUTE_TABLE[:reset][1]
64
+ end
65
+ if meta[:bold]
66
+ words << ATTRIBUTE_TABLE[:bold][1]
67
+ end
68
+ if meta[:underline]
69
+ words << ATTRIBUTE_TABLE[:underline][1]
70
+ end
71
+
72
+ if meta[:foreground] or meta[:background]
73
+ f = meta[:foreground]
74
+ b = meta[:background]
75
+ words << "\x03"
76
+ if f and !b
77
+ words << "#{COLOR_T2I_TABLE[f]}"
78
+ else
79
+ words << "#{f && COLOR_T2I_TABLE[f]},#{COLOR_T2I_TABLE[b]}"
80
+ end
81
+ end
82
+ return words
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module Term2IRC
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'term2irc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "term2irc"
8
+ spec.version = Term2IRC::VERSION
9
+ spec.authors = ["Uchio KONDO"]
10
+ spec.email = ["udzura@udzura.jp"]
11
+ spec.summary = %q{Terminal color to IRC color}
12
+ spec.description = %q{Terminal color to IRC color. Experimental.}
13
+ spec.homepage = "https://github.com/udzura/term2irc"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_development_dependency "test-unit", ">= 3"
25
+ spec.add_development_dependency "test-unit-rr"
26
+ spec.add_development_dependency "test-unit-power_assert"
27
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ require 'test/unit/rr'
3
+ require 'test/unit/power_assert'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+
8
+ require 'term2irc'
@@ -0,0 +1,8 @@
1
+ require 'helper'
2
+
3
+ class Term2IRCTest < Test::Unit::TestCase
4
+ test 'simple convert' do
5
+ result = Term2IRC.t2i("\e[1;4;30;43mgood morning\e[0m")
6
+ assert_equal "\u0002\u001F\u00031,8good morning\u000F", result
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: term2irc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Uchio KONDO
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit-rr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit-power_assert
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Terminal color to IRC color. Experimental.
84
+ email:
85
+ - udzura@udzura.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/term2irc.rb
96
+ - lib/term2irc/version.rb
97
+ - term2irc.gemspec
98
+ - test/helper.rb
99
+ - test/lib/test_term2irc.rb
100
+ homepage: https://github.com/udzura/term2irc
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.14
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Terminal color to IRC color
124
+ test_files:
125
+ - test/helper.rb
126
+ - test/lib/test_term2irc.rb