listpager 1.0.1 → 1.0.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
  SHA1:
3
- metadata.gz: 99c5f337edc88d63d288790ab7b3d3340a07c8ff
4
- data.tar.gz: e0258e3a5820063c7458fb5fab6f1bbc742cd0a5
3
+ metadata.gz: 0d4f836e524e3a80691d2a2a0212b3e447d683c7
4
+ data.tar.gz: 4d68a1eee960c026cfbcbaa24b3b9f7378218e26
5
5
  SHA512:
6
- metadata.gz: a3dc50e4c96303c00c64a860ddbf7756b399f963d23935d65bf8b27aaa74360d15b9d552c979d060c1a29ac150467480709a3761a88831a57be973464118f696
7
- data.tar.gz: a632c1124f1e3257dac52afd9f25ce76d32ca7bf2e7f4226a51c83906a8a8e1a24b43e5d1fd45958caaa2070351ed4092b16b2c4a3d9959bf7b51758797cae6a
6
+ metadata.gz: c2942ab1c84e13c509b4958b6002604f81c3ee7ee8708eeb3a6e6dce0e0286ff2df89b5a3d60463535d4c7941b0052c4755519452b394d3bf87095c3ef101d29
7
+ data.tar.gz: 8789bc607ee28fdf54d6018144c18df4583e61fd4c250739f46e7209e25cf638371e5ec7cb1f5ffca89f8b79df0aff660d926da9112fb0a8bea78a6b1b088f3f
data/README.md CHANGED
@@ -73,8 +73,13 @@ ask for statuses, manipulate the list, add badges, change captions, etc.
73
73
 
74
74
  ## Dependencies and Installation
75
75
  Install listpager with `gem install listpager`. It has few dependencies:
76
- currently only `ncurses-ruby`.
76
+ currently only `ncursesw`. BUT IT DOESNT STOP THERE, of course: For the
77
+ gem to build on a fresh Ubuntu, you'll need the following for widechar-
78
+ supporting libncurses development headers:
77
79
 
80
+ ```bash
81
+ sudo apt install libncursesw5-dev
82
+ ```
78
83
 
79
84
  ## Implementation Notes
80
85
  curses is terrible but portable. 'curses' doesn't expose enough to be useful,
@@ -1,4 +1,4 @@
1
- require 'listpager/ncurses'
1
+ require 'ncursesw'
2
2
  require 'shellwords'
3
3
  require 'optparse'
4
4
  require 'io/console'
@@ -54,36 +54,41 @@ module Listpager
54
54
  @mode == :append
55
55
  end
56
56
 
57
- def process_command(line)
58
- if append_mode?
59
- case line
60
- when '\%%'
61
- list.values.push('%%')
57
+ def process_command(argv)
58
+ cmd, *args = argv
59
+ case cmd
60
+ when 'append-mode', '%'
61
+ @mode = :append
62
+ when 'title'
63
+ @list.title = args[0]
64
+ when 'clear'
65
+ @list.values = []
66
+ @list.selected = 0
62
67
  list.dirty!
63
- when '%%'
68
+ when 'get-selected'
69
+ list.selection_changed
70
+ when 'select'
71
+ list.selected = args.fetch(0).to_i
72
+ when 'get-item'
73
+ puts ["item", args.fetch(0), list.values[args.fetch(0).to_i]].join ' '
74
+ when 'quit'
75
+ raise Interrupt
76
+ end
77
+ end
78
+
79
+ def process_line(line)
80
+ if append_mode?
81
+ if line == '%%'
64
82
  @mode = :command
83
+ elsif line[0] == '%'
84
+ cmd = Shellwords.split(line[1..-1])
85
+ process_command(cmd)
65
86
  else
66
87
  list.values.push(line)
67
88
  list.dirty!
68
89
  end
69
90
  else
