daff 1.2.1 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,7 +18,7 @@ For a live demo, see:
18
18
  Install the library for your favorite language:
19
19
  ````sh
20
20
  npm install daff -g # node/javascript
21
- pip3 install daff # python3
21
+ pip install daff # python
22
22
  gem install daff # ruby
23
23
  composer require paulfitz/daff-php # php
24
24
  ````
@@ -545,7 +545,7 @@ module Coopy
545
545
  class << self
546
546
  attr_accessor :version
547
547
  end
548
- @version = "1.2.1"
548
+ @version = "1.2.3"
549
549
 
550
550
  def Coopy.compare_tables(local,remote,flags = nil)
551
551
  comp = ::Coopy::TableComparisonState.new
@@ -39,7 +39,10 @@ module Coopy
39
39
  i = _g1
40
40
  _g1+=1
41
41
  key = @keys[i]
42
- @keys[i] = key = self.to_key(t,i) if key == nil
42
+ if key == nil
43
+ key = self.to_key(t,i)
44
+ @keys[i] = key
45
+ end
43
46
  item = @items[key]
44
47
  if item == nil
45
48
  item = ::Coopy::IndexItem.new
@@ -264,7 +264,8 @@ module Coopy
264
264
  a = @align.get_source
265
265
  b = @align.get_target
266
266
  p = a
267
- rp_header = ra_header = @align.meta.get_source_header
267
+ ra_header = @align.meta.get_source_header
268
+ rp_header = ra_header
268
269
  rb_header = @align.meta.get_target_header
269
270
  if @align.get_index_columns != nil
270
271
  _g3 = 0
@@ -5,25 +5,42 @@ module Coopy
5
5
  class TerminalDiffRender
6
6
 
7
7
  def initialize
8
+ @align_columns = true
9
+ end
10
+
11
+ protected
12
+
13
+ attr_accessor :codes
14
+ attr_accessor :tt
15
+ attr_accessor :csv
16
+ attr_accessor :v
17
+ attr_accessor :align_columns
18
+
19
+ public
20
+
21
+ def align_columns(enable)
22
+ @align_columns = enable
8
23
  end
9
24
 
10
25
  def render(t)
11
- csv = ::Coopy::Csv.new
26
+ @csv = ::Coopy::Csv.new
12
27
  result = ""
13
28
  w = t.get_width
14
29
  h = t.get_height
15
30
  txt = ""
16
- v = t.get_cell_view
17
- tt = ::Coopy::TableText.new(t)
18
- codes = {}
19
- codes["header"] = "\x1B[0;1m"
20
- codes["spec"] = "\x1B[35;1m"
21
- codes["add"] = "\x1B[32;1m"
22
- codes["conflict"] = "\x1B[33;1m"
23
- codes["modify"] = "\x1B[34;1m"
24
- codes["remove"] = "\x1B[31;1m"
25
- codes["minor"] = "\x1B[2m"
26
- codes["done"] = "\x1B[0m"
31
+ @v = t.get_cell_view
32
+ @tt = ::Coopy::TableText.new(t)
33
+ @codes = {}
34
+ @codes["header"] = "\x1B[0;1m"
35
+ @codes["spec"] = "\x1B[35;1m"
36
+ @codes["add"] = "\x1B[32;1m"
37
+ @codes["conflict"] = "\x1B[33;1m"
38
+ @codes["modify"] = "\x1B[34;1m"
39
+ @codes["remove"] = "\x1B[31;1m"
40
+ @codes["minor"] = "\x1B[2m"
41
+ @codes["done"] = "\x1B[0m"
42
+ sizes = nil
43
+ sizes = self.pick_sizes(t) if @align_columns
27
44
  begin
28
45
  _g = 0
29
46
  while(_g < h)
@@ -34,34 +51,120 @@ module Coopy
34
51
  while(_g1 < w)
35
52
  x = _g1
36
53
  _g1+=1
37
- txt += _hx_str(codes["minor"]) + "," + _hx_str(codes["done"]) if x > 0
38
- val = tt.get_cell_text(x,y)
39
- val = "" if val == nil
40
- cell = ::Coopy::DiffRender.render_cell(tt,x,y)
41
- code = nil
42
- code = codes[cell.category] if cell.category != nil
43
- if cell.category_given_tr != nil
44
- code_tr = codes[cell.category_given_tr]
45
- code = code_tr if code_tr != nil
46
- end
47
- if code != nil
48
- if cell.rvalue != nil
49
- val = _hx_str(codes["remove"]) + _hx_str(cell.lvalue) + _hx_str(codes["modify"]) + _hx_str(cell.pretty_separator) + _hx_str(codes["add"]) + _hx_str(cell.rvalue) + _hx_str(codes["done"])
50
- val = _hx_str(codes["conflict"]) + _hx_str(cell.pvalue) + _hx_str(codes["modify"]) + _hx_str(cell.pretty_separator) + _hx_str(val) if cell.pvalue != nil
51
- else
52
- val = cell.pretty_value
53
- val = _hx_str(code) + _hx_str(val) + _hx_str(codes["done"])
54
+ txt += _hx_str(@codes["minor"]) + "," + _hx_str(@codes["done"]) if x > 0
55
+ txt += self.get_text(x,y,true)
56
+ if sizes != nil
57
+ bit = self.get_text(x,y,false)
58
+ begin
59
+ _g3 = 0
60
+ _g2 = sizes[x] - bit.length
61
+ while(_g3 < _g2)
62
+ i = _g3
63
+ _g3+=1
64
+ txt += " "
65
+ end
54
66
  end
55
67
  end
56
- txt += csv.render_cell(v,val)
57
68
  end
58
69
  end
59
70
  txt += "\r\n"
60
71
  end
61
72
  end
73
+ @tt = nil
74
+ @csv = nil
75
+ @codes = nil
62
76
  return txt
63
77
  end
64
78
 
79
+ protected
80
+
81
+ def get_text(x,y,color)
82
+ val = @tt.get_cell_text(x,y)
83
+ val = "" if val == nil
84
+ cell = ::Coopy::DiffRender.render_cell(@tt,x,y)
85
+ if color
86
+ code = nil
87
+ code = @codes[cell.category] if cell.category != nil
88
+ if cell.category_given_tr != nil
89
+ code_tr = @codes[cell.category_given_tr]
90
+ code = code_tr if code_tr != nil
91
+ end
92
+ if code != nil
93
+ if cell.rvalue != nil
94
+ val = _hx_str(@codes["remove"]) + _hx_str(cell.lvalue) + _hx_str(@codes["modify"]) + _hx_str(cell.pretty_separator) + _hx_str(@codes["add"]) + _hx_str(cell.rvalue) + _hx_str(@codes["done"])
95
+ val = _hx_str(@codes["conflict"]) + _hx_str(cell.pvalue) + _hx_str(@codes["modify"]) + _hx_str(cell.pretty_separator) + _hx_str(val) if cell.pvalue != nil
96
+ else
97
+ val = cell.pretty_value
98
+ val = _hx_str(code) + _hx_str(val) + _hx_str(@codes["done"])
99
+ end
100
+ end
101
+ else
102
+ val = cell.pretty_value
103
+ end
104
+ return @csv.render_cell(@v,val)
105
+ end
106
+
107
+ def pick_sizes(t)
108
+ w = t.get_width
109
+ h = t.get_height
110
+ v = t.get_cell_view
111
+ tt = ::Coopy::TableText.new(t)
112
+ csv = ::Coopy::Csv.new
113
+ sizes = Array.new
114
+ row = -1
115
+ total = w - 1
116
+ begin
117
+ _g = 0
118
+ while(_g < w)
119
+ x = _g
120
+ _g+=1
121
+ m = 0
122
+ m2 = 0
123
+ mmax = 0
124
+ mmostmax = 0
125
+ mmin = -1
126
+ begin
127
+ _g1 = 0
128
+ while(_g1 < h)
129
+ y = _g1
130
+ _g1+=1
131
+ txt = self.get_text(x,y,false)
132
+ row = y if txt == "@@" && row == -1
133
+ len = txt.length
134
+ mmin = len if y == row
135
+ m += len
136
+ m2 += len * len
137
+ mmax = len if len > mmax
138
+ end
139
+ end
140
+ mean = m / h
141
+ stddev = Math.sqrt(m2 / h - mean * mean)
142
+ most = (mean + stddev * 2 + 0.5).to_i
143
+ begin
144
+ _g11 = 0
145
+ while(_g11 < h)
146
+ y1 = _g11
147
+ _g11+=1
148
+ txt1 = self.get_text(x,y1,false)
149
+ len1 = txt1.length
150
+ if len1 <= most
151
+ mmostmax = len1 if len1 > mmostmax
152
+ end
153
+ end
154
+ end
155
+ full = mmax
156
+ most = mmostmax
157
+ if mmin != -1
158
+ most = mmin if most < mmin
159
+ end
160
+ sizes.push(most)
161
+ total += most
162
+ end
163
+ end
164
+ return nil if total > 130
165
+ return sizes
166
+ end
167
+
65
168
  haxe_me
66
169
  end
67
170
 
data/lib/lib/math.rb ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # This space left blank
5
+
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.2.1
4
+ version: 1.2.3
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-10-28 00:00:00.000000000 Z
13
+ date: 2014-10-30 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Diff and patch tables
16
16
  email:
@@ -62,6 +62,7 @@ files:
62
62
  - lib/lib/coopy/sparse_sheet.rb
63
63
  - lib/lib/coopy/table.rb
64
64
  - lib/lib/coopy/viterbi.rb
65
+ - lib/lib/math.rb
65
66
  - lib/lib/list.rb
66
67
  - lib/lib/sys/io/hx_file.rb
67
68
  - lib/lib/sys/io/file_output.rb
@@ -117,7 +118,7 @@ summary: ! '[![Build Status](https://travis-ci.org/paulfitz/daff.svg?branch=mast
117
118
  for comparing tables that share a common origin, in other words multiple versions
118
119
  of the "same" table. For a live demo, see: > http://paulfitz.github.com/daff/ Install
119
120
  the library for your favorite language: ````sh npm install daff -g # node/javascript
120
- pip3 install daff # python3 gem install daff # ruby composer require paulfitz/daff-php #
121
+ pip install daff # python gem install daff # ruby composer require paulfitz/daff-php #
121
122
  php ```` Other translations are available here: > https://github.com/paulfitz/daff/releases Or
122
123
  use the library to view csv diffs on github via a chrome extension: > https://github.com/theodi/csvhub The
123
124
  diff format used by `daff` is specified here: > http://dataprotocols.org/tabular-diff-format/ This