console 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6d335e8b78f82a73be6a3cf6ab279594277fe4fd492d82db5da34695643219e
4
- data.tar.gz: 22dd7d9b66f54a1bd38e563158d5ff58148e9f744d06a4d391ef8ae01676bb9d
3
+ metadata.gz: dc372565fdcca828bd36391080df923729df6f902637a56740a2f7eb3e639188
4
+ data.tar.gz: be63ec825ce033d4f882ff98ee038811b98d72dedfa577bfdb8453eeebf3dcd3
5
5
  SHA512:
6
- metadata.gz: 9c4947d01b98cf603d14444be28815d4e7b6d3e3b7627be3b6f1d4d4d56f97702e7b61827c7c966533d696b73b9a0138b5a74fb2388fec645b5619b2e741ad2e
7
- data.tar.gz: 8ecfe1ee0c30bc99b2662f6095defde0e99c8594a8a49b9c513f14914b80f84c9bc7ee7e13064097ac225a2f9a7a132ebae6b8f31c610cecd4c58e4cbfb77cf7
6
+ metadata.gz: 07d52f0ec479b661e6920d0942f3fa6aab1077706bdab02ab928025ef9c8e66e7066c6d39badac7778276eb1aaa13f5c715218aaf5c658a6b39fb22271d58aea
7
+ data.tar.gz: d05e1500655f528b1f4ccdbaad80cfcdb19dd68ce1cd3201f1736ba0af05e06aa4a6ccd7d79505b6c5c9d8214cf93170a573f342753ed20008ac71aa9c53a73a
@@ -18,9 +18,5 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- module Console
22
- class Generic
23
- def format(buffer, terminal)
24
- end
25
- end
26
- end
21
+ require_relative 'event/spawn'
22
+ require_relative 'event/failure'
@@ -0,0 +1,78 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative 'generic'
22
+
23
+ module Console
24
+ module Event
25
+ class Failure < Generic
26
+ def self.current_working_directory
27
+ Dir.getwd
28
+ rescue # e.g. Errno::EMFILE
29
+ nil
30
+ end
31
+
32
+ def self.for(exception)
33
+ self.new(exception, self.current_working_directory)
34
+ end
35
+
36
+ def initialize(exception, root = nil)
37
+ @exception = exception
38
+ @root = root
39
+ end
40
+
41
+ attr :exception
42
+ attr :root
43
+
44
+ def self.register(terminal)
45
+ terminal[:exception_title] ||= terminal.style(:red, nil, :bold)
46
+ terminal[:exception_detail] ||= terminal.style(:yellow)
47
+ terminal[:exception_backtrace] ||= terminal.style(:red)
48
+ end
49
+
50
+ def format(output, terminal, verbose)
51
+ format_exception(@exception, nil, output, terminal, verbose)
52
+ end
53
+
54
+ def format_exception(exception, prefix = nil, output, terminal, verbose)
55
+ lines = exception.message.lines.map(&:chomp)
56
+
57
+ output.puts " #{prefix}#{terminal[:exception_title]}#{exception.class}#{terminal.reset}: #{lines.shift}"
58
+
59
+ lines.each do |line|
60
+ output.puts " #{terminal[:exception_detail]}#{line}#{terminal.reset}"
61
+ end
62
+
63
+ exception.backtrace&.each_with_index do |line, index|
64
+ path, offset, message = line.split(":")
65
+
66
+ # Make the path a bit more readable
67
+ path.gsub!(/^#{@root}\//, "./") if @root
68
+
69
+ output.puts " #{index == 0 ? "→" : " "} #{terminal[:exception_backtrace]}#{path}:#{offset}#{terminal.reset} #{message}"
70
+ end
71
+
72
+ if exception.cause and verbose
73
+ format_exception(exception.cause, "Caused by ", output, terminal)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,31 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module Console
22
+ module Event
23
+ class Generic
24
+ def self.register(terminal)
25
+ end
26
+
27
+ def format(buffer, terminal)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -21,45 +21,50 @@
21
21
  require_relative 'generic'
22
22
 
23
23
  module Console
24
- class Shell < Generic
25
- def self.for(*arguments, **options)
26
- if arguments.first.is_a?(Hash)
27
- self.new(*arguments, **options)
28
- else
29
- self.new(nil, arguments, **options)
24
+ module Event
25
+ class Spawn < Generic
26
+ def self.for(*arguments, **options)
27
+ if arguments.first.is_a?(Hash)
28
+ self.new(*arguments, **options)
29
+ else
30
+ self.new(nil, arguments, **options)
31
+ end
30
32
  end
31
- end
32
-
33
- def initialize(environment, *arguments, **options)
34
- @environment = environment
35
- @arguments = arguments
36
- @options = options
37
- end
38
-
39
- attr :environment
40
- attr :arguments
41
- attr :options
42
-
43
- def chdir_string(options)
44
- if options and chdir = options[:chdir]
45
- " in #{chdir}"
33
+
34
+ def initialize(environment, *arguments, **options)
35
+ @environment = environment
36
+ @arguments = arguments
37
+ @options = options
46
38
  end
47
- end
48
-
49
- def self.register(terminal)
50
- terminal[:shell_command] ||= terminal.style(:blue, nil, :bold)
51
- end
52
-
53
- def format(output, terminal, verbose)
54
- arguments = @arguments.flatten.collect(&:to_s)
55
39
 
56
- output.puts " #{terminal[:shell_command]}#{arguments.join(' ')}#{terminal.reset}#{chdir_string(options)}"
40
+ attr :environment
41
+ attr :arguments
42
+ attr :options
43
+
44
+ def chdir_string(options)
45
+ if options and chdir = options[:chdir]
46
+ " in #{chdir}"
47
+ end
48
+ end
49
+
50
+ def self.register(terminal)
51
+ terminal[:shell_command] ||= terminal.style(:blue, nil, :bold)
52
+ end
57
53
 
58
- if verbose and @environment
59
- @environment.each do |key, value|
60
- output.puts " export #{key}=#{value}"
54
+ def format(output, terminal, verbose)
55
+ arguments = @arguments.flatten.collect(&:to_s)
56
+
57
+ output.puts " #{terminal[:shell_command]}#{arguments.join(' ')}#{terminal.reset}#{chdir_string(options)}"
58
+
59
+ if verbose and @environment
60
+ @environment.each do |key, value|
61
+ output.puts " export #{key}=#{value}"
62
+ end
61
63
  end
62
64
  end
63
65
  end
64
66
  end
67
+
68
+ # Deprecated.
69
+ Shell = Event::Spawn
65
70
  end
@@ -19,9 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require_relative '../buffer'
22
-
23
- require_relative '../shell'
24
- require_relative '../error'
22
+ require_relative '../event'
25
23
 
26
24
  require_relative 'text'
27
25
  require_relative 'xterm'
@@ -64,8 +62,10 @@ module Console
64
62
  end
65
63
 
66
64
  def register_defaults(terminal)
67
- Shell.register(terminal)
68
- Error.register(terminal)
65
+ Event.constants.each do |constant|
66
+ klass = Event.const_get(constant)
67
+ klass.register(terminal)
68
+ end
69
69
  end
70
70
 
71
71
  UNKNOWN = 'unknown'
@@ -100,8 +100,8 @@ module Console
100
100
  def format_argument(argument, output)
101
101
  case argument
102
102
  when Exception
103
- Error.new(argument).format(output, @terminal, @verbose)
104
- when Generic
103
+ Event::Failure.new(argument).format(output, @terminal, @verbose)
104
+ when Event::Generic
105
105
  argument.format(output, @terminal, @verbose)
106
106
  else
107
107
  format_value(argument, output)
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Console
22
- VERSION = "1.0.0"
22
+ VERSION = "1.1.0"
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -83,12 +83,13 @@ files:
83
83
  - lib/console.rb
84
84
  - lib/console/buffer.rb
85
85
  - lib/console/capture.rb
86
- - lib/console/error.rb
86
+ - lib/console/event.rb
87
+ - lib/console/event/failure.rb
88
+ - lib/console/event/generic.rb
89
+ - lib/console/event/spawn.rb
87
90
  - lib/console/filter.rb
88
- - lib/console/generic.rb
89
91
  - lib/console/logger.rb
90
92
  - lib/console/serialized/logger.rb
91
- - lib/console/shell.rb
92
93
  - lib/console/split.rb
93
94
  - lib/console/terminal.rb
94
95
  - lib/console/terminal/logger.rb
@@ -114,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  - !ruby/object:Gem::Version
115
116
  version: '0'
116
117
  requirements: []
117
- rubygems_version: 3.0.2
118
+ rubygems_version: 3.0.3
118
119
  signing_key:
119
120
  specification_version: 4
120
121
  summary: Beautiful logging for Ruby.
data/lib/console/error.rb DELETED
@@ -1,76 +0,0 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require_relative 'generic'
22
-
23
- module Console
24
- class Error < Generic
25
- def self.current_working_directory
26
- Dir.getwd
27
- rescue # e.g. Errno::EMFILE
28
- nil
29
- end
30
-
31
- def self.for(exception)
32
- self.new(exception, self.current_working_directory)
33
- end
34
-
35
- def initialize(exception, root = nil)
36
- @exception = exception
37
- @root = root
38
- end
39
-
40
- attr :exception
41
- attr :root
42
-
43
- def self.register(terminal)
44
- terminal[:exception_title] ||= terminal.style(:red, nil, :bold)
45
- terminal[:exception_detail] ||= terminal.style(:yellow)
46
- terminal[:exception_backtrace] ||= terminal.style(:red)
47
- end
48
-
49
- def format(output, terminal, verbose)
50
- format_exception(@exception, nil, output, terminal, verbose)
51
- end
52
-
53
- def format_exception(exception, prefix = nil, output, terminal, verbose)
54
- lines = exception.message.lines.map(&:chomp)
55
-
56
- output.puts " #{prefix}#{terminal[:exception_title]}#{exception.class}#{terminal.reset}: #{lines.shift}"
57
-
58
- lines.each do |line|
59
- output.puts " #{terminal[:exception_detail]}#{line}#{terminal.reset}"
60
- end
61
-
62
- exception.backtrace&.each_with_index do |line, index|
63
- path, offset, message = line.split(":")
64
-
65
- # Make the path a bit more readable
66
- path.gsub!(/^#{@root}\//, "./") if @root
67
-
68
- output.puts " #{index == 0 ? "→" : " "} #{terminal[:exception_backtrace]}#{path}:#{offset}#{terminal.reset} #{message}"
69
- end
70
-
71
- if exception.cause and verbose
72
- format_exception(exception.cause, "Caused by ", output, terminal)
73
- end
74
- end
75
- end
76
- end