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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8be81c26ac0c2a6958636763d9fd4f793f05a8666c7daf6e5e9dad9911876082
4
- data.tar.gz: c2b14918e40d7b8beaec15ad10775c5fed853e5e144b4fe1556cc6532a4a1666
3
+ metadata.gz: 29f681d238037ff9d8a5f9e349f07bc4928cfb79f814dd832dfbe3b22d86c03c
4
+ data.tar.gz: 567d51b78d52b38bea800d95d50c7a502bc1b148b4feee7ff46f76490fdd111a
5
5
  SHA512:
6
- metadata.gz: 18db90408d7818ec98741f2d94fd7fd1117e97d32a8fe9c749f242b5f588fa10ec2bbff03e34d999bfb49f76307e125a0cb79cd9e9043dd65c4fa2d6ab072dca
7
- data.tar.gz: c684e9d156e1d12ed488a2c7cb59b9790ff2c6bd641ab7381eb3aaade49dcaf3a9c6e9a3696f85b62ac5e47955fb6c444504940dc3b0b46f5b5abb0d9729beef
6
+ metadata.gz: 7bbf17d5343180f71e6ab03deb27f87e6761b0918eacb57290801e2ec2ec3e5c7dea4fc9ff42cca9d3418869d81fbea3ab2b25696d2335675795556072c3417d
7
+ data.tar.gz: a10a04569d8fed752e42ab4920ba78ec947c1183a8fe41e3298333f658b877d7624a4f0cfb931abea0863263c68bc4c042361cc10f41e69fe5e7d513c4c22389
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fullscreen_tui (0.1.0)
4
+ fullscreen_tui (0.1.1)
5
5
  colorize (~> 0.8)
6
6
  ruby-terminfo (~> 0.1)
7
7
 
@@ -7,7 +7,7 @@ require 'fullscreen_tui'
7
7
  class Example < FullscreenTui
8
8
  def initialize
9
9
  @lines = (1..40).map {|i| "some test #{i} " * 10 }
10
- super headers: [] # ['Example', 'For FullscreenTui']
10
+ super headers: ['Example', 'For FullscreenTui']
11
11
  end
12
12
 
13
13
  def key_press key
@@ -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 :arrow_up then go_up
49
- when :arrow_down then go_down
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 |l, i|
101
+ lines[offset..-1].map(&:to_s).each.with_index do |line, i|
105
102
  selected = i + offset == selection
106
- line = l.to_s
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.size.to_f / columns).ceil }
126
+ .inject(0) {|sum, line| sum + height(line, columns) }
123
127
  end
124
128
 
125
129
  def clear
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FullscreenTui
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
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.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: 2018-12-28 00:00:00.000000000 Z
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
- rubyforge_project:
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