docdiff 0.6.7 → 0.7.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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +69 -36
  3. data/README_ja.md +70 -37
  4. data/doc/example/docdiff.conf.example +3 -0
  5. data/doc/img/screenshot-html.png +0 -0
  6. data/doc/img/screenshot-tty-char.png +0 -0
  7. data/doc/img/screenshot-tty-digest-block.png +0 -0
  8. data/doc/img/screenshot-tty-digest-license-block.png +0 -0
  9. data/doc/img/screenshot-tty-digest-license.png +0 -0
  10. data/doc/img/screenshot-tty-digest.png +0 -0
  11. data/doc/img/screenshot-tty-en-ja.png +0 -0
  12. data/doc/img/screenshot-tty-manued.png +0 -0
  13. data/doc/img/screenshot-tty-wdiff.png +0 -0
  14. data/doc/img/screenshot-tty-word-char.png +0 -0
  15. data/doc/man/docdiff.adoc +3 -3
  16. data/doc/news.md +11 -0
  17. data/docdiff.gemspec +1 -1
  18. data/lib/doc_diff.rb +5 -5
  19. data/lib/docdiff/charstring.rb +36 -40
  20. data/lib/docdiff/cli.rb +23 -10
  21. data/lib/docdiff/document.rb +44 -44
  22. data/lib/docdiff/encoding/en_ascii.rb +4 -4
  23. data/lib/docdiff/version.rb +1 -1
  24. data/lib/docdiff/view.rb +27 -13
  25. data/test/charstring_test.rb +221 -221
  26. data/test/cli_test.rb +12 -12
  27. data/test/document_test.rb +223 -223
  28. data/test/fixture/humpty_dumpty_01_en.txt +4 -0
  29. data/test/fixture/humpty_dumpty_01_ja.txt +4 -0
  30. data/test/fixture/{humpty_dumpty01_ascii_lf.txt → humpty_dumpty_02_en.txt} +2 -2
  31. data/test/fixture/humpty_dumpty_02_ja.txt +4 -0
  32. data/test/view_test.rb +38 -31
  33. metadata +26 -14
  34. data/test/fixture/humpty_dumpty02_ascii_lf.txt +0 -4
  35. /data/doc/img/{screenshot-format-html-digest-firefox.png → old/screenshot-format-html-digest-firefox.png} +0 -0
  36. /data/doc/img/{screenshot-format-html-firefox.png → old/screenshot-format-html-firefox.png} +0 -0
  37. /data/doc/img/{screenshot-format-tty-cmdexe-en.png → old/screenshot-format-tty-cmdexe-en.png} +0 -0
  38. /data/doc/img/{screenshot-format-tty-cmdexe-ja.png → old/screenshot-format-tty-cmdexe-ja.png} +0 -0
  39. /data/doc/img/{screenshot-format-tty-rxvtunicode-en.png → old/screenshot-format-tty-rxvtunicode-en.png} +0 -0
  40. /data/doc/img/{screenshot-format-tty-rxvtunicode-ja.png → old/screenshot-format-tty-rxvtunicode-ja.png} +0 -0
  41. /data/doc/img/{screenshot-format-tty-xterm-en.png → old/screenshot-format-tty-xterm-en.png} +0 -0
  42. /data/doc/img/{screenshot-format-tty-xterm-ja.png → old/screenshot-format-tty-xterm-ja.png} +0 -0
  43. /data/doc/img/{screenshot-resolution-linewordchar-xterm.png → old/screenshot-resolution-linewordchar-xterm.png} +0 -0
data/lib/docdiff/cli.rb CHANGED
@@ -7,6 +7,12 @@ class DocDiff
7
7
  o = base_options.dup
8
8
 
9
9
  option_parser = OptionParser.new do |parser|
