kv 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -3
  3. data/lib/kv.rb +58 -4
  4. data/lib/kv/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a94c201f245d4df4b646fa9b88cd197d915d37096962da6e0cca0bd8dbb39d24
4
- data.tar.gz: 0f8e816be09a9509e5d1fe5b6b157d8d3dcafefc8acd0e97f16a83893bd0aac1
3
+ metadata.gz: 70b1f3af205a0cc4e0654de74a8d9e31e023719c8cf04cd6fbb9e43d96b14be4
4
+ data.tar.gz: 5265f5930278a1f39f5d00f6a6f3265e436bcdce233b7350f8f791d7f0752fee
5
5
  SHA512:
6
- metadata.gz: 96524f391e1af962c1f276d6036ef73e07a2f182736b6d8d92ee1060d5dd82c778dba0567f3ca8eb719d5797fe1f67955768578ac1c34abb6171f9170a2a394a
7
- data.tar.gz: '092e3cb69c9b55c16435a88b3bcffc32e4e4d0ee2301d5f91f497fb538b75dcbfefafbd38f8b6e3dd957fa2be438df8e47391006ce7b1b21044088c052db3365'
6
+ metadata.gz: 935613e6eb8be95f504d75b777b83a864bab18a34ccbdc4694df5e82c8b2312d270e9f4f4f5da7ef07ed360cc083281705b61ff62a329aa7004da289e989909f
7
+ data.tar.gz: 7fb6b11b84f0c014c956cf0f0e223a74ce88426860f65919ef2e351028b957876c72a255fba10c2ed2e65dac0dbf701691cf10817745f7ec231a42de76ff7ed4
data/README.md CHANGED
@@ -10,8 +10,6 @@ Install it yourself as:
10
10
 
11
11
  kv requires recent Ruby and curses gem.
12
12
 
13
- # Usage
14
-
15
13
  ## Use kv
16
14
 
17
15
  ```
@@ -27,14 +25,18 @@ $ [CMD] | kv [OPTIONS]
27
25
  # View command help
28
26
  $ kv
29
27
 
30
- Options:
28
+ Usage: kv [options]
31
29
  -f following mode like "tail -f"
32
30
  -n, --line-number LINE goto LINE
33
31
  -N Show lines
34
32
  -T, --time-stamp Enable time stamp
35
33
  -e CMD Run CMD as a child process
34
+ -p, --pipe Open named pipe
35
+ -s Separation mode (tsv)
36
36
  ```
37
37
 
38
+ Note that `--pipe` option creates a named pipe (`~/.kv_pipe` or a specified file) if there is not a fifo file.
39
+
38
40
  ## Command on a pager
39
41
 
