smooth_terminal_print 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smooth_terminal_print.rb +19 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f0586e38bbb9d3bea892e5607aa39d204a0364b
|
4
|
+
data.tar.gz: 603cb30f4282c8557d0cfe134e916ab960daef63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0425af7c364c0c1f4b1b41cedeb984a93a36dbbf85905e4b32ff9727809e85e2833920821ca37df544785b234fa6ce85fa31aaf7b42990c6774ed4e9fec98dd8
|
7
|
+
data.tar.gz: 89f2ba09ce36b3b15dcc91ca461952da10992756b5247e516f4f92aa4b5495f9df7e04522de7d05df5fb6bcd9d85e22381d960e2d047b7ce50150e20a91a3a07
|
@@ -1,16 +1,29 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
1
3
|
module SmoothTerminalPrint
|
2
4
|
extend self
|
3
5
|
|
4
6
|
def start(&block)
|
5
7
|
@stp_reset_timer ||= Time.now.to_i
|
6
|
-
|
8
|
+
|
7
9
|
if(Time.now.to_i - @stp_reset_timer > 1)
|
8
|
-
|
10
|
+
clear_screen
|
9
11
|
@stp_reset_timer = Time.now.to_i
|
10
12
|
end
|
11
13
|
hide_cursor
|
12
14
|
move_to_top_left
|
15
|
+
|
16
|
+
out = StringIO.new
|
17
|
+
$stdout = out
|
13
18
|
yield
|
19
|
+
out.rewind
|
20
|
+
|
21
|
+
num_lines = ((`tput lines`).strip.to_i) - 5
|
22
|
+
num_lines.times do
|
23
|
+
STDOUT.puts out.gets
|
24
|
+
end
|
25
|
+
|
26
|
+
$stdout = STDOUT
|
14
27
|
end
|
15
28
|
|
16
29
|
def stop
|
@@ -19,6 +32,10 @@ module SmoothTerminalPrint
|
|
19
32
|
end
|
20
33
|
|
21
34
|
private
|
35
|
+
def clear_screen
|
36
|
+
print "\e[2J"
|
37
|
+
end
|
38
|
+
|
22
39
|
def hide_cursor
|
23
40
|
print "\e[?25l"
|
24
41
|
end
|