70
- cmd, *args = Shellwords.split(line)
71
- begin
72
- case cmd
73
- when '%%', 'append-mode'
74
- @mode = :append
75
- when 'get-selected'
76
- list.selection_changed
77
- when 'select'
78
- list.selected = args.fetch(0).to_i
79
- when 'get-item'
80
- puts ["item", args.fetch(0), list.values[args.fetch(0).to_i]].join ' '
81
- when 'quit'
82
- raise Interrupt
83
- end
84
- rescue IndexError => e
85
- puts "error bad-command #{line}"
86
- end
91
+ process_command(Shellwords.split(line))
87
92
  end
88
93
  end
89
94
 
@@ -103,7 +108,7 @@ module Listpager
103
108
  used = 0
104
109
  StringIO.new(@buffer).each_line do |line|
105
110
  if line[-1] == "\n"
106
- process_command(line.chomp)
111
+ process_line(line.chomp)
107
112
  used += line.size
108
113
  else
109
114
  break
@@ -1,4 +1,4 @@
1
- require 'listpager/ncurses'
1
+ require 'ncursesw'
2
2
 
3
3
  module Listpager
4
4
  class Color
@@ -8,6 +8,7 @@ module Listpager
8
8
  scroll_track: 2,
9
9
  scroll_thumb: 3,
10
10
  scroll_arrow: 4,
11
+ title: 5,
11
12
  }.freeze
12
13
 
13
14
  def self.curses_lookup(c)
@@ -24,6 +25,7 @@ module Listpager
24
25
  init_color(:scroll_track, :COLOR_BLACK, :COLOR_BLACK)
25
26
  init_color(:scroll_thumb, :COLOR_WHITE, :COLOR_WHITE)
26
27
  init_color(:scroll_arrow, :COLOR_WHITE, :COLOR_BLACK)
28
+ init_color(:title, :COLOR_BLACK, :COLOR_BLUE)
27
29
  end
28
30
 
29
31
  def self.[](name)
@@ -1,5 +1,4 @@
1
- require 'listpager/ncurses'
2
-
1
+ require 'ncursesw'
3
2
  require 'listpager/color'
4
3
  require 'listpager/scrollbar'
5
4
 
@@ -27,9 +26,11 @@ module Listpager
27
26
  attr_reader :selected
28
27
  attr_reader :offset
29
28
  attr_reader :scrollbar
29
+ attr_reader :title
30
30
 
31
31
  def initialize(window)
32
32
  @window = window
33
+ @title = nil
33
34
  @values = []
34
35
  @selected = 0
35
36
  @offset = 0
@@ -45,17 +46,29 @@ module Listpager
45
46
  @dirty
46
47
  end
47
48
 
49
+ def title=(v)
50
+ if v != @title
51
+ @title = v
52
+ dirty!
53
+ end
54
+ @title
55
+ end
56
+
48
57
  def offset=(v)
49
58
  dirty! if v != @offset
59
+ v = 0 if v < 0
50
60
  @offset = v
51
61
  end
52
62
 
53
63
  attr_reader :selected
54
64
  def selected=(v)
65
+ minx, miny = getminxy
55
66
  maxx, maxy = getmaxxy
56
67
 
57
68
  v = [0, v, values.size - 1].sort[1]
58
- self.offset = [v - maxy + 1, offset, v].sort[1]
69
+ screenh = maxy - miny
70
+
71
+ self.offset = [v + miny - 1, offset, (v + miny + 1) - screenh].sort[1]
59
72
 
60
73
  if v != @selected
61
74
  dirty!
@@ -103,21 +116,45 @@ module Listpager
103
116
  s.gsub(/[^[:print:]]/, '')
104
117
  end
105
118
 
119
+ def getminxy
120
+ x, y = 0, 0
121
+ y += 1 if title
122
+ [x, y]
123
+ end
124
+
106
125
  def getmaxxy
107
126
  maxx, maxy = [], []
108
127
  window.getmaxyx(maxy, maxx)
