|
1 | 1 | #!/usr/bin/env lua |
2 | 2 |
|
| 3 | +CONTEXT_LINES = 3 |
3 | 4 | local function diff_u(fn1, fn2) |
4 | 5 | local function open(fn) local f, e = io.open(fn) if not f then print(e) os.exit(1) end return f end |
5 | 6 | local f1, f2, pre, add, del, p1, p2, x, y, h, l1, l2 = open(fn1), open(fn2), {}, {}, {}, 0, 0, 0, 0 |
@@ -50,31 +51,33 @@ local function diff_u(fn1, fn2) |
50 | 51 | end |
51 | 52 | local function diagonal() |
52 | 53 | flush_hunk() |
53 | | - if #pre >= 3 then table.remove(pre, 1) end |
| 54 | + if #pre > CONTEXT_LINES then table.remove(pre, 1) end |
54 | 55 | if p1 > 0 or p2 > 0 then |
55 | 56 | if p1 > 0 and p2 > 0 then |
56 | | - if p1 > 1 or p2 > 1 then table.insert(buf.line, " " .. l2) end |
| 57 | + if p1 > CONTEXT_LINES or p2 > CONTEXT_LINES then table.insert(buf.line, " " .. l2) end |
57 | 58 | p1, p2 = p1 - 1, p2 - 1 |
58 | 59 | elseif p1 > 0 then |
59 | | - if p1 > 1 then table.insert(buf.line, " " .. l1) end |
| 60 | + if p1 > CONTEXT_LINES then table.insert(buf.line, " " .. l1) end |
60 | 61 | p1 = p1 - 1 |
61 | 62 | elseif p2 > 0 then |
62 | | - if p2 > 1 then table.insert(buf.line, " " .. l2) end |
| 63 | + if p2 > CONTEXT_LINES then table.insert(buf.line, " " .. l2) end |
63 | 64 | p2 = p2 - 1 |
64 | | - end |
| 65 | + elseif p2 <= CONTEXT_LINES then table.insert(pre, l2) |
| 66 | + elseif p1 <= CONTEXT_LINES then table.insert(pre, l1) end |
| 67 | + |
65 | 68 | if p1 == 0 or p2 == 0 then flush_buf() table.insert(pre, l2) end |
66 | 69 | else |
67 | 70 | table.insert(pre, l2) |
68 | 71 | end |
69 | 72 | x, y, l1, l2 = x + 1, y + 1, f1:read("*l"), f2:read("*l") |
70 | 73 | end |
71 | 74 | local function right() |
72 | | - flush_pre() p1 = 4 |
| 75 | + flush_pre() p1 = (CONTEXT_LINES * 2) + 1 |
73 | 76 | table.insert(del, l1) |
74 | 77 | x, l1 = x + 1, f1:read("*l") |
75 | 78 | end |
76 | 79 | local function down() |
77 | | - flush_pre() p2 = 4 |
| 80 | + flush_pre() p2 = (CONTEXT_LINES * 2) + 1 |
78 | 81 | table.insert(add, l2) |
79 | 82 | y, l2 = y + 1, f2:read("*l") |
80 | 83 | end |
|
0 commit comments