out.w70.wrap 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. commit 15bfa564b9db08fb277a343a3d0a01d377800606
  2. Author: Matthew Wang <XXXXXXX@gmail.com>
  3. Date: Thu Jan 31 15:27:17 2013 +0800
  4. 
  5.  Default width is now 80
  6. 
  7. diff --git a/src/cdiff.py b/src/cdiff.py
  8. index 13f725f..bf15ef1 100755
  9. --- a/src/cdiff.py
  10. +++ b/src/cdiff.py
  11. @@ -128,9 +128,7 @@ class Diff(object):
  12. 128  yield self._markup_common(' ' + old[1]) 128  yield self._markup_common(' ' + old[1])
  13. 129  129 
  14. 130  def markup_side_by_side(self, width): 130  def markup_side_by_side(self, width):
  15. 131  """width of 0 means infinite width, None means auto detect. Re 131  """Returns a generator"""
  16.   turns a  
  17. 132  generator  
  18. 133  """  
  19. 134  def _normalize(line): 132  def _normalize(line):
  20. 135  return line.replace('\t', ' ' * 8).replace('\n', '') 133  return line.replace('\t', ' ' * 8).replace('\n', '')
  21. 136  134 
  22. @@ -147,7 +145,8 @@ class Diff(object):
  23. 147  return markup 145  return markup
  24. 148  146 
  25. 149  # Setup line width and number width 147  # Setup line width and number width
  26. 150  if not width: width = 80 148  if width <= 0:
  27.   149  width = 80
  28. 151  (start, offset) = self._hunks[-1].get_old_addr() 150  (start, offset) = self._hunks[-1].get_old_addr()
  29. 152  max1 = start + offset - 1 151  max1 = start + offset - 1
  30. 153  (start, offset) = self._hunks[-1].get_new_addr() 152  (start, offset) = self._hunks[-1].get_new_addr()
  31. @@ -430,13 +429,10 @@ if __name__ == '__main__':
  32. 430  parser = optparse.OptionParser(usage) 429  parser = optparse.OptionParser(usage)
  33. 431  parser.add_option('-s', '--side-by-side', action='store_true', 430  parser.add_option('-s', '--side-by-side', action='store_true',
  34. 432  help=('show in side-by-side mode')) 431  help=('show in side-by-side mode'))
  35. 433  parser.add_option('-w', '--width', type='int', default=None, 432  parser.add_option('-w', '--width', type='int', default=80,
  36. 434  help='set line width (side-by-side mode only)') 433  help='set line width (side-by-side mode only), default is 
  37.     80')
  38. 435  opts, args = parser.parse_args() 434  opts, args = parser.parse_args()
  39. 436   
  40. 437  if opts.width and opts.width < 0:  
  41. 438  opts.width = 0  
  42. 439  435 
  43. 440  if len(args) >= 1: 436  if len(args) >= 1:
  44. 441  diff_hdl = open(args[0], 'r') 437  diff_hdl = open(args[0], 'r')
  45. 442  elif sys.stdin.isatty(): 438  elif sys.stdin.isatty():