kv 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kv.rb +72 -31
  3. data/lib/kv/version.rb +1 -1
  4. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c689e9c776cfb742a4258bcbb83ed972be567eff1478e734f30abca73aaed0d
4
- data.tar.gz: 9aa2015affec2a824ce1f528f29ad180d48be400ecf5505932ad6c8d229c9334
3
+ metadata.gz: 3c803b1b67678cd6668eff3068451093dba82fa6bd85e09a7c32be56c7febeaf
4
+ data.tar.gz: 1d49373d49d9bc626d2a5635538dc58fe8839927461db18befcaec4d187fd14b
5
5
  SHA512:
6
- metadata.gz: 4d261340c36970a0b5a828b4ff69868f0bc51858857a42e5307f2194bbc4116bdf6157064067fbbdfd4f175c1e8888e499163aca789fdcc02d93c1302208c959
7
- data.tar.gz: 39e63f31e30988bc152a08d6afd77c605662291722912d2e3f9981f6731f421d8bb88da0c298b22f9bdaa116afabc8538ee152c8ec0e33afb5538454af604797
6
+ metadata.gz: 9b625de709b8af9d9f55672504c78b73979ff9f2a054c9e78503796fa659861a9ea14ef8c4a9990ab1006a7f315a63b88f7fcd54e06b96997e3031bcd7e3d5ca
7
+ data.tar.gz: 382d0287eaf1ac11904f8a7e71ed4be9019d15443b202991a5bb750d51b3a78283a439cbbfe5547ce8d26b9c2b8603abd29a63e45092f83ec48e5fabf307749f
data/lib/kv.rb CHANGED
@@ -28,7 +28,10 @@ class Screen
28
28
  end
29
29
  end
30
30
 
31
- def initialize input, lines: [], search: nil, name: nil, following_mode: false, first_line: 0, line_mode: false, time_stamp: nil
31
+ def initialize input, lines: [],
32
+ name: nil, search: nil, first_line: 0,
33
+ following_mode: false, line_mode: false,
34
+ time_stamp: nil, ext_input: nil
32
35
  @rs = RenderStatus.new
33
36
  @last_rs = nil
34
37
  @rs.y = first_line
@@ -42,7 +45,9 @@ class Screen
42
45
 
43
46
  @name = name
44
47
  @filename = @name if @name && File.exist?(@name)
48
+
45
49
  @time_stamp = time_stamp
50
+ @ext_input = ext_input
46
51
 
47
52
  @lines = lines
48
53
  @mode = :screen
@@ -189,18 +194,6 @@ class Screen
189
194
  end
190
195
  end
191
196
 
192
- def screen_status status, post = nil
193
- Curses.setpos Curses.lines-1, 0
194
- Curses.addstr ' '.ljust(Curses.cols)
195
-
196
- standout{
197
- Curses.setpos Curses.lines-1, 0
198
- Curses.addstr status
199
- }
200
- Curses.addstr post if post
201
- Curses.standend
202
- end
203
-
204
197
  LINE_ATTR = Curses::A_DIM
205
198
 
206
199
  def render_data
@@ -295,6 +288,18 @@ class Screen
295
288
  screen_status "#{name} lines:#{self.y+1}/#{@lines.size}#{x}#{loading}#{search}#{mouse}"
296
289
  end
297
290
 
291
+ def screen_status status, post = nil
292
+ Curses.setpos Curses.lines-1, 0
293
+ Curses.addstr ' '.ljust(Curses.cols)
294
+
295
+ standout{
296
+ Curses.setpos Curses.lines-1, 0
297
+ Curses.addstr status
298
+ }
299
+ Curses.addstr post if post
300
+ Curses.standend
301
+ end
302
+
298
303
  def check_update
299
304
  if @loading == false
300
305
  if @filename && File.exist?(@filename) && File.mtime(@filename) > @file_mtime
@@ -392,26 +397,32 @@ class Screen
392
397
  ev
393
398
  end
394
399
 
395
- def input_str pattern, str = ''.dup, other_actions: nil
396
- loop{
397
- ev = Curses.getch
400
+ def input_str pattern, str = ''.dup, other_actions: {}
401
+ update_action = other_actions[:update]
398
402
 
399
- case ev
400
- when 10
401
- return str
402
- when Curses::KEY_BACKSPACE
403
- str.chop!
404
- when pattern
405
- str << ev
406
- else
407
- if other_actions && (action = other_actions[ev])
408
- action.call(ev)
403
+ ctimeout update_action ? 200 : -1 do
404
+ loop do
405
+ ev = Curses.getch
406
+
407
+ case ev
408
+ when 10
409
+ return str
410
+ when Curses::KEY_BACKSPACE
411
+ str.chop!
412
+ when pattern
413
+ str << ev
414
+ when nil # timeout
415
+ update_action[str]
409
416
  else
410
- log "failure: #{key_name ev}"
411
- return nil
417
+ if action = other_actions[ev]
418
+ action.call(ev)
419
+ else
420
+ log "failure: #{key_name ev}"
421
+ return nil
422
+ end
412
423
  end
413
424
  end
414
- }
425
+ end
415
426
  end
416
427
 
417
428
  def pause
@@ -538,7 +549,7 @@ class Screen
538
549
 
539
550
  when 'v'
540
551
  if @filename
541
- system("vi #{@filename} +#{self.y + 1}")
552
+ syste m("vi #{@filename} +#{self.y + 1}")
542
553
  @last_rs = nil
543
554
  end
544
555
 
@@ -583,6 +594,26 @@ class Screen
583
594
  when 't'
584
595
  Curses.close_screen
585
596
  @mode = :terminal
597
+ when 'x'
598
+ while @ext_input && !@ext_input.closed?
599
+ update_ext_status = -> str do
600
+ screen_status "input for ext:", str
601
+ end
602
+ update_ext_status['']
603
+ actions = {
604
+ update: -> str do
605
+ self.y = self.y_max
606
+ render_data
607
+ update_ext_status[str]
608
+ end
609
+ }
610
+ str = input_str(/./, other_actions: actions)
611
+ if str && !str.empty?
612
+ @ext_input.puts str unless @ext_input.closed?
613
+ else
614
+ break
615
+ end
616
+ end
586
617
 
587
618
  when 'H'
588
619
  if @meta
@@ -645,7 +676,14 @@ class KV
645
676
  @pipe_in = nil
646
677
 
647
678
  if files.empty?
648
- if STDIN.isatty
679
+ case
680
+ when @opts[:e]
681
+ cmd = @opts.delete(:e)
682
+ input = IO.popen(cmd, 'a+')
683
+ name = nil
684
+ @pipe_in = input
685
+ @opts[:ext_input] = input
686
+ when STDIN.isatty
649
687
  input = help_io
650
688
  name = 'HELP'
651
689
  else
@@ -694,6 +732,9 @@ class KV
694
732
  opts.on('-T', '--time-stamp', 'Enable time stamp'){
695
733
  @opts[:time_stamp] = true
696
734
  }
735
+ opts.on('-e CMD'){|cmd|
736
+ @opts[:e] = cmd
737
+ }
697
738
  opts.parse!(argv)
698
739
  end
699
740
 
data/lib/kv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module KV
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.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.3.0
4
+ version: 0.4.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-17 00:00:00.000000000 Z
11
+ date: 2020-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -61,8 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubyforge_project:
65
- rubygems_version: 2.7.6
64
+ rubygems_version: 3.1.2
66
65
  signing_key:
67
66
  specification_version: 4
68
67
  summary: 'kv: A page viewer written by Ruby'