ttycoke 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ ## EMACS
2
+ *~
3
+ \#*
4
+ .\#*
5
+
6
+ ## VIM
7
+ *.swp
8
+
9
+ ## PROJECT::SPECIFIC
10
+ TAGS
11
+ *.log
12
+ *.gem
13
+ .bundle
14
+ Gemfile.lock
15
+ pkg
16
+ .yardoc
data/.togglerc ADDED
@@ -0,0 +1,10 @@
1
+ ;; -*- mode: emacs-lisp; -*-
2
+
3
+ (add-to-list
4
+ 'toggle-mapping-styles
5
+ '(ttycoke
6
+ ("test/ttycoke/test_\\1.rb" . "lib/ttycoke/\\1.rb")
7
+ ("test/test_\\1.rb" . "lib/\\1.rb")
8
+ ("test_\\1.rb" . "\\1.rb")))
9
+
10
+ (buffer-toggle-style 'ttycoke)
data/.tork.rb ADDED
@@ -0,0 +1,2 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'tork/config/logdir'
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 1.9.2
4
+ - rbx
5
+
6
+ script: "rake"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2012 Jose Pablo Barrantes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # TTYCoke [![Build Status](https://secure.travis-ci.org/jpablobr/ttycoke.png?branch=master)][travis]
2
+
3
+ [travis]: http://travis-ci.org/jpablobr/ttycoke
4
+
5
+ TTYCoke lets one modify the colorset of a running program (that
6
+ display output to the command-line) based on predefined regular
7
+ expression. Basically it's wrapper around the program, executing it
8
+ and parsing its stdout stream (where it will apply the matching
9
+ rules/colors).
10
+
11
+ ## <a name="Before-After"></a>Before/After
12
+
13
+ [![before](http://i.imgur.com/nIen0.png)][before] [![after](http://i.imgur.com/4iVkc.png)][after]
14
+
15
+ [before]: http://i.imgur.com/nIen0.png
16
+ [after]: http://i.imgur.com/4iVkc.png
17
+
18
+ Initial disclaimer! This mess is raw, like sushi. So, haters to the left.
19
+
20
+ anyway,
21
+
22
+ ## <a name="Installation"></a>Installation :)
23
+
24
+ For specific Ruby version requirements, see the [Travis build](http://travis-ci.org/#!/jpablobr/ttycoke). ATM > 1.9.
25
+
26
+ With RubyGems, simply open a terminal and type:
27
+
28
+ $ {sudo} gem install ttycoke
29
+
30
+ Local installation:
31
+
32
+ [Download](http://github.com/jpablobr/ttycoke/download) the tarball package and:
33
+
34
+ $ tar -xvzf ttycoke-{version}.tgz
35
+
36
+ or
37
+
38
+ $ git clone https://github.com/jpablobr/ttycoke.git
39
+
40
+ then
41
+
42
+ $ cd ttycoke-{version}
43
+ $ {sudo} rake install
44
+
45
+ Now you are ready to start coking!
46
+
47
+ ## <a name="Usage"></a>Usage
48
+
49
+ $ ttycoke {program-name}
50
+
51
+ If the program exist in the config file, it will use its rules to `ttycoke`
52
+ it, otherwise it will fallback to its normal execution.
53
+
54
+ You can also define your own rules for things such as `tailing` your logs! Something like the following should work:
55
+
56
+ Create an executable shell script and name it lets say, `my_awesome_app_logs.sh` with:
57
+
58
+ #!/bin/sh
59
+ tail -f ~/apps/my_awesome_app/log/**/*.log
60
+
61
+ Then in your terminal you can `ttycoke` it as such:
62
+
63
+ $ ttycoke my_awesome_app_logs.sh # <3<3<3
64
+
65
+ if you were creative enough, you'll be seeing rainbows!
66
+
67
+ Again, it's just a wrapper around the program, It just parses it
68
+ stdout stream, so its capable of much more!
69
+
70
+ ## <a name="Configuration"></a>Configuration
71
+ The following rake task will copy the `ttycoke/config/config.yaml` file to your `$HOME` directory as `.ttycokerc`.
72
+
73
+ $ rake setup
74
+
75
+ This file contains the regular expression rules and it's also where you'll be adding yours!
76
+
77
+ ## <a name="How-it-works"></a>How it works
78
+
79
+ Basically it's just 1:1 match to the specified colors in the regular
80
+ expression groups. So for example, with the following rule:
81
+
82
+ ``` yaml
83
+ lsmod:
84
+ regex: !ruby/regexp
85
+ /^(?<green>\w+)(?<uncolored>\s+)(?<blue>\d+)(?<uncolored>\s+)(?<yellow>\d+)(?<magenta>.+)/
86
+
87
+ ```
88
+
89
+ the lsmod program will be matched as follows: (I know kind of obvious)
90
+
91
+ '/^(?<green>\w+)(?<uncolored>\s+)(?<blue>\d+)(?<uncolored>\s+)(?<yellow>\d+)(?<magenta>.+)/'
92
+ | | | | | |
93
+ | | | | | \_: magenta
94
+ | | | | \_: yellow
95
+ | | | \_: uncolored
96
+ | | \_:blue
97
+ | \_:uncolored
98
+ \_:green
99
+
100
+ Based on that you can now take it a bit further and for example the
101
+ following will create a green/red TDD kind of output:
102
+
103
+ ((?<green>success)|(?<red>fail|error))
104
+
105
+ The first screenshot is based of the following:
106
+
107
+ ``` yaml
108
+ tail_tork_logs:
109
+ -
110
+ results:
111
+ regex: !ruby/regexp
112
+ /^(?<underscore>Finished.*)/
113
+ error:
114
+ regex: !ruby/regexp
115
+ /(?<red>.+(Error|Failure):)/
116
+ expected:
117
+ regex: !ruby/regexp
118
+ /(?<blue>--- expected)/
119
+ expected-string:
120
+ regex: !ruby/regexp
121
+ /(?<blue>-\".+)/
122
+ actual:
123
+ regex: !ruby/regexp
124
+ /(?<red>\++ actual)/
125
+ actual-string:
126
+ regex: !ruby/regexp
127
+ /(?<red>\+\".+)/
128
+ at:
129
+ regex: !ruby/regexp
130
+ /(?<on_yellow>@.+)/
131
+ stats:
132
+ regex: !ruby/regexp
133
+ /(?<white>\d+ tests, )(?<green>\d+ assertions, )(?<magenta>\d+ failures, )(?<red>\d+ errors, )(?<yellow>\d+ skips)/
134
+ ```
135
+
136
+ and the `tail_tork_logs` looks like this:
137
+
138
+ #!/bin/sh
139
+
140
+ tail -f log/test/**/*.log
141
+
142
+ That's just from `tailing` the ouput of the [Tork](https://github.com/sunaku/tork) continuous testing framework.
143
+
144
+ ## <a name="todo"></a>TODO
145
+ * Add more sample regular expression parsers.
146
+
147
+ ## <a name="copyright"></a>Copyright
148
+ Copyright (c) 2012 Jose Pablo Barrantes. See [LICENSE][] for details.
149
+
150
+ [license]: https://github.com/jpablobr/ttycoke/blob/master/LICENSE
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'bundler/gem_tasks'
4
+
5
+ namespace :test do
6
+ Rake::TestTask.new do |t|
7
+ t.name = "minitest"
8
+ t.libs << "test"
9
+ t.test_files = FileList['test/ttycoke/test_*.rb', 'test/test_*.rb']
10
+ t.verbose = true
11
+ end
12
+ end
13
+
14
+ desc "install the rc file into user's home directory"
15
+ task :setup do
16
+ if File.exist?(File.join(ENV['HOME'], ".ttycokerc"))
17
+ puts "#{File.join(ENV['HOME'], '.ttycokerc')} already exist."
18
+ else
19
+ puts "Coping .ttycokerc to $HOME directory"
20
+ system %Q{cp "$PWD/config/config.yaml" "$HOME/.ttycokerc"}
21
+ puts "done."
22
+ end
23
+ end
24
+
25
+ task :default => "test:minitest"
data/bin/ttycoke ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'ttycoke'
4
+ include TTYCoke::Log
5
+
6
+ # Stdout/stderr should not buffer output
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ TTYCoke::CLI.new.parse_options(ARGV)
@@ -0,0 +1,5 @@
1
+ # This file imports all the rules from the ttycoke.d directory.
2
+ import:
3
+ - /ttycoke.d/lsmod.yaml
4
+ - /ttycoke.d/id.yaml
5
+ - /ttycoke.d/tail_tork_logs.yaml
@@ -0,0 +1,4 @@
1
+ id:
2
+ clrs:
3
+ regex: !ruby/regexp
4
+ /(?<green>\w+=)(?<yellow>\d+)/
@@ -0,0 +1,3 @@
1
+ lsmod:
2
+ regex: !ruby/regexp
3
+ /^(?<green>\w+)(?<uncolored>\s+)(?<blue>\d+)(?<uncolored>\s+)(?<yellow>\d+)(?<red>.+)/
@@ -0,0 +1,14 @@
1
+ tail-focus.sh:
2
+ -
3
+ first:
4
+ regex: !ruby/regexp
5
+ /(?<red># \w+)/
6
+ second:
7
+ regex: !ruby/regexp
8
+ /(?<yellow>## \w+)/
9
+ third:
10
+ regex: !ruby/regexp
11
+ /(?<green>### \w+)/
12
+ fouth:
13
+ regex: !ruby/regexp
14
+ /(?<blue>#### \w+)/
@@ -0,0 +1,26 @@
1
+ tail_tork_logs:
2
+ -
3
+ results:
4
+ regex: !ruby/regexp
5
+ /^(?<underscore>Finished.*)/
6
+ error:
7
+ regex: !ruby/regexp
8
+ /(?<red>.+(Error|Failure):)/
9
+ expected:
10
+ regex: !ruby/regexp
11
+ /(?<blue>--- expected)/
12
+ expected-string:
13
+ regex: !ruby/regexp
14
+ /(?<blue>-\".+)/
15
+ actual:
16
+ regex: !ruby/regexp
17
+ /(?<red>\++ actual)/
18
+ actual-string:
19
+ regex: !ruby/regexp
20
+ /(?<red>\+\".+)/
21
+ at:
22
+ regex: !ruby/regexp
23
+ /(?<on_yellow>@.+)/
24
+ stats:
25
+ regex: !ruby/regexp
26
+ /(?<white>\d+ tests, )(?<green>\d+ assertions, )(?<magenta>\d+ failures, )(?<red>\d+ errors, )(?<yellow>\d+ skips)/
@@ -0,0 +1,8 @@
1
+ top:
2
+ -
3
+ tasks:
4
+ regex: !ruby/regexp
5
+ /(?<green>Tasks:.*)/
6
+ tasks:
7
+ regex: !ruby/regexp
8
+ /(?<blue>CPU.*)/