ttycoke 0.2.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.
Files changed (75) hide show
  1. data/.gitignore +16 -0
  2. data/.togglerc +10 -0
  3. data/.tork.rb +2 -0
  4. data/.travis.yml +6 -0
  5. data/LICENSE +21 -0
  6. data/README.md +150 -0
  7. data/Rakefile +25 -0
  8. data/bin/ttycoke +10 -0
  9. data/config/config.yaml +5 -0
  10. data/config/ttycoke.d/id.yaml +4 -0
  11. data/config/ttycoke.d/lsmod.yaml +3 -0
  12. data/config/ttycoke.d/tail_focus.yaml +14 -0
  13. data/config/ttycoke.d/tail_tork_logs.yaml +26 -0
  14. data/config/ttycoke.d/top.yaml +8 -0
  15. data/doc/TTYCoke/ANSI.html +598 -0
  16. data/doc/TTYCoke/ANSIColor.html +586 -0
  17. data/doc/TTYCoke/CLI.html +242 -0
  18. data/doc/TTYCoke/Config/Configuration.html +210 -0
  19. data/doc/TTYCoke/Config.html +347 -0
  20. data/doc/TTYCoke/Errors/CustomizationFailed.html +135 -0
  21. data/doc/TTYCoke/Errors/FallbackError.html +216 -0
  22. data/doc/TTYCoke/Errors/ProgramNotFoundError.html +216 -0
  23. data/doc/TTYCoke/Errors/TTYCokeError.html +206 -0
  24. data/doc/TTYCoke/Errors/TTYCokeTypeError.html +216 -0
  25. data/doc/TTYCoke/Errors/YamlSyntaxError.html +216 -0
  26. data/doc/TTYCoke/Errors.html +106 -0
  27. data/doc/TTYCoke/LineParser.html +210 -0
  28. data/doc/TTYCoke/Log.html +391 -0
  29. data/doc/TTYCoke/Parser.html +210 -0
  30. data/doc/TTYCoke/Platform.html +398 -0
  31. data/doc/TTYCoke/Run.html +198 -0
  32. data/doc/TTYCoke/TTYCokeLogFormat.html +204 -0
  33. data/doc/TTYCoke/Version.html +136 -0
  34. data/doc/TTYCoke.html +110 -0
  35. data/doc/_index.html +279 -0
  36. data/doc/class_list.html +47 -0
  37. data/doc/css/common.css +1 -0
  38. data/doc/css/full_list.css +55 -0
  39. data/doc/css/style.css +322 -0
  40. data/doc/file.README.html +153 -0
  41. data/doc/file_list.html +49 -0
  42. data/doc/frames.html +13 -0
  43. data/doc/index.html +153 -0
  44. data/doc/js/app.js +205 -0
  45. data/doc/js/full_list.js +167 -0
  46. data/doc/js/jquery.js +16 -0
  47. data/doc/method_list.html +238 -0
  48. data/doc/top-level-namespace.html +130 -0
  49. data/lib/ttycoke/ansi.rb +127 -0
  50. data/lib/ttycoke/cli.rb +33 -0
  51. data/lib/ttycoke/config.rb +39 -0
  52. data/lib/ttycoke/errors.rb +40 -0
  53. data/lib/ttycoke/import.rb +72 -0
  54. data/lib/ttycoke/log.rb +84 -0
  55. data/lib/ttycoke/parser.rb +59 -0
  56. data/lib/ttycoke/platform.rb +33 -0
  57. data/lib/ttycoke/run.rb +59 -0
  58. data/lib/ttycoke/version.rb +10 -0
  59. data/lib/ttycoke.rb +15 -0
  60. data/test/data/ansi_lines.yaml +12 -0
  61. data/test/data/config.yaml +4 -0
  62. data/test/data/syntax_error_config.yaml +6 -0
  63. data/test/data/ttycoke.d/id.yaml +4 -0
  64. data/test/data/ttycoke.d/lsmod.yaml +3 -0
  65. data/test/data/ttycoke.d/tail_focus.yaml +14 -0
  66. data/test/data/ttycoke.d/tail_tork_logs.yaml +26 -0
  67. data/test/data/ttycoke.d/top.yaml +8 -0
  68. data/test/test_helper.rb +14 -0
  69. data/test/ttycoke/test_ansi.rb +89 -0
  70. data/test/ttycoke/test_cli.rb +8 -0
  71. data/test/ttycoke/test_config.rb +23 -0
  72. data/test/ttycoke/test_log.rb +22 -0
  73. data/test/ttycoke/test_parser.rb +24 -0
  74. data/ttycoke.gemspec +16 -0
  75. metadata +120 -0
