Class: Coopy::TerminalDiffRender
- Inherits:
-
Object
- Object
- Coopy::TerminalDiffRender
- Defined in:
- lib/lib/coopy/terminal_diff_render.rb
Instance Method Summary collapse
-
#initialize ⇒ TerminalDiffRender
constructor
A new instance of TerminalDiffRender.
- #render(t) ⇒ Object
Constructor Details
#initialize ⇒ TerminalDiffRender
Returns a new instance of TerminalDiffRender.
7 8 |
# File 'lib/lib/coopy/terminal_diff_render.rb', line 7 def initialize end |
Instance Method Details
#render(t) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lib/coopy/terminal_diff_render.rb', line 10 def render(t) csv = ::Coopy::Csv.new result = "" w = t.get_width h = t.get_height txt = "" v = t.get_cell_view tt = ::Coopy::TableText.new(t) codes = {} codes["header"] = "\x1B[0;1m" codes["add"] = "\x1B[32;1m" codes["conflict"] = "\x1B[33;1m" codes["modify"] = "\x1B[34;1m" codes["remove"] = "\x1B[31;1m" codes["done"] = "\x1B[0m" begin _g = 0 while(_g < h) y = _g _g+=1 begin _g1 = 0 while(_g1 < w) x = _g1 _g1+=1 txt += "," if x > 0 val = tt.get_cell_text(x,y) val = "" if val == nil cell = ::Coopy::DiffRender.render_cell(tt,x,y) code = nil code = codes[cell.category] if cell.category != nil if code != nil if cell.rvalue != nil 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"]) val = _hx_str(codes["conflict"]) + _hx_str(cell.pvalue) + _hx_str(codes["modify"]) + _hx_str(cell.separator) + _hx_str(val) if cell.pvalue != nil else val = _hx_str(code) + _hx_str(val) + _hx_str(codes["done"]) end end txt += csv.render_cell(v,val) end end txt += "\r\n" end end return txt end |