rubcat 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a35fae84b7496cbd5a933f78ea5805780c04f7e
4
+ data.tar.gz: 90707fddbf577dab159f83ae22946756a0c54560
5
+ SHA512:
6
+ metadata.gz: a8a02c5bcb9ecc5c0a15154a48e3814f31f668c65bb704f83391c3575887e2ef7f295d04ca21d59ef77579e8716fdd8a87b74b40364ed8067ee91f441ea03a65
7
+ data.tar.gz: febcc58bb6278ac07908713f17717c9911dc78f0f41cdcfc215b8f3bf016c0f41535c3541bd8dbfa7f9716b8d50ce332253cb81254dc92ae08c1db0fef515469
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubcat.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 polamjag
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,23 @@
1
+ # rubcat
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubcat`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Just execute:
10
+
11
+ $ gem install rubcat
12
+
13
+ ## Usage
14
+
15
+ TODO: Write usage instructions here
16
+
17
+ ## Contributing
18
+
19
+ 1. Fork it ( https://github.com/polamjag/rubcat/fork )
20
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
21
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
22
+ 4. Push to the branch (`git push origin my-new-feature`)
23
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/rubcat ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pty'
4
+ require 'optparse'
5
+
6
+ require 'rubcat'
7
+
8
+ cmd = "adb logcat"
9
+
10
+ opt = OptionParser.new
11
+
12
+ OPTS = {}
13
+
14
+ opt.on('-d') { |v| cmd << " -d" }
15
+ opt.on('-l {V,D,I,W,E,F}', '--level={V,D,I,W,E,F}', 'Minimul level to display') { |v|
16
+ if %w{V D I W E F}.include? v
17
+ OPTS[:min_level] = v.to_sym
18
+ else
19
+ raise OptionParser::ParseError, "Invalid choice: 'A' (choose from 'V', 'D', 'I', 'W', 'E', 'F')"
20
+ end
21
+ }
22
+ opt.on('-s DEVICE_SERIAL', '--serial=DEVICE_SERIAL') { |v| cmd << " -s #{v}" }
23
+ opt.on('-d', 'Use first device for log input (adb -d option)') { |v| cmd << " -d" }
24
+ opt.on('-e', 'Use first emulator for log input (adb -e option)') { |v| cmd << " -e" }
25
+ opt.on('--tag-length=LENGTH', 'Length of tag shown in left of screen (default is 25)') { |v| OPTS[:tag_length] = Integer(v) }
26
+ opt.on('--split-tags', 'Insert empty line between tags') { |v| OPTS[:split_tags] = true }
27
+ opt.parse!
28
+
29
+ pl = Rubcat::PrettyLogcat.new OPTS
30
+
31
+ begin
32
+ PTY.spawn cmd do |stdout, stdin, pid|
33
+ begin
34
+ # parse and print output
35
+ stdout.each do |line|
36
+ begin
37
+ pl.echo line
38
+ rescue => e
39
+ puts line
40
+ end
41
+ end
42
+ rescue Errno::EIO
43
+ puts "Errno:EIO"
44
+ end
45
+ end
46
+ rescue PTY::ChildExited
47
+ puts "PTY::ChildExited"
48
+ end
@@ -0,0 +1,33 @@
1
+ class String
2
+ # http://stackoverflow.com/questions/1489183/colorized-ruby-output
3
+ def black; "\033[30m#{self}\033[0m" end
4
+ def red; "\033[31m#{self}\033[0m" end
5
+ def green; "\033[32m#{self}\033[0m" end
6
+ def brown; "\033[33m#{self}\033[0m" end
7
+ def blue; "\033[34m#{self}\033[0m" end
8
+ def magenta; "\033[35m#{self}\033[0m" end
9
+ def cyan; "\033[36m#{self}\033[0m" end
10
+ def gray; "\033[37m#{self}\033[0m" end
11
+ def bg_black; "\033[40m#{self}\033[0m" end
12
+ def bg_red; "\033[41m#{self}\033[0m" end
13
+ def bg_green; "\033[42m#{self}\033[0m" end
14
+ def bg_brown; "\033[43m#{self}\033[0m" end
15
+ def bg_blue; "\033[44m#{self}\033[0m" end
16
+ def bg_magenta; "\033[45m#{self}\033[0m" end
17
+ def bg_cyan; "\033[46m#{self}\033[0m" end
18
+ def bg_gray; "\033[47m#{self}\033[0m" end
19
+ def bold; "\033[1m#{self}\033[22m" end
20
+ def reverse_color; "\033[7m#{self}\033[27m" end
21
+
22
+ def randomize_color
23
+ "\033[3#{self.hash % 6 + 1}m#{self}\033[0m"
24
+ end
25
+
26
+ def trim_and_rjust(len)
27
+ if self.length > len
28
+ self[-len .. -1]
29
+ else
30
+ self.rjust len
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,67 @@
1
+ module Rubcat
2
+ class PrettyLogcat
3
+ attr_reader :opt, :last_tag
4
+
5
+ def initialize(options)
6
+ @opt = {
7
+ min_level: :V,
8
+ tag_length: 25,
9
+ split_tags: false
10
+ }.merge options
11
+ end
12
+
13
+ def parse_message(mes)
14
+ {
15
+ type: mes.match(/^[VDIWEFS]/).to_s,
16
+ tag: mes.match(/^.\/(.*)\(\s*[0-9]+\):/)[1].strip,
17
+ pid: mes.match(/\(\s*([0-9]+)\):/)[1],
18
+ message: mes.match(/\(\s*[0-9]+\):\s(.*)/)[1]
19
+ }
20
+ end
21
+
22
+ def colorize_type(type)
23
+ case type
24
+ when "V"
25
+ " #{type} ".bold.bg_gray.black
26
+ when "D"
27
+ " #{type} ".bold.bg_blue
28
+ when "I"
29
+ " #{type} ".bold.bg_green
30
+ when "W"
31
+ " #{type} ".bold.bg_brown
32
+ else
33
+ " #{type} ".bold.bg_red
34
+ end
35
+ end
36
+
37
+ KNOWN_TAGS = %w{dalvikvm art dex2oat}
38
+
39
+ def format_tag(tag)
40
+ unless tag == @last_tag
41
+ @last_tag = tag
42
+ puts if @opt[:split_tags]
43
+ if KNOWN_TAGS.include? tag
44
+ tag.trim_and_rjust(@opt[:tag_length]).bold.black.bg_gray
45
+ else
46
+ tag.trim_and_rjust(@opt[:tag_length]).randomize_color.bold
47
+ end
48
+ else
49
+ " " * @opt[:tag_length]
50
+ end
51
+ end
52
+
53
+ def prettify(mes)
54
+ buf = format_tag mes[:tag]
55
+
56
+ buf += " "
57
+ buf += colorize_type mes[:type]
58
+ buf += " "
59
+ buf += mes[:message]
60
+ buf
61
+ end
62
+
63
+ def echo(mes)
64
+ puts prettify parse_message mes
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Rubcat
2
+ VERSION = "0.1.0"
3
+ end
data/lib/rubcat.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "core_ext/string"
2
+
3
+ require "rubcat/version"
4
+ require "rubcat/pretty_logcat"
5
+
6
+ module Rubcat
7
+ end
data/rubcat.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubcat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubcat"
8
+ spec.version = Rubcat::VERSION
9
+ spec.authors = ["polamjag"]
10
+ spec.email = ["s@polamjag.info"]
11
+
12
+ spec.summary = %q{pidcat, pretty adb logcat in Ruby}
13
+ spec.description = %q{pidcat, pretty adb logcat in Ruby. without any dependencies. can be installed and updated with gem command!}
14
+ spec.homepage = "https://github.com/rubcat"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubcat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - polamjag
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-20 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.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
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
+ description: pidcat, pretty adb logcat in Ruby. without any dependencies. can be installed
42
+ and updated with gem command!
43
+ email:
44
+ - s@polamjag.info
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/rubcat
57
+ - lib/core_ext/string.rb
58
+ - lib/rubcat.rb
59
+ - lib/rubcat/pretty_logcat.rb
60
+ - lib/rubcat/version.rb
61
+ - rubcat.gemspec
62
+ homepage: https://github.com/rubcat
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.5
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: pidcat, pretty adb logcat in Ruby
86
+ test_files: []
87
+ has_rdoc: