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 +4 -4
- data/lib/fullscreen_tui.rb +27 -25
- data/lib/fullscreen_tui/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8be81c26ac0c2a6958636763d9fd4f793f05a8666c7daf6e5e9dad9911876082
|
4
|
+
data.tar.gz: c2b14918e40d7b8beaec15ad10775c5fed853e5e144b4fe1556cc6532a4a1666
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18db90408d7818ec98741f2d94fd7fd1117e97d32a8fe9c749f242b5f588fa10ec2bbff03e34d999bfb49f76307e125a0cb79cd9e9043dd65c4fa2d6ab072dca
|
7
|
+
data.tar.gz: c684e9d156e1d12ed488a2c7cb59b9790ff2c6bd641ab7381eb3aaade49dcaf3a9c6e9a3696f85b62ac5e47955fb6c444504940dc3b0b46f5b5abb0d9729beef
|
data/lib/fullscreen_tui.rb
CHANGED
@@ -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
|
-
|
32
|
+
rows, columns = TermInfo.screen_size
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
39
|
+
renderer.header header_text unless header_text.empty?
|
38
40
|
|
39
|
-
print_lines
|
41
|
+
print_lines rows, columns
|
40
42
|
|
41
|
-
|
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
|
51
|
+
else footer.message = "Unknown key: #{key.inspect}"
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
55
|
def selected_line
|
54
|
-
|
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
|
-
|
80
|
-
return if
|
81
|
+
footer.message = ''
|
82
|
+
return if selection.zero?
|
81
83
|
|
82
|
-
|
84
|
+
self.selection -= 1
|
83
85
|
end
|
84
86
|
|
85
87
|
def go_down
|
86
|
-
|
87
|
-
return if
|
88
|
+
footer.message = ''
|
89
|
+
return if selection >= lines.size - 1
|
88
90
|
|
89
|
-
|
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
|
101
|
+
def print_lines rows, columns
|
100
102
|
used_lines = 0
|
101
|
-
offset = [
|
102
|
-
|
103
|
-
selected = i + offset ==
|
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 >
|
107
|
-
|
108
|
+
if used_lines > rows
|
109
|
+
renderer.line '...', selected: selected
|
108
110
|
break
|
109
111
|
end
|
110
112
|
|
111
|
-
|
112
|
-
break if used_lines ==
|
113
|
+
renderer.line line, selected: selected
|
114
|
+
break if used_lines == rows
|
113
115
|
end
|
114
116
|
|
115
|
-
(
|
117
|
+
(rows - used_lines).times { renderer.line '~', selected: false }
|
116
118
|
end
|
117
119
|
|
118
120
|
def required_lines text, columns
|