@@ -0,0 +1,89 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+ require 'ttycoke/ansi'
4
+
5
+ class String
6
+ include TTYCoke::ANSI
7
+ end
8
+
9
+ class Color
10
+ extend TTYCoke::ANSI
11
+ end
12
+
13
+ class StringLike
14
+ def initialize(string)
15
+ @string = string
16
+ end
17
+
18
+ def to_str
19
+ @string
20
+ end
21
+ end
22
+
23
+ class ANSITest < MiniTest::Unit::TestCase
24
+ include TTYCoke::ANSI
25
+
26
+ def setup
27
+ @string = "red"
28
+ @string_red = "\e[31mred\e[0m"
29
+ @string_red_on_green = "\e[42m\e[31mred\e[0m\e[0m"
30
+ @string_like = StringLike.new(@string)
31
+ @string_like_red = StringLike.new(@string_red)
32
+ end
33
+
34
+ attr_reader :string, :string_red, :string_red_on_green, :string_like, :string_like_red
35
+
36
+ def test_red
37
+ assert_equal string_red, string.red
38
+ assert_equal string_red, Color.red(string)
39
+ assert_equal string_red, Color.red { string }
40
+ assert_equal string_red, TTYCoke::ANSI.red { string }
41
+ assert_equal string_red, red { string }
42
+ end
43
+
44
+ def test_red_on_green
45
+ assert_equal string_red_on_green, string.red.on_green
46
+ assert_equal string_red_on_green, Color.on_green(Color.red(string))
47
+ assert_equal string_red_on_green, Color.on_green { Color.red { string } }
48
+ assert_equal string_red_on_green,
49
+ TTYCoke::ANSI.on_green { TTYCoke::ANSI.red { string } }
50
+ assert_equal string_red_on_green, on_green { red { string } }
51
+ end
52
+
53
+
54
+ def test_uncolored
55
+ assert_equal string, string_red.uncolored
56
+ assert_equal string, Color.uncolored(string_red)
57
+ assert_equal string, Color.uncolored(string_like_red)
58
+ assert_equal string, Color.uncolored { string_red }
59
+ assert_equal string, Color.uncolored { string_like_red }
60
+ assert_equal string, TTYCoke::ANSI.uncolored { string_red }
61
+ assert_equal string, TTYCoke::ANSI.uncolored { string_like_red }
62
+ assert_equal string, uncolored { string }
63
+ assert_equal string, uncolored { string_like_red }
64
+ assert_equal "", uncolored(Object.new)
65
+ end
66
+
67
+ def test_attributes
68
+ foo = 'foo'
69
+ for (a, _) in TTYCoke::ANSI.attributes
70
+ # skip clear for Ruby 1.9 which implements String#clear to empty the string
71
+ if a != :clear || TTYCoke::ANSI.support?(:clear)
72
+ refute_equal foo, foo_colored = foo.__send__(a)
73
+ assert_equal foo, foo_colored.uncolored
74
+ end
75
+ refute_equal foo, foo_colored = Color.__send__(a, foo)
76
+ assert_equal foo, Color.uncolored(foo_colored)
77
+ refute_equal foo, foo_colored = Color.__send__(a) { foo }
78
+ assert_equal foo, Color.uncolored { foo_colored }
79
+ refute_equal foo, foo_colored = TTYCoke::ANSI.__send__(a) { foo }
80
+ assert_equal foo, TTYCoke::ANSI.uncolored { foo_colored }
81
+ refute_equal foo, foo_colored = __send__(a) { foo }
82
+ assert_equal foo, uncolored { foo_colored }
83
+ end
84
+ end
85
+
86
+ def test_coloring_string_like
87
+ assert_equal "\e[31mred\e[0m", red(string_like)
88
+ end
89
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class CLITest < MiniTest::Unit::TestCase
5
+ def setup
6
+ assert @cli = TTYCoke::CLI.new
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class ConfigTest < MiniTest::Unit::TestCase
5
+ include TTYCoke::Log
6
+
7
+ def setup
8
+ @config = TTYCoke::Config.new(File.dirname(__FILE__) + '/../data/config.yaml')
9
+ end
10
+
11
+ def test_find_program
12
+ assert @config.find_program('lsmod')
13
+ refute @config.find_program('do not exist')
14
+ end
15
+
16
+ def test_yaml_file_syntax_error
17
+ buggie_test_file = File.dirname(__FILE__) + '/../data/syntax_error_config.yaml'
18
+ exception = assert_raises(TTYCoke::Errors::YamlSyntaxError) {
19
+ TTYCoke::Config.new(buggie_test_file)
20
+ }
21
+ end
22
+
23
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class LogTest < MiniTest::Unit::TestCase
5
+ include TTYCoke::Log
6
+
7
+ def test_logger_can_optionally_be_redefined
8
+ log_file = File.dirname(__FILE__) + '/../data/my-test-log.log'
9
+ @@logger = Logger.new(log_file)
10
+ assert_match @@logger.inspect, /my-test-log.log/
11
+ end
12
+
13
+ def test_log_rescue_method
14
+ exception = assert_raises (ArgumentError) { log_rescue }
15
+ assert_equal("wrong number of arguments (0 for 3)", exception.message)
16
+ end
17
+
18
+ def test_log_rescue_method
19
+ exception = assert_raises (ArgumentError) { log_debug }
20
+ assert_equal("wrong number of arguments (0 for 5)", exception.message)
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class ParserTest < MiniTest::Unit::TestCase
5
+ def setup
6
+ @config = TTYCoke::Config.new(File.dirname(__FILE__) + '/../data/config.yaml')
7
+ ansi_line_file = File.dirname(__FILE__) + '/../data/ansi_lines.yaml'
8
+ @ansi_lines = YAML::load(File.open(File.expand_path(ansi_line_file)))
9
+ end
10
+
11
+ def test_one_regexp_match
12
+ prgm = @config.find_program('lsmod')
13
+ line = @ansi_lines.fetch('lsmod').fetch('line')
14
+ expect = @ansi_lines.fetch('lsmod').fetch('exp')
15
+ assert_equal expect, TTYCoke::Parser.coke!(prgm, line)
16
+ end
17
+
18
+ def test_multiple_regexps_match
19
+ prgm = @config.find_program('tail_tork_logs')
20
+ @ansi_lines.fetch('tail_tork_logs')[0].each { |p|
21
+ assert_equal p[1].fetch('exp'), TTYCoke::Parser.coke!(prgm, p[1].fetch('line'))
22
+ }
23
+ end
24
+ end
data/ttycoke.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+ $:.unshift File.expand_path("../lib", __FILE__)
3
+ require 'ttycoke/version'
4
+ Gem::Specification.new do |s|
5
+ s.name = 'ttycoke'
6
+ s.version = TTYCoke::Version::STRING
7
+ s.platform = Gem::Platform::RUBY
8
+ s.date = '2012-01-01'
9
+ s.authors = ["José Pablo Barrantes"]
10
+ s.email = 'xjpablobrx@gmail.com'
11
+ s.summary = 'TTYCoke enables coloring on ANSI terminals based on regular expressions.'
12
+ s.homepage = 'http://jpablobr.github.com/ttycoke'
13
+ s.files = `git ls-files`.split("\n")
14
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
15
+ s.require_path = 'lib'
16
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ttycoke
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - José Pablo Barrantes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: xjpablobrx@gmail.com
16
+ executables:
17
+ - ttycoke
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .togglerc
23
+ - .tork.rb
24
+ - .travis.yml
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - bin/ttycoke
29
+ - config/config.yaml
30
+ - config/ttycoke.d/id.yaml
31
+ - config/ttycoke.d/lsmod.yaml
32
+ - config/ttycoke.d/tail_focus.yaml
33
+ - config/ttycoke.d/tail_tork_logs.yaml
34
+ - config/ttycoke.d/top.yaml
35
+ - doc/TTYCoke.html
36
+ - doc/TTYCoke/ANSI.html
37
+ - doc/TTYCoke/ANSIColor.html
38
+ - doc/TTYCoke/CLI.html
39
+ - doc/TTYCoke/Config.html
40
+ - doc/TTYCoke/Config/Configuration.html
41
+ - doc/TTYCoke/Errors.html
42
+ - doc/TTYCoke/Errors/CustomizationFailed.html
43
+ - doc/TTYCoke/Errors/FallbackError.html
44
+ - doc/TTYCoke/Errors/ProgramNotFoundError.html
45
+ - doc/TTYCoke/Errors/TTYCokeError.html
46
+ - doc/TTYCoke/Errors/TTYCokeTypeError.html
47
+ - doc/TTYCoke/Errors/YamlSyntaxError.html
48
+ - doc/TTYCoke/LineParser.html
49
+ - doc/TTYCoke/Log.html
50
+ - doc/TTYCoke/Parser.html
51
+ - doc/TTYCoke/Platform.html
52
+ - doc/TTYCoke/Run.html
53
+ - doc/TTYCoke/TTYCokeLogFormat.html
54
+ - doc/TTYCoke/Version.html
55
+ - doc/_index.html
56
+ - doc/class_list.html
57
+ - doc/css/common.css
58
+ - doc/css/full_list.css
59
+ - doc/css/style.css
60
+ - doc/file.README.html
61
+ - doc/file_list.html
62
+ - doc/frames.html
63
+ - doc/index.html
64
+ - doc/js/app.js
65
+ - doc/js/full_list.js
66
+ - doc/js/jquery.js
67
+ - doc/method_list.html
68
+ - doc/top-level-namespace.html
69
+ - lib/ttycoke.rb
70
+ - lib/ttycoke/ansi.rb
71
+ - lib/ttycoke/cli.rb
72
+ - lib/ttycoke/config.rb
73
+ - lib/ttycoke/errors.rb
74
+ - lib/ttycoke/import.rb
75
+ - lib/ttycoke/log.rb
76
+ - lib/ttycoke/parser.rb
77
+ - lib/ttycoke/platform.rb
78
+ - lib/ttycoke/run.rb
79
+ - lib/ttycoke/version.rb
80
+ - test/data/ansi_lines.yaml
81
+ - test/data/config.yaml
82
+ - test/data/syntax_error_config.yaml
83
+ - test/data/ttycoke.d/id.yaml
84
+ - test/data/ttycoke.d/lsmod.yaml
85
+ - test/data/ttycoke.d/tail_focus.yaml
86
+ - test/data/ttycoke.d/tail_tork_logs.yaml
87
+ - test/data/ttycoke.d/top.yaml
88
+ - test/test_helper.rb
89
+ - test/ttycoke/test_ansi.rb
90
+ - test/ttycoke/test_cli.rb
91
+ - test/ttycoke/test_config.rb
92
+ - test/ttycoke/test_log.rb
93
+ - test/ttycoke/test_parser.rb
94
+ - ttycoke.gemspec
95
+ homepage: http://jpablobr.github.com/ttycoke
96
+ licenses: []
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.10
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: TTYCoke enables coloring on ANSI terminals based on regular expressions.
119
+ test_files: []
120
+ has_rdoc: