fullscreen_tui 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/example +1 -1
- data/lib/fullscreen_tui.rb +17 -13
- data/lib/fullscreen_tui/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29f681d238037ff9d8a5f9e349f07bc4928cfb79f814dd832dfbe3b22d86c03c
|
4
|
+
data.tar.gz: 567d51b78d52b38bea800d95d50c7a502bc1b148b4feee7ff46f76490fdd111a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bbf17d5343180f71e6ab03deb27f87e6761b0918eacb57290801e2ec2ec3e5c7dea4fc9ff42cca9d3418869d81fbea3ab2b25696d2335675795556072c3417d
|
7
|
+
data.tar.gz: a10a04569d8fed752e42ab4920ba78ec947c1183a8fe41e3298333f658b877d7624a4f0cfb931abea0863263c68bc4c042361cc10f41e69fe5e7d513c4c22389
|
data/Gemfile.lock
CHANGED
data/bin/example
CHANGED
data/lib/fullscreen_tui.rb
CHANGED
@@ -10,11 +10,13 @@ require_relative 'fullscreen_tui/renderer'
|
|
10
10
|
class FullscreenTui
|
11
11
|
attr_accessor :selection, :lines
|
12
12
|
attr_reader :header, :footer, :renderer
|
13
|
-
def initialize headers:, renderer: nil
|
13
|
+
def initialize headers:, renderer: nil, enable_jk: true
|
14
14
|
@header = Header.new headers
|
15
15
|
@footer = Footer.new
|
16
16
|
@selection = 0
|
17
17
|
@renderer = renderer || Renderer.new
|
18
|
+
@up_actions = [:arrow_up, enable_jk ? 'k' : nil].reject(&:nil?)
|
19
|
+
@down_actions = [:arrow_down, enable_jk ? 'j' : nil].reject(&:nil?)
|
18
20
|
end
|
19
21
|
|
20
22
|
def run
|
@@ -45,8 +47,8 @@ class FullscreenTui
|
|
45
47
|
|
46
48
|
def key_press key
|
47
49
|
case key
|
48
|
-
when
|
49
|
-
when
|
50
|
+
when *@up_actions then go_up
|
51
|
+
when *@down_actions then go_down
|
50
52
|
when 'q', "\u0004" then throw :quit # ctrl-d
|
51
53
|
else footer.message = "Unknown key: #{key.inspect}"
|
52
54
|
end
|
@@ -56,12 +58,7 @@ class FullscreenTui
|
|
56
58
|
lines[selection]
|
57
59
|
end
|
58
60
|
|
59
|
-
ARROWS = {
|
60
|
-
'A' => :arrow_up,
|
61
|
-
'B' => :arrow_down,
|
62
|
-
'C' => :arrow_right,
|
63
|
-
'D' => :arrow_left,
|
64
|
-
}.freeze
|
61
|
+
ARROWS = {'A' => :arrow_up, 'B' => :arrow_down, 'C' => :arrow_right, 'D' => :arrow_left}.freeze
|
65
62
|
|
66
63
|
def react
|
67
64
|
key = case char = STDIN.getch
|
@@ -101,10 +98,9 @@ class FullscreenTui
|
|
101
98
|
def print_lines rows, columns
|
102
99
|
used_lines = 0
|
103
100
|
offset = [selection - 5, 0].max
|
104
|
-
lines[offset..-1].each.with_index do |
|
101
|
+
lines[offset..-1].map(&:to_s).each.with_index do |line, i|
|
105
102
|
selected = i + offset == selection
|
106
|
-
line
|
107
|
-
used_lines += (line.size.to_f / columns).ceil
|
103
|
+
used_lines += height line, columns
|
108
104
|
if used_lines > rows
|
109
105
|
renderer.line '...', selected: selected
|
110
106
|
break
|
@@ -114,12 +110,20 @@ class FullscreenTui
|
|
114
110
|
break if used_lines == rows
|
115
111
|
end
|
116
112
|
|
113
|
+
fill_remaining_lines rows, used_lines
|
114
|
+
end
|
115
|
+
|
116
|
+
def fill_remaining_lines rows, used_lines
|
117
117
|
(rows - used_lines).times { renderer.line '~', selected: false }
|
118
118
|
end
|
119
119
|
|
120
|
+
def height text, columns
|
121
|
+
(text.size.to_f / columns).ceil
|
122
|
+
end
|
123
|
+
|
120
124
|
def required_lines text, columns
|
121
125
|
text.split($INPUT_RECORD_SEPARATOR)
|
122
|
-
.inject(0) {|sum, line| sum + (line
|
126
|
+
.inject(0) {|sum, line| sum + height(line, columns) }
|
123
127
|
end
|
124
128
|
|
125
129
|
def clear
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fullscreen_tui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Ganz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -110,8 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
|
-
|
114
|
-
rubygems_version: 2.7.6
|
113
|
+
rubygems_version: 3.0.2
|
115
114
|
signing_key:
|
116
115
|
specification_version: 4
|
117
116
|
summary: A simple fullscreen wrapper for terminal uis
|