10
+ parser.summary_width = 20
11
+ parser.summary_indent = " "
12
+
13
+ parser.banner =
14
+ "#{File.basename($PROGRAM_NAME)} [options] file1 file2"
15
+
10
16
  parser.on(
11
17
  "--resolution=RESOLUTION",
12
18
  resolutions = ["line", "word", "char"],
@@ -54,8 +60,9 @@ class DocDiff
54
60
  "--format=FORMAT",
55
61
  formats = ["tty", "manued", "html", "wdiff", "stat", "user"],
56
62
  "specify output format",
57
- "#{formats.join("|")} (default: html) (stat is deprecated)",
58
- "(user tags can be defined in config file)",
63
+ "#{formats.join("|")} (default: tty)",
64
+ "(stat is deprecated)",
65
+ "(user tags can be defined in configuration file)",
59
66
  ) { |s| o[:format] = (s || "manued") }
60
67
  parser.on("--tty", "same as --format=tty") { o[:format] = "tty" }
61
68
  parser.on("--manued", "same as --format=manued") { o[:format] = "manued" }
@@ -66,7 +73,8 @@ class DocDiff
66
73
  parser.on(
67
74
  "--label LABEL",
68
75
  "-L LABEL",
69
- "use label instead of file name (not implemented; exists for compatibility with diff)",
76
+ "use label instead of file name",
77
+ "(not implemented; exists for compatibility with diff)",
70
78
  ) do |s|
71
79
  o[:label] ||= []
72
80
  o[:label] << s
@@ -78,22 +86,24 @@ class DocDiff
78
86
  parser.on(
79
87
  "--display=DISPLAY",
80
88
  display_types = ["inline", "block", "multi"],
81
- "specify presentation type (effective only with digest; experimental feature)",
82
- "#{display_types.join("|")} (default: inline) (multi is deprecated)",
89
+ "specify presentation type (effective only with digest)",
90
+ "#{display_types.join("|")} (default: inline)",
91
+ "(experimental feature) (multi is deprecated)",
83
92
  ) { |s| o[:display] ||= s.downcase }
84
93
 
85
94
  parser.on("--cache", "use file cache (not implemented) (deprecated)") { o[:cache] = true }
86
95
  parser.on(
87
96
  "--pager=PAGER",
88
97
  String,
89
- "specify pager (if available, $DOCDIFF_PAGER is used by default)",
98
+ "specify pager",
99
+ "(falls back to $DOCDIFF_PAGER, $PAGER, or none)",
90
100
  ) { |s| o[:pager] = s }
91
101
  parser.on("--no-pager", "do not use pager") { o[:pager] = false }
92
- parser.on("--config-file=FILE", String, "specify config file to read") { |s| o[:config_file] = s }
93
- parser.on("--no-config-file", "do not read config files") { o[:no_config_file] = true }
102
+ parser.on("--config-file=FILE", String, "specify configuration file to read") { |s| o[:config_file] = s }
103
+ parser.on("--no-config-file", "do not read configuration files") { o[:no_config_file] = true }
94
104
  parser.on("--verbose", "run verbosely (not well-supported) (deprecated)") { o[:verbose] = true }
95
105
 
96
- parser.on("--help", "show this message") do
106
+ parser.on("--help", "show help message") do
97
107
  puts parser
98
108
  exit(0)
99
109
  end
@@ -112,7 +122,8 @@ class DocDiff
112
122
 
113
123
  parser.on_tail(
114
124
  "When invoked as worddiff or chardiff, resolution will be set accordingly.",
115
- "Config files: /etc/docdiff/docdiff.conf, ~/.config/docdiff/docdiff.conf (or ~/etc/docdiff/docdiff.conf (deprecated))",
125
+ "Configuration files: /etc/docdiff/docdiff.conf, ~/.config/docdiff/docdiff.conf, ",
126
+ "or ~/etc/docdiff/docdiff.conf (deprecated)",
116
127
  )
117
128
  end
118
129
 
@@ -246,6 +257,8 @@ class DocDiff
246
257
  config_from_env_vars = {}
247
258
  if (pager = ENV["DOCDIFF_PAGER"]) && !pager.empty?
248
259
  config_from_env_vars[:pager] = pager
