kv 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -0
  3. data/lib/kv.rb +60 -20
  4. data/lib/kv/version.rb +1 -1
  5. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c803b1b67678cd6668eff3068451093dba82fa6bd85e09a7c32be56c7febeaf
4
- data.tar.gz: 1d49373d49d9bc626d2a5635538dc58fe8839927461db18befcaec4d187fd14b
3
+ metadata.gz: a94c201f245d4df4b646fa9b88cd197d915d37096962da6e0cca0bd8dbb39d24
4
+ data.tar.gz: 0f8e816be09a9509e5d1fe5b6b157d8d3dcafefc8acd0e97f16a83893bd0aac1
5
5
  SHA512:
6
- metadata.gz: 9b625de709b8af9d9f55672504c78b73979ff9f2a054c9e78503796fa659861a9ea14ef8c4a9990ab1006a7f315a63b88f7fcd54e06b96997e3031bcd7e3d5ca
7
- data.tar.gz: 382d0287eaf1ac11904f8a7e71ed4be9019d15443b202991a5bb750d51b3a78283a439cbbfe5547ce8d26b9c2b8603abd29a63e45092f83ec48e5fabf307749f
6
+ metadata.gz: 96524f391e1af962c1f276d6036ef73e07a2f182736b6d8d92ee1060d5dd82c778dba0567f3ca8eb719d5797fe1f67955768578ac1c34abb6171f9170a2a394a
7
+ data.tar.gz: '092e3cb69c9b55c16435a88b3bcffc32e4e4d0ee2301d5f91f497fb538b75dcbfefafbd38f8b6e3dd957fa2be438df8e47391006ce7b1b21044088c052db3365'
data/README.md CHANGED
@@ -32,6 +32,7 @@ Options:
32
32
  -n, --line-number LINE goto LINE
33
33
  -N Show lines
34
34
  -T, --time-stamp Enable time stamp