109
128
  [maxx[0], maxy[0]]
110
129
  end
111
130
 
131
+ def space_pad(s, w)
132
+ nspaces = (w - s.size)
133
+ nspaces = 0 if nspaces < 0
134
+ s + (BLANK_SPACE * (w - s.size))
135
+ end
136
+
137
+ def render_title
138
+ maxx, maxy = getmaxxy
139
+ if title
140
+ window.color_set(Color[:title], nil)
141
+ window.move(0, 0)
142
+ window.addstr(space_pad(' ' + title, maxx))
143
+ end
144
+ end
145
+
112
146
  def render
113
147
  return false if ! dirty?
114
148
 
149
+ render_title
150
+
115
151
  maxx, maxy = getmaxxy
152
+ minx, miny = getminxy
116
153
 
117
- (0...maxy).each do |i|
154
+ (miny...maxy).each do |i|
118
155
  window.color_set(Color[:list_default], nil)
119
156
 
120
- list_index = offset + i
157
+ list_index = (offset + i) - miny
121
158
  window.move(i, 0)
122
159
  indicator = nil
123
160
 
@@ -1,5 +1,4 @@
1
- require 'listpager/ncurses'
2
-
1
+ require 'ncursesw'
3
2
  require 'listpager/color'
4
3
 
5
4
  module Listpager
@@ -1,3 +1,3 @@
1
1
  module Listpager
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/listpager.gemspec CHANGED
@@ -27,16 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- # Check out the hack in ext/mkrf_conf.rb, which is effectively:
31
- #
32
- # if RUBY_PLATFORM =~ /\bdarwin/
33
- # spec.add_runtime_dependency 'ncurses-ruby'
34
- # else
35
- # # Doesn't build on newer macOS...
36
- # spec.add_runtime_dependency 'ncursesw'
37
- # end
38
- #
39
- # A PR has been submitted to ncursesw, so hopefully this can go away soon.
30
+ spec.add_runtime_dependency "ncursesw", "~> 1.4.10"
40
31
 
41
32
  spec.add_development_dependency "bundler", "~> 1.12"
42
33
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: listpager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Owens
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-01 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ncursesw
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.10
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -55,12 +69,10 @@ files:
55
69
  - bin/setup
56
70
  - doc/screenshot.png
57
71
  - exe/listpager
58
- - ext/mkrf_conf.rb
59
72
  - lib/listpager.rb
60
73
  - lib/listpager/client_terminal.rb
61
74
  - lib/listpager/color.rb
62
75
  - lib/listpager/list.rb
63
- - lib/listpager/ncurses.rb
64
76
  - lib/listpager/scrollbar.rb
65
77
  - lib/listpager/version.rb
66
78
  - listpager.gemspec
data/ext/mkrf_conf.rb DELETED
@@ -1,23 +0,0 @@
1
- require 'rubygems'
2
- require 'rubygems/command.rb'
3
- require 'rubygems/dependency_installer.rb'
4
-
5
- begin
6
- Gem::Command.build_args = ARGV
7
- rescue NoMethodError
8
- # We're good
9
- end
10
-
11
- inst = Gem::DependencyInstaller.new
12
- begin
13
- if RUBY_PLATFORM =~ /\bdarwin/i
14
- inst.install "ruby-ncurses", "~> 1.2.4"
15
- else
16
- inst.install "ncursesw", "~> 1.4.9"
17
- end
18
- rescue
19
- exit 1
20
- end
21
-
22
- # create dummy rakefile to indicate success
23
- File.write(__dir__("Rakefile"), "task: default\n")
@@ -1,8 +0,0 @@
1
- # Note: This is a hack to work around ncursesw not building on macOS.
2
- # Hopefully it can go away soon.
3
-
4
- if RUBY_PLATFORM =~ /\bdarwin/i
5
- require 'ncurses'
6
- else
7
- require 'ncursesw'
8
- end