smooth_terminal_print 0.0.4 → 0.0.5

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: f5eb6274b2094b0627fbfbdaf1669595ea47aa7a
4
- data.tar.gz: 0758bc5cc97635a72a319537653d1982cc6c0c96
3
+ metadata.gz: 76ac9646a7704edd941afaf47329bbd61153ef67
4
+ data.tar.gz: 5b197c0f17048924750aa6b6ebb1d3dbb72e2ad2
5
5
  SHA512:
6
- metadata.gz: 700e062107c3bacb742c8ce33f884d6a016495981ecfc71f26eb2161523e2068b823c5678e578490730976f8140d888f63c18eeddd0dd8aeaf9454a7075eb099
7
- data.tar.gz: 7050b456e989e9af09313b964a40768270b12bde5ad13f5be02708d0fed6f4385a85b5c7622cdce530a2b2978fef625af224e68994f8f4d766241fabc72859fa
6
+ metadata.gz: 7d032f94c7952d4758bbdb52b4b15016f21a27d38a2032281484ae374bd608022524a468eee43c6cdf9f57276a1b56f0d04814a3cb7b0ee786fe7250f0929db0
7
+ data.tar.gz: cdfbf5c50a32fff66151664f541440cf033b5c046d506d07721960e53b97d95b5e989c9945e7525592a08f160f6a1ecc4c757a40d8aaf312c75adf5adc71e968
@@ -1,29 +1,24 @@
1
1
  require 'stringio'
2
+ require_relative './terminal_actions'
2
3
 
3
4
  module SmoothTerminalPrint
5
+ include TerminalActions
4
6
  extend self
5
7
 
6
8
  def start(&block)
7
- @stp_reset_timer ||= Time.now.to_i
9
+ get_screen_dimensions
8
10
 
9
- if(Time.now.to_i - @stp_reset_timer > 1)
10
- clear_screen
11
- @stp_reset_timer = Time.now.to_i
12
- end
13
11
  hide_cursor
12
+
14
13
  move_to_top_left
15
14
 
16
- out = StringIO.new
17
- $stdout = out
15
+ io = StringIO.new
16
+ $stdout = io
18
17
  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
18
  $stdout = STDOUT
19
+ io.rewind
20
+
21
+ print_text(io)
27
22
  end
28
23
 
29
24
  def stop
@@ -33,23 +28,33 @@ module SmoothTerminalPrint
33
28
  end
34
29
 
35
30
  private
36
- def clear_screen
37
- print "\e[2J"
38
- end
39
-
40
- def hide_cursor
41
- print "\e[?25l"
42
- end
43
-
44
- def move_to_top_left
45
- print "\e[H"
46
- end
47
-
48
- def show_cursor
49
- print "\e[?25h"
31
+ def print_text(string_io)
32
+ @num_lines.times do
33
+ line = string_io.gets
34
+ break if line.nil?
35
+
36
+ line.strip!
37
+ line = line[0..@columns]
38
+ line.length.upto(@columns) { line << ' ' }
39
+ line << "\n"
40
+ puts line
41
+ end
50
42
  end
51
43
 
52
- def move_to_bottom
53
- print "\e[2000E"
44
+ def get_screen_dimensions
45
+ @stp_reset_timer ||= nil
46
+
47
+ if(@stp_reset_timer == nil || Time.now.to_i - @stp_reset_timer > 3)
48
+ old_num_lines = @num_lines
49
+ old_num_cols = @columns
50
+ @num_lines = (`tput lines`).strip.to_i - 5
51
+ @columns = `tput cols`.strip.to_i - 5
52
+
53
+ if(old_num_lines != @num_lines || old_num_cols != @columns)
54
+ clear_screen
55
+ end
56
+
57
+ @stp_reset_timer = Time.now.to_i
58
+ end
54
59
  end
55
60
  end
@@ -0,0 +1,23 @@
1
+ module SmoothTerminalPrint
2
+ module TerminalActions
3
+ def clear_screen
4
+ print "\e[2J"
5
+ end
6
+
7
+ def hide_cursor
8
+ print "\e[?25l"
9
+ end
10
+
11
+ def move_to_top_left
12
+ print "\e[H"
13
+ end
14
+
15
+ def show_cursor
16
+ print "\e[?25h"
17
+ end
18
+
19
+ def move_to_bottom
20
+ print "\e[2000E"
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smooth_terminal_print
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Sykes
@@ -17,6 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/smooth_terminal_print.rb
20
+ - lib/terminal_actions.rb
20
21
  homepage: https://github.com/bretts/smooth_terminal_print
21
22
  licenses:
22
23
  - MIT