fullscreen_tui 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: e18910035ac6cba870a3a6e75c5b1a2d44a711481c4af6de6da68ab151e0a801
4
- data.tar.gz: 5876fb56e1136f720eaca08841cb61c90625949d6e9677b7fac659be9a0527ac
3
+ metadata.gz: 8be81c26ac0c2a6958636763d9fd4f793f05a8666c7daf6e5e9dad9911876082
4
+ data.tar.gz: c2b14918e40d7b8beaec15ad10775c5fed853e5e144b4fe1556cc6532a4a1666
5
5
  SHA512:
6
- metadata.gz: 8b50cf1d96d88510c4a6d0702fcf6e366abbbaa847cf227acc86c72987e0d8eab1c2c348d7deb5f93297acf714e547c0402439654e21f769c9fa29861849d94a
7
- data.tar.gz: c5b5c1ffe1325d60bb535c6c2c3f5245e1a4830fb2c8ca6b40472f9833c3ba01d46b344560d78882c478cf3e3b9dcbd5e4bbf6ee9f54f3a31b9fb18a4d74b9f8
6
+ metadata.gz: 18db90408d7818ec98741f2d94fd7fd1117e97d32a8fe9c749f242b5f588fa10ec2bbff03e34d999bfb49f76307e125a0cb79cd9e9043dd65c4fa2d6ab072dca
7
+ data.tar.gz: c684e9d156e1d12ed488a2c7cb59b9790ff2c6bd641ab7381eb3aaade49dcaf3a9c6e9a3696f85b62ac5e47955fb6c444504940dc3b0b46f5b5abb0d9729beef
@@ -8,6 +8,8 @@ require_relative 'fullscreen_tui/footer'
8
8
  require_relative 'fullscreen_tui/renderer'
9
9
 
10
10
  class FullscreenTui
11
+ attr_accessor :selection, :lines
12
+ attr_reader :header, :footer, :renderer
11
13
  def initialize headers:, renderer: nil
12
14
  @header = Header.new headers
13
15
  @footer = Footer.new
@@ -27,18 +29,18 @@ class FullscreenTui
27
29
  def print_screen
28
30
  clear
29
31
 
30
- lines, columns = TermInfo.screen_size
32
+ rows, columns = TermInfo.screen_size
31
33
 
32
- header = @header.output
33
- lines -= required_lines header, columns
34
- footer = @footer.output width: columns, lines: @lines.size, current_line: @selection
35
- lines -= required_lines footer, columns
34
+ header_text = header.output
35
+ rows -= required_lines header_text, columns
36
+ footer_text = footer.output width: columns, lines: lines.size, current_line: selection
37
+ rows -= required_lines footer_text, columns
36
38
 
37
- @renderer.header header unless header.empty?
39
+ renderer.header header_text unless header_text.empty?
38
40
 
39
- print_lines lines, columns
41
+ print_lines rows, columns
40
42
 
41
- @renderer.footer footer
43
+ renderer.footer footer_text
42
44
  end
43
45
 
44
46
  def key_press key
@@ -46,12 +48,12 @@ class FullscreenTui
46
48
  when :arrow_up then go_up
47
49
  when :arrow_down then go_down
48
50
  when 'q', "\u0004" then throw :quit # ctrl-d
49
- else @footer.message = "Unknown key: #{key.inspect}"
51
+ else footer.message = "Unknown key: #{key.inspect}"
50
52
  end
51
53
  end
52
54
 
53
55
  def selected_line
54
- @lines[@selection]
56
+ lines[selection]
55
57
  end
56
58
 
57
59
  ARROWS = {
@@ -76,17 +78,17 @@ class FullscreenTui
76
78
  end
77
79
 
78
80
  def go_up
79
- @footer.message = ''
80
- return if @selection.zero?
81
+ footer.message = ''
82
+ return if selection.zero?
81
83
 
82
- @selection -= 1
84
+ self.selection -= 1
83
85
  end
84
86
 
85
87
  def go_down
86
- @footer.message = ''
87
- return if @selection >= @lines.size - 1
88
+ footer.message = ''
89
+ return if selection >= lines.size - 1
88
90
 
89
- @selection += 1
91
+ self.selection += 1
90
92
  end
91
93
 
92
94
  def read_full_line message
@@ -96,23 +98,23 @@ class FullscreenTui
96
98
 
97
99
  private
98
100
 
99
- def print_lines lines, columns
101
+ def print_lines rows, columns
100
102
  used_lines = 0
101
- offset = [@selection - 5, 0].max
102
- @lines[offset..-1].each.with_index do |l, i|
103
- selected = i + offset == @selection
103
+ offset = [selection - 5, 0].max
104
+ lines[offset..-1].each.with_index do |l, i|
105
+ selected = i + offset == selection
104
106
  line = l.to_s
105
107
  used_lines += (line.size.to_f / columns).ceil
106
- if used_lines > lines
107
- @renderer.line '...', selected: selected
108
+ if used_lines > rows
109
+ renderer.line '...', selected: selected
108
110
  break
109
111
  end
110
112
 
111
- @renderer.line line, selected: selected
112
- break if used_lines == lines
113
+ renderer.line line, selected: selected
114
+ break if used_lines == rows
113
115
  end
114
116
 
115
- (lines - used_lines).times { @renderer.line '~', selected: false }
117
+ (rows - used_lines).times { renderer.line '~', selected: false }
116
118
  end
117
119
 
118
120
  def required_lines text, columns
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FullscreenTui
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fullscreen_tui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Ganz