smooth_terminal_print 1.0.6 → 2.0.0

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
  SHA1:
3
- metadata.gz: d0f92d15656500328dc31801362f6454559ec62f
4
- data.tar.gz: 9c718b684e24e78310f80a19a793e9a876291c11
3
+ metadata.gz: b80d17f78b7a5d8b3c88c56f7ce920f7aaae010b
4
+ data.tar.gz: 1b1a453db1651bb68594fba40a45e65829142fae
5
5
  SHA512:
6
- metadata.gz: a63eb566774e6009d148869a24a15695f6167c4cf6ef449dd57349b09064c30800d42ba24a8c29c1a7c0d5238b4592d20ed7de369b132372ccd600caa153cde8
7
- data.tar.gz: e6cb9cd6cce48f25e7f2891a574403347a692d8776aa737f47c779d5f1f5e7019d0bf0c70314157fe963bf21ec8dbd49eef12e747e5dc867c7f032672cf0eec2
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
- module SmoothTerminalPrint
5
- include TerminalActions
6
- extend self
7
-
8
- def start(&block)
9
- get_screen_dimensions
10
-
11
- hide_cursor
12
-
13
- move_to_top_left
14
-
15
- io = StringIO.new
16
- $stdout = io
17
- yield
18
- $stdout = STDOUT
19
- io.rewind
20
-
21
- print_text(io)
22
- end
23
-
24
- def stop
25
- $stdout = STDOUT
26
- move_to_bottom
27
- show_cursor
28
- end
29
-
30
- private
31
- def print_text(string_io)
32
- 0.upto(@num_lines) do
33
- line = string_io.gets
34
-
35
- if line.nil?
36
- line = ''
37
- else
38
- line.strip!
39
- end
40
-
41
- line << "\e[K"
42
- puts line
43
- end
44
- end
45
-
46
- def get_screen_dimensions
47
- @stp_reset_timer ||= nil
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
@@ -1,23 +1,25 @@
1
- module SmoothTerminalPrint
2
- module TerminalActions
3
- def clear_screen
4
- print "\e[2J"
5
- end
1
+ module TerminalActions
2
+ def clear_screen
3
+ return "\e[2J"
4
+ end
6
5
 
7
- def hide_cursor
8
- print "\e[?25l"
9
- end
6
+ def hide_cursor
7
+ return "\e[?25l"
8
+ end
10
9
 
11
- def move_to_top_left
12
- print "\e[H"
13
- end
10
+ def move_to_top_left
11
+ return "\e[H"
12
+ end
14
13
 
15
- def show_cursor
16
- print "\e[?25h"
17
- end
14
+ def clear_to_line_end
15
+ return "\e[K"
16
+ end
18
17
 
19
- def move_to_bottom
20
- print "\e[2000E"
21
- end
22
- end
23
- end
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: 1.0.6
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-23 00:00:00.000000000 Z
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Allows the user to smoothly print to the terminal while in a tight loop
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: Smoothly print to the terminal while in a tight loop
44
+ summary: Animate printing text in a terminal window while in a tight loop
45
45
  test_files: []