35
+ -e CMD Run CMD as a child process
35
36
  ```
36
37
 
37
38
  ## Command on a pager
@@ -79,6 +80,12 @@ kv: A pager by Ruby Command list
79
80
  s: Save screen buffer to file
80
81
  P: gist -p
81
82
 
83
+ # Child process
84
+ You can run child process using -e command line option like -e CMD
85
+ and you can send a meesage to the child process with x command.
86
+
87
+ x: send a message to the child process
88
+
82
89
  # Modes
83
90
  N: toggle line mode
84
91
  T: toggle time stamp mode
data/lib/kv.rb CHANGED
@@ -52,8 +52,8 @@ class Screen
52
52
  @lines = lines
53
53
  @mode = :screen
54
54
 
55
- @following_mode = following_mode
56
- @searching = false
55
+ @following = following_mode
56
+ @apos = 0
57
57
 
58
58
  @mouse = false
59
59
  @search_ignore_case = false
@@ -83,7 +83,7 @@ class Screen
83
83
  def read_async input
84
84
  @loading = true
85
85
  begin
86
- data = input.read_nonblock(4096)
86
+ data = input.read_nonblock(800_000)
87
87
  rescue IO::EAGAINWaitReadable, EOFError
88
88
  data = ''
89
89
  end
@@ -122,7 +122,8 @@ class Screen
122
122
  end
123
123
 
124
124
  def y_max
125
- @lines.size - Curses.lines + 2
125
+ max = @lines.size - Curses.lines + 2
126
+ max < 0 ? 0 : max
126
127
  end
127
128
 
128
129
  def y
@@ -166,6 +167,11 @@ class Screen
166
167
  else
167
168
  Curses.mousemask(0)
168
169
  end
170
+
171
+ if @loading && self.y_max < @rs.y
172
+ log [:going, self.y_max, @rs.y]
173
+ @following = :going
174
+ end
169
175
  self.y = @rs.y
170
176
  end
171
177
 
@@ -283,21 +289,47 @@ class Screen
283
289
  name = @name ? "<#{@name}>" : ''
284
290
  mouse = @mouse ? ' [MOUSE]' : ''
285
291
  search = @rs.search ? " search[#{search_str}]" : ''
286
- loading = @loading ? " (loading...#{@load_unlimited ? '!' : nil}#{@following_mode ? ' following' : ''}) " : ''
292
+ loading = @loading ? " (loading...#{@load_unlimited ? '!' : nil}#{@following ? ' following' : ''}) " : ''
287
293
  x = self.x > 0 ? " x:#{self.x}" : ''
288
294
  screen_status "#{name} lines:#{self.y+1}/#{@lines.size}#{x}#{loading}#{search}#{mouse}"
289
295
  end
290
296
 
297
+ ANIMATION = ['[O ]',
298
+ '[o. ]',
299
+ '[... ]',
300
+ '[ ... ]',
301
+ '[ ... ]',
302
+ '[ ...]',
303
+ '[ .o]',
304
+ '[ O]',
305
+ '[ .o]',
306
+ '[ ...]',
307
+ '[ ... ]',
308
+ '[ ... ]',
309
+ '[ ... ]',
310
+ '[... ]',
311
+ '[o. ]',
312
+ ]
313
+
291
314
  def screen_status status, post = nil
292
- Curses.setpos Curses.lines-1, 0
293
- Curses.addstr ' '.ljust(Curses.cols)
315
+ cols = Curses.cols
316
+ line = Curses.lines-1
317
+ Curses.setpos line, 0
318
+ Curses.addstr ' '.ljust(cols)
319
+ len = status.size
320
+ len += post.size if post
294
321
 
295
322
  standout{
296
323
  Curses.setpos Curses.lines-1, 0
297
324
  Curses.addstr status
298
325
  }
299
326
  Curses.addstr post if post
300
- Curses.standend
327
+
328
+ if !post && len < cols - ANIMATION.first.size
329
+ Curses.setpos line, cols - ANIMATION.first.size - 1
330
+ @apos = (@apos + 1) % ANIMATION.size
331
+ Curses.addstr ANIMATION[@apos]
332
+ end
301
333
  end
302
334
 
303
335
  def check_update
@@ -320,7 +352,7 @@ class Screen
320
352
  def render_screen
321
353
  ev = nil
322
354
 
323
- ms = @following_mode ? 100 : 500
355
+ ms = @following ? 100 : 500
324
356
 
325
357
  ctimeout ms do
326
358
  while ev == nil
@@ -330,20 +362,27 @@ class Screen
330
362
  check_update
331
363
  y_max = self.y_max
332
364
 
333
- if @rs.search && @searching
334
- if search_next_move
335
- break
365
+ if @following
366
+ case @following
367
+ when :searching
368
+ break if search_next_move
369
+ when :going
370
+ if @rs.goto <= y_max
371
+ self.y = @rs.goto
372
+ break
373
+ end
374
+ when true
375
+ # ok
376
+ else
377
+ raise "unknown following mode: #{@following}"
336
378
  end
337
- end
338
379
 
339
- if @following_mode
340
380
  self.y = y_max
341
381
  end
342
382
  end
343
383
 
344
- @following_mode = false
384
+ @following = false
345
385
  set_load_unlimited false
346
- @searching = false
347
386
 
348
387
  return ev
349
388
  end
@@ -351,7 +390,7 @@ class Screen
351
390
 
352
391
  def search_next_move
353
392
  last_line = @lines.size
354
- log (@searching..last_line)
393
+ # log (@searching..last_line)
355
394
 
356
395
  (@searching...last_line).each{|i|
357
396
  if @rs.search === @lines[i]
@@ -371,6 +410,7 @@ class Screen
371
410
  else
372
411
  if @loading
373
412
  set_load_unlimited true
413
+ @following = :searching
374
414
  else
375
415
  screen_status "not found: [#{self.search_str}]"
376
416
  pause
@@ -465,7 +505,7 @@ class Screen
465
505
  end
466
506
 
467
507
  when 'F'
468
- @following_mode = true
508
+ @following = true
469
509
  set_load_unlimited true
470
510
 
471
511
  when 'L'
@@ -700,7 +740,7 @@ class KV
700
740
  case name
701
741
  when /(.+):(\d+)/
702
742
  name = $1
703
- @first_line = $2.to_i - 1
743
+ @opts[:first_line] = $2.to_i - 1
704
744
  retry
705
745
  when URI.regexp
706
746
  input = URI.open(name)
@@ -732,7 +772,7 @@ class KV
732
772
  opts.on('-T', '--time-stamp', 'Enable time stamp'){
733
773
  @opts[:time_stamp] = true
734
774
  }
735
- opts.on('-e CMD'){|cmd|
775
+ opts.on('-e CMD', 'Run CMD as a child process'){|cmd|
736
776
  @opts[:e] = cmd
737
777
  }
738
778
  opts.parse!(argv)
@@ -1,3 +1,3 @@
1
1
  module KV
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Sasada
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-18 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -61,7 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.1.2
64
+ rubyforge_project:
65
+ rubygems_version: 2.7.6
65
66
  signing_key:
66
67
  specification_version: 4
67
68
  summary: 'kv: A page viewer written by Ruby'