260
+ elsif (pager = ENV["PAGER"]) && !pager.empty?
261
+ config_from_env_vars[:pager] = pager
249
262
  end
250
263
 
251
264
  config_in_effect = DocDiff::DEFAULT_CONFIG.dup
@@ -54,92 +54,92 @@ class DocDiff
54
54
  @body.eol = eolstr
55
55
  end
56
56
 
57
- def split_to_line
58
- @body.split_to_line
57
+ def to_lines
58
+ @body.to_lines
59
59
  end
60
60
 
61
- def split_to_word
62
- @body.split_to_word
61
+ def to_words
62
+ @body.to_words
63
63
  end
64
64
 
65
- def split_to_char
66
- @body.split_to_char
65
+ def to_chars
66
+ @body.to_chars
67
67
  end
68
68
 
69
- def split_to_byte
70
- @body.split_to_byte
69
+ def to_bytes
70
+ @body.to_bytes
71
71
  end
72
72
 
73
- def count_line
74
- @body.count_line
73
+ def count_lines
74
+ @body.count_lines
75
75
  end
76
76
 
77
- def count_blank_line
78
- @body.count_blank_line
77
+ def count_blank_lines
78
+ @body.count_blank_lines
79
79
  end
80
80
 
81
- def count_empty_line
82
- @body.count_empty_line
81
+ def count_empty_lines
82
+ @body.count_empty_lines
83
83
  end
84
84
 
85
- def count_graph_line
86
- @body.count_graph_line
85
+ def count_graph_lines
86
+ @body.count_graph_lines
87
87
  end
88
88
 
89
- def count_word
90
- @body.count_word
89
+ def count_words
90
+ @body.count_words
91
91
  end
92
92
 
93
- def count_latin_word
94
- @body.count_latin_word
93
+ def count_latin_words
94
+ @body.count_latin_words
95
95
  end
96
96
 
97
- def count_ja_word
98
- @body.count_ja_word
97
+ def count_ja_words
98
+ @body.count_ja_words
99
99
  end
100
100
 
101
- def count_valid_word
102
- @body.count_valid_word
101
+ def count_valid_words
102
+ @body.count_valid_words
103
103
  end
104
104
 
105
- def count_latin_valid_word
106
- @body.count_latin_valid_word
105
+ def count_latin_valid_words
106
+ @body.count_latin_valid_words
107
107
  end
108
108
 
109
- def count_ja_valid_word
110
- @body.count_ja_valid_word
109
+ def count_ja_valid_words
110
+ @body.count_ja_valid_words
111
111
  end
112
112
 
113
- def count_char
114
- @body.count_char
113
+ def count_chars
114
+ @body.count_chars
115
115
  end
116
116
 
117
- def count_blank_char
118
- @body.count_blank_char
117
+ def count_blank_chars
118
+ @body.count_blank_chars
119
119
  end
120
120
 
121
- def count_graph_char
122
- @body.count_graph_char
121
+ def count_graph_chars
122
+ @body.count_graph_chars
123
123
  end
124
124
 
125
- def count_latin_blank_char
126
- @body.count_latin_blank_char
125
+ def count_latin_blank_chars
126
+ @body.count_latin_blank_chars
127
127
  end
128
128
 
129
- def count_latin_graph_char
130
- @body.count_latin_graph_char
129
+ def count_latin_graph_chars
130
+ @body.count_latin_graph_chars
131
131
  end
132
132
 
133
- def count_ja_blank_char
134
- @body.count_ja_blank_char
133
+ def count_ja_blank_chars
134
+ @body.count_ja_blank_chars
135
135
  end
136
136
 
137
- def count_ja_graph_char
138
- @body.count_ja_graph_char
137
+ def count_ja_graph_chars
138
+ @body.count_ja_graph_chars
139
139
  end
140
140
 
141
- def count_byte
142
- @body.count_byte
141
+ def count_bytes
142
+ @body.count_bytes
143
143
  end
144
144
 
145
145
  def eol_char
@@ -53,22 +53,22 @@ class DocDiff
53
53
  ].join
54
54
 
