rubcat 0.5.2 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7195ee684462e7b33de2befa92e6d2d71ae35401
4
- data.tar.gz: 23df5d73c0338b5b473e00fbd72b071b64cf7260
3
+ metadata.gz: bb580474c09c7997b57faf5a48f3b448aaec89b7
4
+ data.tar.gz: 903799ea6617203a66ed4721da9fd4d507b742cb
5
5
  SHA512:
6
- metadata.gz: 1b2f57ee39e302ffe3585b45a06620e9d519f4e95bc44b11c1dd18d4438ea2cedcfc9bbdc1ca0823e512ce59b230bc1c82070b8a665bb7ea1e04357dbae5682e
7
- data.tar.gz: 2f84898aee725b718a32b55340eb2f64265404628a9b9cbbd92d2463f2153d49739c26199c8f19d4a7b64a87cd6b2672c8151f5f35cbb4fe592943680d064de1
6
+ metadata.gz: ca66ce662bc0fcdab90ba9bbec4052a4e93eb507821be5d7be8471f85c86d1c80aafa75aaf1e2711871da1682b6b9971b90ded2d39034ca57208e7c2a4b2be5b
7
+ data.tar.gz: 74187438056f98a0c88f06decd83a5002bd6db21526882e18db5fe927c7b3c6f579f07ff512b9efb168a66fa7f16b5ff78e4e1ef27efc68be926390c556d9eeb
data/exe/rubcat CHANGED
@@ -18,7 +18,7 @@ opt.on('-l {V,D,I,W,E,F}', '--level={V,D,I,W,E,F}', 'Minimul level to display')
18
18
  if %w{V D I W E F}.include? v
19
19
  OPTS[:min_level] = v.to_sym
20
20
  else
21
- raise OptionParser::ParseError, "Invalid choice: 'A' (choose from 'V', 'D', 'I', 'W', 'E', 'F')"
21
+ raise OptionParser::ParseError, "Invalid choice: #{v} (choose from 'V', 'D', 'I', 'W', 'E', 'F')"
22
22
  end
23
23
  }
24
24
  opt.on('-s DEVICE_SERIAL', '--serial=DEVICE_SERIAL') { |v| flags << " -s #{v}" }
@@ -42,6 +42,7 @@ begin
42
42
  pl.echo line
43
43
  rescue => e
44
44
  puts line
45
+ puts e if ENV["DEBUG"]
45
46
  end
46
47
  end
47
48
  rescue Errno::EIO
@@ -3,6 +3,7 @@ require 'io/console'
3
3
  module Rubcat
4
4
  class PrettyLogcat
5
5
  attr_reader :opt, :last_tag
6
+ LOG_LEVELS = [:V, :D, :I, :W, :E, :F]
6
7
 
7
8
  def initialize(options)
8
9
  @opt = {
@@ -15,7 +16,7 @@ module Rubcat
15
16
  def parse_message(message)
16
17
  m = message.match(/^([VDIWEFS])\/(.*)\((\s*[0-9]+)\):\s(.*)$/)
17
18
  {
18
- type: m[1],
19
+ type: m[1].to_sym,
19
20
  tag: m[2].strip,
20
21
  pid: m[3],
21
22
  message: m[4]
@@ -24,13 +25,13 @@ module Rubcat
24
25
 
25
26
  def colorize_type(type)
26
27
  case type
27
- when "V"
28
+ when :V
28
29
  " #{type} ".bold.bg_gray.black
29
- when "D"
30
+ when :D
30
31
  " #{type} ".bold.bg_blue
31
- when "I"
32
+ when :I
32
33
  " #{type} ".bold.bg_green
33
- when "W"
34
+ when :W
34
35
  " #{type} ".bold.bg_brown
35
36
  else
36
37
  " #{type} ".bold.bg_red
@@ -39,31 +40,59 @@ module Rubcat
39
40
 
40
41
  KNOWN_TAGS = %w{dalvikvm art dex2oat}
41
42
 
42
- def format_tag(tag)
43
- unless tag == @last_tag
44
- @last_tag = tag
45
- puts if @opt[:split_tags]
46
- if KNOWN_TAGS.include? tag
47
- tag.trim_and_rjust(@opt[:tag_length]).bold.black.bg_gray
43
+ def format_tag(type, tag)
44
+ if type == :normal
45
+ unless tag == @last_tag
46
+ @last_tag = tag
47
+ puts if @opt[:split_tags]
48
+ if KNOWN_TAGS.include? tag
49
+ tag.trim_and_rjust(@opt[:tag_length]).bold.black.bg_gray
50
+ elsif tag == "ActivityManager"
51
+ tag.trim_and_rjust(@opt[:tag_length]).bold
52
+ else
53
+ tag.trim_and_rjust(@opt[:tag_length]).randomize_color.bold
54
+ end
48
55
  else
49
- tag.trim_and_rjust(@opt[:tag_length]).randomize_color.bold
56
+ " " * @opt[:tag_length]
50
57
  end
51
- else
52
- " " * @opt[:tag_length]
58
+ elsif type == :activity_kill
59
+ tag.trim_and_rjust(@opt[:tag_length]).bold.bg_red
60
+ elsif type == :activity_start
61
+ tag.trim_and_rjust(@opt[:tag_length]).bold.bg_green
53
62
  end
54
63
  end
55
64
 
65
+
56
66
  def wrap_message(mes, type)
57
67
  mes.scan(/.{1,#{IO.console.winsize[1] - @opt[:tag_length] - 5}}/).join("\n#{' ' * @opt[:tag_length]} #{type} ")
58
68
  end
59
69
 
60
- def prettify(mes)
70
+ def pretty_print(mes)
71
+ return if (LOG_LEVELS.find_index @opt[:min_level]) > (LOG_LEVELS.find_index mes[:type])
72
+
61
73
  type = colorize_type mes[:type]
62
- "#{format_tag mes[:tag]} #{type} #{wrap_message mes[:message], type}"
74
+
75
+ if mes[:tag] == "ActivityManager"
76
+ if mes[:message] =~ /^Killing/
77
+ m = mes[:message].match(/^Killing ([0-9]+):([^\s\/]+)/)
78
+ puts
79
+ puts "#{format_tag :activity_kill, "Killing process"} #{wrap_message(m[2] + " (pid " + m[1], "")})"
80
+ puts
81
+ elsif mes[:message] =~ /^Start proc/
82
+ m = mes[:message].match(/^Start proc (.*)$/)
83
+ puts
84
+ puts "#{format_tag :activity_start, "Start process"} #{wrap_message(m[1], "")}"
85
+ puts
86
+ else
87
+ puts "#{format_tag :normal, mes[:tag]} #{type} #{wrap_message mes[:message], type}"
88
+ end
89
+ else
90
+ puts "#{format_tag :normal, mes[:tag]} #{type} #{wrap_message mes[:message], type}"
91
+ end
63
92
  end
64
93
 
65
94
  def echo(mes)
66
- puts prettify parse_message mes
95
+ pretty_print parse_message mes
67
96
  end
68
97
  end
69
98
  end
@@ -1,3 +1,3 @@
1
1
  module Rubcat
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - polamjag