40
42
  ```
data/lib/kv.rb CHANGED
@@ -30,8 +30,8 @@ class Screen
30
30
 
31
31
  def initialize input, lines: [],
32
32
  name: nil, search: nil, first_line: 0,
33
- following_mode: false, line_mode: false,
34
- time_stamp: nil, ext_input: nil
33
+ following_mode: false, line_mode: false, separation_mode: false,
34
+ time_stamp: nil, ext_input: nil, fifo_file: nil
35
35
  @rs = RenderStatus.new
36
36
  @last_rs = nil
37
37
  @rs.y = first_line
@@ -48,6 +48,8 @@ class Screen
48
48
 
49
49
  @time_stamp = time_stamp
50
50
  @ext_input = ext_input
51
+ @fifo_file = fifo_file
52
+ @separation_mode = separation_mode
51
53
 
52
54
  @lines = lines
53
55
  @mode = :screen
@@ -106,6 +108,7 @@ class Screen
106
108
  end
107
109
 
108
110
  @lines << setup_line(line)
111
+
109
112
  while !@load_unlimited && @lines.size > self.y + @buffer_lines
110
113
  @yq.pop; @yq.clear
111
114
  end
@@ -115,6 +118,10 @@ class Screen
115
118
  if @filename
116
119
  @file_mtime = File.mtime(@filename)
117
120
  @file_lastpos = input.tell
121
+ elsif @fifo_file
122
+ input = open(@fifo_file)
123
+ log(input)
124
+ redo
118
125
  end
119
126
  input.close
120
127
  @loading = false
@@ -215,6 +222,15 @@ class Screen
215
222
 
216
223
  Curses.clear
217
224
 
225
+ if @separation_mode && (lines = @lines[self.y ... (self.y + c_lines - 1)])
226
+ max_cols = []
227
+ lines.each.with_index{|line, ln|
228
+ line.split("\t").each_with_index{|w, i|
229
+ max_cols[i] = max_cols[i] ? [max_cols[i], w.size].max : w.size
230
+ }
231
+ }
232
+ end
233
+
218
234
  (c_lines-1).times{|i|
219
235
  lno = i + self.y
220
236
  line = @lines[lno]
@@ -257,6 +273,17 @@ class Screen
257
273
 
258
274
  line = line[self.x, cols] || ''
259
275
 
276
+ if @separation_mode
277
+ line = line.split(/\t/).tap{|e|
278
+ if (max = max_cols.size) > 0
279
+ # fill empty columns
280
+ e[max - 1] ||= nil
281
+ end
282
+ }.map.with_index{|w, i|
283
+ "%-#{max_cols[i]}s" % w
284
+ }.join(' | ')
285
+ end
286
+
260
287
  if !@rs.search || !(Regexp === @rs.search)
261
288
  Curses.addstr line
262
289
  else
@@ -712,10 +739,31 @@ class KV
712
739
  }
713
740
 
714
741
  files = parse_option(argv)
742
+ name = files.shift
715
743
 
716
744
  @pipe_in = nil
717
745
 
718
- if files.empty?
746
+ if @opts[:pipe] || (name && File.pipe?(name))
747
+ @opts.delete(:pipe)
748
+ @opts[:fifo_file] = name || '/tmp/kv_pipe'
749
+
750
+ if name && File.pipe?(name)
751
+ # ok
752
+ else
753
+ begin
754
+ name ||= File.expand_path('~/.kv_pipe')
755
+ unlink_name = name
756
+ File.mkfifo(name)
757
+ at_exit{ puts "$ rm #{unlink_name}"; File.unlink(unlink_name) }
758
+ rescue Errno::EEXIST
759
+ raise "#{name} already exists."
760
+ end
761
+ end
762
+
763
+ puts "waiting for #{name}"
764
+ input = @pipe_in = open(name)
765
+ name = nil
766
+ elsif !name
719
767
  case
720
768
  when @opts[:e]
721
769
  cmd = @opts.delete(:e)
@@ -733,7 +781,6 @@ class KV
733
781
  @pipe_in = input
734
782
  end
735
783
  else
736
- name = files.shift
737
784
  begin
738
785
  input = open(name)
739
786
  rescue Errno::ENOENT
@@ -775,6 +822,12 @@ class KV
775
822
  opts.on('-e CMD', 'Run CMD as a child process'){|cmd|
776
823
  @opts[:e] = cmd
777
824
  }
825
+ opts.on('-p', '--pipe', 'Open named pipe'){
826
+ @opts[:pipe] = true
827
+ }
828
+ opts.on('-s', 'Separation mode (tsv)'){
829
+ @opts[:separation_mode] = true
830
+ }
778
831
  opts.parse!(argv)
779
832
  end
780
833
 
@@ -785,6 +838,7 @@ class KV
785
838
  @screens.last.control
786
839
  rescue PopScreen
787
840
  @screens.pop
841
+ @screens.last.redraw!
788
842
  rescue PushScreen => e
789
843
  @screens.push e.screen
790
844
  @screens.last.redraw!
@@ -1,3 +1,3 @@
1
1
  module KV
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.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.5.0
4
+ version: 0.6.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-03-02 00:00:00.000000000 Z
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses