kv 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kv.rb +72 -31
- data/lib/kv/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: 3c803b1b67678cd6668eff3068451093dba82fa6bd85e09a7c32be56c7febeaf
|
4
|
+
data.tar.gz: 1d49373d49d9bc626d2a5635538dc58fe8839927461db18befcaec4d187fd14b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: [],
|
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:
|
396
|
-
|
397
|
-
ev = Curses.getch
|
400
|
+
def input_str pattern, str = ''.dup, other_actions: {}
|
401
|
+
update_action = other_actions[:update]
|
398
402
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
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
|
-
|
411
|
-
|
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
|
-
|
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
|
-
|
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
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
|
+
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-
|
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
|
-
|
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'
|