cli-ui 2.2.1 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1edd90ccd15771c59e43d39ad0004ed99d20b0ff1b68a63cc73b9beea480cb30
4
- data.tar.gz: '096a40c20c1e2fb8e0bcf68b6fb0f8542d5b0d5c578c11e4b6248507efaeace2'
3
+ metadata.gz: 140781de33cc19ef1c5bc946a0a887b3707e54475823affad8f5568e98fbc0dd
4
+ data.tar.gz: b754caad8da6b0d37ea17d807aef78351518c4f17d511a39decbfb29b0512791
5
5
  SHA512:
6
- metadata.gz: ebd356d3f38fa275e66180f3c621a408b36fc4f1ad9965e7bd7b6b2dfef0768364e9175cbeefe5b4964d26c44b3e95cf2e2825a007e1e6a78eeb537704ee024c
7
- data.tar.gz: 40da4c348dd7aa86ab14697abc1172947c63fedc8b1b40b7938fdc65c24e63c71b4d40819f8e6f925059444a33d689e906edd66c68b26c6bd454735436c7c935
6
+ metadata.gz: 8d841fb206c3de7427c4903aa5bb350241c5fe10bbf39c04cb1980eada288deda4b235bf1d5d99a293ebaa6cd78482dd2f49849d65ddd3e7929d63d2f35894bc
7
+ data.tar.gz: 6a99dc71d996abbff3fccdda8ce9ede069a7868ba467d86296bed3575e5726f50f76b65d4d427757f5ddaea211b7926d25045402ae5304e1593ae2fb6bc656fb
@@ -16,12 +16,12 @@ module CLI
16
16
  @name = name
17
17
  end
18
18
 
19
- sig { params(args: String).void }
19
+ sig { params(args: Object).returns(Integer) }
20
20
  def write(*args)
21
21
  args = args.map do |str|
22
22
  if auto_frame_inset?
23
23
  str = str.dup # unfreeze
24
- str = str.force_encoding(Encoding::UTF_8)
24
+ str = str.to_s.force_encoding(Encoding::UTF_8)
25
25
  apply_line_prefix(str, CLI::UI::Frame.prefix)
26
26
  else
27
27
  @pending_newline = false
@@ -31,10 +31,10 @@ module CLI
31
31
 
32
32
  # hook return of false suppresses output.
33
33
  if (hook = Thread.current[:cliui_output_hook])
34
- return if hook.call(args.map(&:to_s).join, @name) == false
34
+ return 0 if hook.call(args.map(&:to_s).join, @name) == false
35
35
  end
36
36
 
37
- T.unsafe(@stream).write_without_cli_ui(*prepend_id(@stream, args))
37
+ ret = T.unsafe(@stream).write_without_cli_ui(*prepend_id(@stream, args))
38
38
  if (dup = StdoutRouter.duplicate_output_to)
39
39
  begin
40
40
  T.unsafe(dup).write(*prepend_id(dup, args))
@@ -42,6 +42,7 @@ module CLI
42
42
  # Ignore
43
43
  end
44
44
  end
45
+ ret
45
46
  end
46
47
 
47
48
  private
@@ -92,7 +93,7 @@ module CLI
92
93
  extend T::Sig
93
94
 
94
95
  @capture_mutex = Mutex.new
95
- @stdin_mutex = ReentrantMutex.new
96
+ @stdin_mutex = CLI::UI::ReentrantMutex.new
96
97
  @active_captures = 0
97
98
  @saved_stdin = nil
98
99
 
@@ -262,7 +263,7 @@ module CLI
262
263
  sig { params(stream: IO).void }
263
264
  def initialize(stream)
264
265
  @stream = stream
265
- @m = ReentrantMutex.new
266
+ @m = CLI::UI::ReentrantMutex.new
266
267
  end
267
268
 
268
269
  sig { type_parameters(:T).params(block: T.proc.returns(T.type_parameter(:T))).returns(T.type_parameter(:T)) }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CLI
4
4
  module UI
5
- VERSION = '2.2.1'
5
+ VERSION = '2.2.3'
6
6
  end
7
7
  end
@@ -22,54 +22,57 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
24
  # Sourced from https://github.com/dotboris/reentrant_mutex
25
+ module CLI
26
+ module UI
27
+ class ReentrantMutex < Mutex
28
+ def initialize
29
+ @count_mutex = Mutex.new
30
+ @counts = Hash.new(0)
25
31
 
26
- class ReentrantMutex < Mutex
27
- def initialize
28
- @count_mutex = Mutex.new
29
- @counts = Hash.new(0)
32
+ super
33
+ end
30
34
 
31
- super
32
- end
35
+ def synchronize
36
+ raise ThreadError, 'Must be called with a block' unless block_given?
33
37
 
34
- def synchronize
35
- raise ThreadError, 'Must be called with a block' unless block_given?
38
+ begin
39
+ lock
40
+ yield
41
+ ensure
42
+ unlock
43
+ end
44
+ end
36
45
 
37
- begin
38
- lock
39
- yield
40
- ensure
41
- unlock
42
- end
43
- end
46
+ def lock
47
+ c = increase_count Thread.current
48
+ super if c <= 1
49
+ end
44
50
 
45
- def lock
46
- c = increase_count Thread.current
47
- super if c <= 1
48
- end
51
+ def unlock
52
+ c = decrease_count Thread.current
53
+ if c <= 0
54
+ super
55
+ delete_count Thread.current
56
+ end
57
+ end
49
58
 
50
- def unlock
51
- c = decrease_count Thread.current
52
- if c <= 0
53
- super
54
- delete_count Thread.current
55
- end
56
- end
59
+ def count
60
+ @count_mutex.synchronize { @counts[Thread.current] }
61
+ end
57
62
 
58
- def count
59
- @count_mutex.synchronize { @counts[Thread.current] }
60
- end
63
+ private
61
64
 
62
- private
65
+ def increase_count(thread)
66
+ @count_mutex.synchronize { @counts[thread] += 1 }
67
+ end
63
68
 
64
- def increase_count(thread)
65
- @count_mutex.synchronize { @counts[thread] += 1 }
66
- end
69
+ def decrease_count(thread)
70
+ @count_mutex.synchronize { @counts[thread] -= 1 }
71
+ end
67
72
 
68
- def decrease_count(thread)
69
- @count_mutex.synchronize { @counts[thread] -= 1 }
70
- end
71
-
72
- def delete_count(thread)
73
- @count_mutex.synchronize { @counts.delete(thread) }
73
+ def delete_count(thread)
74
+ @count_mutex.synchronize { @counts.delete(thread) }
75
+ end
76
+ end
74
77
  end
75
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2023-04-18 00:00:00.000000000 Z
13
+ date: 2023-05-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest