daff 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -46,9 +46,14 @@ Call as:
46
46
  daff [--output OUTPUT.csv] a.csv b.csv
47
47
  daff [--output OUTPUT.csv] parent.csv a.csv b.csv
48
48
  daff [--output OUTPUT.jsonbook] a.jsonbook b.jsonbook
49
- daff patch [--output OUTPUT.csv] source.csv patch.csv
49
+ daff patch [--inplace] [--output OUTPUT.csv] a.csv patch.csv
50
+ daff merge [--inplace] [--output OUTPUT.csv] parent.csv a.csv b.csv
50
51
  daff trim [--output OUTPUT.csv] source.csv
51
52
  daff render [--output OUTPUT.html] diff.csv
53
+ daff git
54
+ daff version
55
+
56
+ The --inplace option to patch and merge will result in modification of a.csv.
52
57
 
53
58
  If you need more control, here is the full list of flags:
54
59
  daff diff [--output OUTPUT.csv] [--context NUM] [--all] [--act ACT] a.csv b.csv
@@ -56,6 +61,9 @@ If you need more control, here is the full list of flags:
56
61
  --all: do not prune unchanged rows
57
62
  --act ACT: show only a certain kind of change (update, insert, delete)
58
63
 
64
+ daff diff --git path old-file old-hex old-mode new-file new-hex new-mode
65
+ --git: process arguments provided by git to diff drivers
66
+
59
67
  daff render [--output OUTPUT.html] [--css CSS.css] [--fragment] [--plain] diff.csv
60
68
  --css CSS.css: generate a suitable css file to go with the html
61
69
  --fragment: generate just a html fragment rather than a page
@@ -65,35 +73,9 @@ If you need more control, here is the full list of flags:
65
73
  Using with git
66
74
  --------------
67
75
 
68
- Run `daff git csv` to see how to use daff to improve `git`'s handling
69
- of csv files.
70
-
71
- ````
72
- $ daff git csv
73
- You can use daff to improve git's handling of csv files, by using it as a
74
- diff driver (for showing what has changed) and as a merge driver (for merging
75
- changes between multiple versions). Here is how.
76
-
77
- Create and add a file called .gitattributes in the root directory of your
78
- repository, containing:
79
-
80
- *.csv diff=daff-diff
81
- *.csv merge=daff-merge
82
-
83
- Create a file called .gitconfig in your home directory (or alternatively
84
- open .git/config for a particular repository) and add:
85
-
86
- [merge "daff-merge"]
87
- name = daff tabular merge
88
- driver = daff merge --output %A %O %A %B
89
-
90
- [diff "daff-diff"]
91
- command = daff diff --git
92
-
93
- Make sure you can run daff from the command-line as just "daff" - if not,
94
- replace "daff" in the driver and command lines above with the correct way
95
- to call it.
96
- ````
76
+ Run `daff git csv` to install daff as a diff and merge handler
77
+ for `*.csv` files in your repository. Run `daff git` for instructions
78
+ on doing this manually.
97
79
 
98
80
  The library
99
81
  -----------
@@ -51,6 +51,7 @@ require_relative 'lib/coopy/table_diff'
51
51
  require_relative 'lib/coopy/table_io'
52
52
  require_relative 'lib/coopy/table_modifier'
53
53
  require_relative 'lib/coopy/table_text'
54
+ require_relative 'lib/coopy/terminal_diff_render'
54
55
  require_relative 'lib/coopy/unit'
55
56
  require_relative 'lib/coopy/viewed_datum'
56
57
  require_relative 'lib/coopy/viterbi'
@@ -170,7 +170,7 @@ module Coopy
170
170
  key = "add_diff_driver_" + _hx_str(format1)
171
171
  if !@status.include?(key)
172
172
  if !have_diff_driver
173
- r = self.command(io,"git",["config","--global","diff.daff-" + _hx_str(format1) + ".command",_hx_str(@daff_cmd) + " diff --git"])
173
+ r = self.command(io,"git",["config","--global","diff.daff-" + _hx_str(format1) + ".command",_hx_str(@daff_cmd) + " diff --color --git"])
174
174
  return r if r == 999
175
175
  io.write_stdout("- Added diff driver for " + _hx_str(format1) + "\n")
176
176
  else
@@ -258,6 +258,7 @@ module Coopy
258
258
  pretty = true
259
259
  inplace = false
260
260
  git = false
261
+ color = false
261
262
  flags = ::Coopy::CompareFlags.new
262
263
  flags.always_show_header = true
263
264
  while(more)
@@ -320,6 +321,11 @@ module Coopy
320
321
  git = true
321
322
  args.slice!(i,1)
322
323
  break
324
+ elsif tag == "--color"
325
+ more = true
326
+ color = true
327
+ args.slice!(i,1)
328
+ break
323
329
  end
324
330
  end
325
331
  end
@@ -345,18 +351,18 @@ module Coopy
345
351
  io.write_stdout(" *.csv merge=daff-csv\n")
346
352
  io.write_stdout("\nCreate a file called .gitconfig in your home directory (or alternatively\nopen .git/config for a particular repository) and add:\n\n")
347
353
  io.write_stdout(" [diff \"daff-csv\"]\n")
348
- io.write_stdout(" command = daff diff --git\n")
354
+ io.write_stdout(" command = daff diff --color --git\n")
349
355
  io.write_stderr("\n")
350
356
  io.write_stdout(" [merge \"daff-csv\"]\n")
351
357
  io.write_stdout(" name = daff tabular merge\n")
352
358
  io.write_stdout(" driver = daff merge --output %A %O %A %B\n\n")
353
- io.write_stderr("Make sure you can run daff from the command-line as just \"daff\" - if not,\nreplace \"daff\" in the driver and command lines above with the correct way\nto call it.")
359
+ io.write_stderr("Make sure you can run daff from the command-line as just \"daff\" - if not,\nreplace \"daff\" in the driver and command lines above with the correct way\nto call it. Omit --color if your terminal does not support ANSI colors.")
354
360
  io.write_stderr("\n")
355
361
  return 0
356
362
  end
357
363
  io.write_stderr("daff can produce and apply tabular diffs.\n")
358
364
  io.write_stderr("Call as:\n")
359
- io.write_stderr(" daff [--output OUTPUT.csv] a.csv b.csv\n")
365
+ io.write_stderr(" daff [--color] [--output OUTPUT.csv] a.csv b.csv\n")
360
366
  io.write_stderr(" daff [--output OUTPUT.csv] parent.csv a.csv b.csv\n")
361
367
  io.write_stderr(" daff [--output OUTPUT.jsonbook] a.jsonbook b.jsonbook\n")
362
368
  io.write_stderr(" daff patch [--inplace] [--output OUTPUT.csv] a.csv patch.csv\n")
@@ -370,6 +376,7 @@ module Coopy
370
376
  io.write_stderr("\n")
371
377
  io.write_stderr("If you need more control, here is the full list of flags:\n")
372
378
  io.write_stderr(" daff diff [--output OUTPUT.csv] [--context NUM] [--all] [--act ACT] a.csv b.csv\n")
379
+ io.write_stderr(" --color: highlight changes with terminal colors\n")
373
380
  io.write_stderr(" --context NUM: show NUM rows of context\n")
374
381
  io.write_stderr(" --all: do not prune unchanged rows\n")
375
382
  io.write_stderr(" --act ACT: show only a certain kind of change (update, insert, delete)\n")
@@ -436,7 +443,12 @@ module Coopy
436
443
  td = ::Coopy::TableDiff.new(align,flags)
437
444
  o = ::Coopy::SimpleTable.new(0,0)
438
445
  td.hilite(o)
439
- tool.save_table(output,o)
446
+ if color
447
+ render = ::Coopy::TerminalDiffRender.new
448
+ tool.save_text(output,render.render(o))
449
+ else
450
+ tool.save_table(output,o)
451
+ end
440
452
  elsif cmd1 == "patch"
441
453
  patcher = ::Coopy::HighlightPatch.new(a,b)
442
454
  patcher.apply
@@ -468,7 +480,7 @@ module Coopy
468
480
  class << self
469
481
  attr_accessor :version
470
482
  end
471
- @version = "1.1.6"
483
+ @version = "1.1.7"
472
484
 
473
485
  def Coopy.compare_tables(local,remote)
474
486
  ct = ::Coopy::CompareTable.new
@@ -642,7 +654,7 @@ module Coopy
642
654
  txt += "\n"
643
655
  end
644
656
  end
645
- ::Haxe::Log._trace.call(txt,{ file_name: "Coopy.hx", line_number: 615, class_name: "coopy.Coopy", method_name: "show"})
657
+ ::Haxe::Log._trace.call(txt,{ file_name: "Coopy.hx", line_number: 627, class_name: "coopy.Coopy", method_name: "show"})
646
658
  end
647
659
 
648
660
  def Coopy.jsonify(t)
@@ -34,7 +34,6 @@ module Coopy
34
34
  rescue => e
35
35
  return 1
36
36
  end
37
- return 1
38
37
  end
39
38
 
40
39
  def async
@@ -43,7 +42,6 @@ module Coopy
43
42
 
44
43
  def exists(path)
45
44
  return File.exist?(path)
46
- return false
47
45
  end
48
46
 
49
47
  end
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class TerminalDiffRender
6
+
7
+ def initialize
8
+ end
9
+
10
+ def render(t)
11
+ csv = ::Coopy::Csv.new
12
+ result = ""
13
+ w = t.get_width
14
+ h = t.get_height
15
+ txt = ""
16
+ v = t.get_cell_view
17
+ tt = ::Coopy::TableText.new(t)
18
+ codes = {}
19
+ codes["header"] = "\x1B[0;1m"
20
+ codes["add"] = "\x1B[32;1m"
21
+ codes["conflict"] = "\x1B[33;1m"
22
+ codes["modify"] = "\x1B[34;1m"
23
+ codes["remove"] = "\x1B[31;1m"
24
+ codes["done"] = "\x1B[0m"
25
+ begin
26
+ _g = 0
27
+ while(_g < h)
28
+ y = _g
29
+ _g+=1
30
+ begin
31
+ _g1 = 0
32
+ while(_g1 < w)
33
+ x = _g1
34
+ _g1+=1
35
+ txt += "," if x > 0
36
+ val = tt.get_cell_text(x,y)
37
+ val = "" if val == nil
38
+ cell = ::Coopy::DiffRender.render_cell(tt,x,y)
39
+ code = nil
40
+ code = codes[cell.category] if cell.category != nil
41
+ if code != nil
42
+ if cell.rvalue != nil
43
+ val = _hx_str(codes["remove"]) + _hx_str(cell.lvalue) + _hx_str(codes["modify"]) + _hx_str(cell.separator) + _hx_str(codes["add"]) + _hx_str(cell.rvalue) + _hx_str(codes["done"])
44
+ val = _hx_str(codes["conflict"]) + _hx_str(cell.pvalue) + _hx_str(codes["modify"]) + _hx_str(cell.separator) + _hx_str(val) if cell.pvalue != nil
45
+ else
46
+ val = _hx_str(code) + _hx_str(val) + _hx_str(codes["done"])
47
+ end
48
+ end
49
+ txt += csv.render_cell(v,val)
50
+ end
51
+ end
52
+ txt += "\r\n"
53
+ end
54
+ end
55
+ return txt
56
+ end
57
+
58
+ end
59
+
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-07-11 00:00:00.000000000 Z
13
+ date: 2014-07-17 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Diff and patch tables
16
16
  email:
@@ -42,6 +42,7 @@ files:
42
42
  - lib/lib/coopy/cross_match.rb
43
43
  - lib/lib/coopy/table_diff.rb
44
44
  - lib/lib/coopy/alignment.rb
45
+ - lib/lib/coopy/terminal_diff_render.rb
45
46
  - lib/lib/coopy/table_modifier.rb
46
47
  - lib/lib/coopy/highlight_patch.rb
47
48
  - lib/lib/coopy/table_text.rb
@@ -127,42 +128,37 @@ summary: ! '[![Build Status](https://travis-ci.org/paulfitz/daff.svg?branch=mast
127
128
  can run `daff`/`daff.py`/`daff.rb` as a utility program: ```` $ daff daff can produce
128
129
  and apply tabular diffs. Call as: daff [--output OUTPUT.csv] a.csv b.csv daff [--output
129
130
  OUTPUT.csv] parent.csv a.csv b.csv daff [--output OUTPUT.jsonbook] a.jsonbook b.jsonbook
130
- daff patch [--output OUTPUT.csv] source.csv patch.csv daff trim [--output OUTPUT.csv]
131
- source.csv daff render [--output OUTPUT.html] diff.csv If you need more control,
132
- here is the full list of flags: daff diff [--output OUTPUT.csv] [--context NUM]
133
- [--all] [--act ACT] a.csv b.csv --context NUM: show NUM rows of context --all: do
131
+ daff patch [--inplace] [--output OUTPUT.csv] a.csv patch.csv daff merge [--inplace]
132
+ [--output OUTPUT.csv] parent.csv a.csv b.csv daff trim [--output OUTPUT.csv] source.csv
133
+ daff render [--output OUTPUT.html] diff.csv daff git daff version The --inplace
134
+ option to patch and merge will result in modification of a.csv. If you need more
135
+ control, here is the full list of flags: daff diff [--output OUTPUT.csv] [--context
136
+ NUM] [--all] [--act ACT] a.csv b.csv --context NUM: show NUM rows of context --all: do
134
137
  not prune unchanged rows --act ACT: show only a certain kind of change (update,
135
- insert, delete) daff render [--output OUTPUT.html] [--css CSS.css] [--fragment]
136
- [--plain] diff.csv --css CSS.css: generate a suitable css file to go with the html
137
- --fragment: generate just a html fragment rather than a page --plain: do
138
- not use fancy utf8 characters to make arrows prettier ```` Using with git -------------- Run
139
- `daff git csv` to see how to use daff to improve `git`''s handling of csv files. ````
140
- $ daff git csv You can use daff to improve git''s handling of csv files, by using
141
- it as a diff driver (for showing what has changed) and as a merge driver (for merging
142
- changes between multiple versions). Here is how. Create and add a file called
143
- .gitattributes in the root directory of your repository, containing: *.csv diff=daff-diff
144
- *.csv merge=daff-merge Create a file called .gitconfig in your home directory (or
145
- alternatively open .git/config for a particular repository) and add: [merge "daff-merge"]
146
- name = daff tabular merge driver = daff merge --output %A %O %A %B [diff "daff-diff"]
147
- command = daff diff --git Make sure you can run daff from the command-line as just
148
- "daff" - if not, replace "daff" in the driver and command lines above with the correct
149
- way to call it. ```` The library ----------- You can use `daff` as a library from
150
- any supported language. We take here the example of Javascript. To use `daff`
151
- on a webpage, first include `daff.js`: ```html <script src="daff.js"></script> ```
152
- Or if using node outside the browser: ```js var daff = require(''daff''); ``` For
153
- concreteness, assume we have two versions of a table, `data1` and `data2`: ```js
154
- var data1 = [ [''Country'',''Capital''], [''Ireland'',''Dublin''], [''France'',''Paris''],
155
- [''Spain'',''Barcelona''] ]; var data2 = [ [''Country'',''Code'',''Capital''], [''Ireland'',''ie'',''Dublin''],
156
- [''France'',''fr'',''Paris''], [''Spain'',''es'',''Madrid''], [''Germany'',''de'',''Berlin'']
157
- ]; ``` To make those tables accessible to the library, we wrap them in `daff.TableView`:
158
- ```js var table1 = new daff.TableView(data1); var table2 = new daff.TableView(data2);
159
- ``` We can now compute the alignment between the rows and columns in the two tables:
160
- ```js var alignment = daff.compareTables(table1,table2).align(); ``` To produce
161
- a diff from the alignment, we first need a table for the output: ```js var data_diff
162
- = []; var table_diff = new daff.TableView(data_diff); ``` Using default options
163
- for the diff: ```js var flags = new daff.CompareFlags(); var highlighter = new daff.TableDiff(alignment,flags);
164
- highlighter.hilite(table_diff); ``` The diff is now in `data_diff` in highlighter
165
- format, see specification here: > http://share.find.coop/doc/spec_hilite.html ```js
138
+ insert, delete) daff diff --git path old-file old-hex old-mode new-file new-hex
139
+ new-mode --git: process arguments provided by git to diff drivers daff
140
+ render [--output OUTPUT.html] [--css CSS.css] [--fragment] [--plain] diff.csv --css
141
+ CSS.css: generate a suitable css file to go with the html --fragment: generate
142
+ just a html fragment rather than a page --plain: do not use fancy utf8 characters
143
+ to make arrows prettier ```` Using with git -------------- Run `daff git csv`
144
+ to install daff as a diff and merge handler for `*.csv` files in your repository. Run
145
+ `daff git` for instructions on doing this manually. The library ----------- You
146
+ can use `daff` as a library from any supported language. We take here the example
147
+ of Javascript. To use `daff` on a webpage, first include `daff.js`: ```html <script
148
+ src="daff.js"></script> ``` Or if using node outside the browser: ```js var daff
149
+ = require(''daff''); ``` For concreteness, assume we have two versions of a table,
150
+ `data1` and `data2`: ```js var data1 = [ [''Country'',''Capital''], [''Ireland'',''Dublin''],
151
+ [''France'',''Paris''], [''Spain'',''Barcelona''] ]; var data2 = [ [''Country'',''Code'',''Capital''],
152
+ [''Ireland'',''ie'',''Dublin''], [''France'',''fr'',''Paris''], [''Spain'',''es'',''Madrid''],
153
+ [''Germany'',''de'',''Berlin''] ]; ``` To make those tables accessible to the library,
154
+ we wrap them in `daff.TableView`: ```js var table1 = new daff.TableView(data1);
155
+ var table2 = new daff.TableView(data2); ``` We can now compute the alignment between
156
+ the rows and columns in the two tables: ```js var alignment = daff.compareTables(table1,table2).align();
157
+ ``` To produce a diff from the alignment, we first need a table for the output:
158
+ ```js var data_diff = []; var table_diff = new daff.TableView(data_diff); ``` Using
159
+ default options for the diff: ```js var flags = new daff.CompareFlags(); var highlighter
160
+ = new daff.TableDiff(alignment,flags); highlighter.hilite(table_diff); ``` The
161
+ diff is now in `data_diff` in highlighter format, see specification here: > http://share.find.coop/doc/spec_hilite.html ```js
166
162
  [ [ ''!'', '''', ''+++'', '''' ], [ ''@@'', ''Country'', ''Code'', ''Capital'' ],
167
163
  [ ''+'', ''Ireland'', ''ie'', ''Dublin'' ], [ ''+'', ''France'', ''fr'', ''Paris''
168
164
  ], [ ''->'', ''Spain'', ''es'', ''Barcelona->Madrid'' ], [ ''+++'', ''Germany'',