ips 0.2.0 → 0.3.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: e1f6fa1d4276f6a2e4490785949a2f9d776fd22deefd7bf8b4a32a1373e1ace2
4
- data.tar.gz: dc254907783de35d83da05e504aff4b94479fcbb0b18e5fd227fc9af97864a6e
3
+ metadata.gz: 5c8dde979505d34763745a2f6dcf6f9df0a8e6396fdd2351b769282393839417
4
+ data.tar.gz: 4225c76063e8a905bbf14efb5eb8ee000a030b4f674d6c2c9cef9571f007d4b6
5
5
  SHA512:
6
- metadata.gz: aaabca2ef626e4c0856f7ba3786fc0f91613b8a52a5681351dcd5dfd563918188dc62f2ffd2b1e25b6940ddabe447da85b9608002c63d01373a3de95548c990c
7
- data.tar.gz: e9ba746e1183237048aff5b35f41865d7886ee6e57b77be7c238f1d9ae09f2e707599adf7aa32c98bfee964ab3ae7a909cf80d5d1602b05dd989b28396d9b0dd
6
+ metadata.gz: d0178e0e87a6913dc3134f4e748bdb795f16e4fb2a2cca10c3f1fc7e7dc9a4615e5bb3d45c12aff7adb6a0a12afd644392b77f07bd080ee91e382734b0ea1b8e
7
+ data.tar.gz: 199d08e24ae772bc5030a9f8daf63b4b453cfef6e8623110fd292ae70d5d1ca1f806bcaae7b86e364dae1850deea6a398b4b01426166c153cbc45917ec823644
data/lib/ips/display.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ begin
4
+ require "io/console"
5
+ rescue LoadError
6
+ end
7
+
3
8
  module IPS
4
9
  class Display
5
10
  BAR_WIDTH = 30
@@ -8,14 +13,19 @@ module IPS
8
13
  @out = out
9
14
  @max_label = labels.map(&:size).max
10
15
  @max_label = 20 if @max_label < 20
11
- @tty = @out.tty? && !debug
16
+ @tty = @out.tty? && !debug && terminal_wide_enough?
12
17
  end
13
18
 
14
19
  def start_item(label, total_ns)
15
20
  @item_label = label
16
21
  @item_start = Timing.now
17
22
  @item_total_ns = total_ns
18
- progress
23
+ if @tty
24
+ progress
25
+ else
26
+ @out.print "%#{@max_label}s: " % label
27
+ @out.flush
28
+ end
19
29
  end
20
30
 
21
31
  def progress(estimate: nil)
@@ -33,11 +43,16 @@ module IPS
33
43
  end
34
44
 
35
45
  def finish_item(result)
36
- @out.print "\r\e[2K" if @tty
37
46
  gc = result.gc_pct >= 1.0 ? ", GC %4.1f%%" % result.gc_pct : ""
38
47
  error = result.error_pct > 100 ? ">100" : "%4.1f" % result.error_pct
39
- @out.printf "%#{@max_label}s: %10s i/s (±%s%%%s)\n",
40
- result.label, format_ips(result.ips), error, gc
48
+ if @tty
49
+ @out.print "\r\e[2K"
50
+ @out.printf "%#{@max_label}s: %10s i/s (±%s%%%s)\n",
51
+ result.label, format_ips(result.ips), error, gc
52
+ else
53
+ @out.printf "%10s i/s (±%s%%%s)\n",
54
+ format_ips(result.ips), error, gc
55
+ end
41
56
  end
42
57
 
43
58
  def summary(results)
@@ -63,6 +78,14 @@ module IPS
63
78
  end
64
79
  end
65
80
 
81
+ def terminal_wide_enough?
82
+ return true unless @out.respond_to?(:winsize)
83
+ # label + ": " + estimate + " " + bar + " ETA Ns "
84
+ min_width = @max_label + 2 + 14 + 1 + BAR_WIDTH + 8
85
+ _, cols = @out.winsize
86
+ cols >= min_width
87
+ end
88
+
66
89
  def format_ips(ips)
67
90
  Display.format_ips(ips)
68
91
  end
data/lib/ips/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IPS
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ips
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn