smooth_terminal_print 1.0.6 → 2.0.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 +4 -4
- data/lib/smooth_terminal_print.rb +45 -58
- data/lib/terminal_actions.rb +21 -19
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b80d17f78b7a5d8b3c88c56f7ce920f7aaae010b
|
4
|
+
data.tar.gz: 1b1a453db1651bb68594fba40a45e65829142fae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6b674ed934757c321146237f12a2b7f421da0c0e2d04513e3532949bbec6c69c3636099ce977463dedae670fb5caa6fb88b12df25d6c2f58280c8806bbfdc29
|
7
|
+
data.tar.gz: 926ff92b54af16c2fa4b7ce1fbdc7c181923bfe9eee3a4ff55378be5d9c76346e708f7a2f3a513cf046a097c6b43458a7557e7b0b7fe7112b7070db9c19dd705
|
@@ -1,62 +1,49 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
require_relative './terminal_actions'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
if(@stp_reset_timer == nil || Time.now.to_i - @stp_reset_timer > 3)
|
50
|
-
old_num_lines = @num_lines
|
51
|
-
old_num_cols = @columns
|
52
|
-
@num_lines = (`tput lines`).strip.to_i - 2
|
53
|
-
@columns = `tput cols`.strip.to_i - 5
|
54
|
-
|
55
|
-
if(old_num_lines != @num_lines || old_num_cols != @columns)
|
56
|
-
clear_screen
|
57
|
-
end
|
58
|
-
|
59
|
-
@stp_reset_timer = Time.now.to_i
|
60
|
-
end
|
61
|
-
end
|
4
|
+
class SmoothTerminalPrint
|
5
|
+
include TerminalActions
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
update_screen_dimensions
|
9
|
+
|
10
|
+
trap('SIGINT') { stop_smooth_printing_mode; exit }
|
11
|
+
trap('SIGWINCH') { update_screen_dimensions }
|
12
|
+
at_exit { stop_smooth_printing_mode }
|
13
|
+
end
|
14
|
+
|
15
|
+
def print_smoothly(io)
|
16
|
+
print(hide_cursor)
|
17
|
+
print(move_to_top_left)
|
18
|
+
|
19
|
+
print_text(io)
|
20
|
+
end
|
21
|
+
|
22
|
+
def stop_smooth_printing_mode
|
23
|
+
print(move_to_bottom)
|
24
|
+
print(show_cursor)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def update_screen_dimensions
|
29
|
+
@num_lines = `tput lines`.strip.to_i - 2
|
30
|
+
@columns = `tput cols`.strip.to_i - 5
|
31
|
+
end
|
32
|
+
|
33
|
+
def print_text(io)
|
34
|
+
io.rewind
|
35
|
+
|
36
|
+
0.upto(@num_lines) do
|
37
|
+
line = io.gets
|
38
|
+
|
39
|
+
if line.nil?
|
40
|
+
line = ''
|
41
|
+
else
|
42
|
+
line.strip!
|
43
|
+
end
|
44
|
+
|
45
|
+
line << clear_to_line_end
|
46
|
+
puts line
|
47
|
+
end
|
48
|
+
end
|
62
49
|
end
|
data/lib/terminal_actions.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
1
|
+
module TerminalActions
|
2
|
+
def clear_screen
|
3
|
+
return "\e[2J"
|
4
|
+
end
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def hide_cursor
|
7
|
+
return "\e[?25l"
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def move_to_top_left
|
11
|
+
return "\e[H"
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def clear_to_line_end
|
15
|
+
return "\e[K"
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
def show_cursor
|
19
|
+
return "\e[?25h"
|
20
|
+
end
|
21
|
+
|
22
|
+
def move_to_bottom
|
23
|
+
return "\e[2000E"
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smooth_terminal_print
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Sykes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: Animate printing text in a terminal window while in a tight loop
|
14
14
|
email: brettcsykes@gmail.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -41,5 +41,5 @@ rubyforge_project:
|
|
41
41
|
rubygems_version: 2.6.8
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
|
-
summary:
|
44
|
+
summary: Animate printing text in a terminal window while in a tight loop
|
45
45
|
test_files: []
|