55
55
  # override default method, as ASCII has no Japanese in it
56
- def count_ja_graph_char
56
+ def count_ja_graph_chars
57
57
  0
58
58
  end
59
59
 
60
60
  # override default method, as ASCII has no Japanese in it
61
- def count_ja_blank_char
61
+ def count_ja_blank_chars
62
62
  0
63
63
  end
64
64
 
65
65
  # override default method, as ASCII has no Japanese in it
66
- def count_ja_word
66
+ def count_ja_words
67
67
  0
68
68
  end
69
69
 
70
70
  # override default method, as ASCII has no Japanese in it
71
- def count_ja_valid_word
71
+ def count_ja_valid_words
72
72
  0
73
73
  end
74
74
 
@@ -1,3 +1,3 @@
1
1
  module Docdiff
2
- VERSION = "0.6.7"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/docdiff/view.rb CHANGED
@@ -107,6 +107,20 @@ class DocDiff
107
107
  nil
108
108
  end
109
109
 
110
+ def format_line_number(n1, n2 = nil, paren: false)
111
+ content =
112
+ if n2
113
+ "LL#{n1}-#{n2}"
114
+ else
115
+ "L#{n1}"
116
+ end
117
+ if paren
118
+ "(#{content})"
119
+ else
120
+ content
121
+ end
122
+ end
123
+
110
124
  CONTEXT_PRE_LENGTH = 32
111
125
  CONTEXT_POST_LENGTH = 32
112
126
  def apply_style_digest(tags, headfoot = true)
@@ -180,17 +194,17 @@ class DocDiff
180
194
  when :change_elt
181
195
  range1 =
182
196
  if span1 > 1
183
- "#{d1l}-#{d1l + span1 - 1}"
197
+ format_line_number(d1l, (d2l + span1 - 1))
184
198
  else
185
- d1l.to_s
199
+ format_line_number(d1l)
186
200
  end
187
201
  range2 =
188
202
  if span2 > 1
189
- "#{d2l}-#{d2l + span2 - 1}"
203
+ format_line_number(d2l, (d2l + span2 - 1))
190
204
  else
191
- d2l.to_s
205
+ format_line_number(d2l)
192
206
  end
193
- pos_str = "#{range1},#{range2}"
207
+ pos_str = "#{range1}, #{range2}"
194
208
  case display
195
209
  when "inline"
196
210
  result << (e_head.call(pos_str) + e_cxt_pre + e_chg + e_cxt_post + e_foot)
@@ -202,13 +216,13 @@ class DocDiff
202
216
  when :del_elt
203
217
  range1 =
204
218
  if span1 > 1
205
- "#{d1l}-#{d1l + span1 - 1}"
219
+ format_line_number(d1l, (d1l + span1 - 1))
206
220
  else
207
- d1l.to_s
221
+ format_line_number(d1l)
208
222
  end
209
223
  range2 =
210
- "(#{d2l})"
211
- pos_str = "#{range1},#{range2}"
224
+ format_line_number(d2l, paren: true)
225
+ pos_str = "#{range1}, #{range2}"
212
226
  case display
213
227
  when "inline"
214
228
  result << (e_head.call(pos_str) + e_cxt_pre + e_del + e_cxt_post + e_foot)
@@ -219,14 +233,14 @@ class DocDiff
219
233
  end
220
234
  when :add_elt
221
235
  range1 =
222
- "(#{d1l})"
236
+ format_line_number(d1l, paren: true)
223
237
  range2 =
224
238
  if span2 > 1
225
- "#{d2l}-#{d2l + span2 - 1}"
239
+ format_line_number(d2l, (d2l + span2 - 1))
226
240
  else
227
- d2l.to_s
241
+ format_line_number(d2l)
228
242
  end
229
- pos_str = "#{range1},#{range2}"
243
+ pos_str = "#{range1}, #{range2}"
230
244
  case display
231
245
  when "inline"
232
246
  result << (e_head.call(pos_str) + e_cxt_pre + e_add + e_cxt_post + e_foot)