Documentation ¶
Index ¶
- type AddRemTags
- type CRender
- func (r *CRender) Clone() RenderBuilder
- func (r *CRender) Make() Renderer
- func (r *CRender) RenderDiff(unified string) (markup string)
- func (r *CRender) RenderLine(a, b string) (ma, mb string)
- func (r *CRender) SetComment(open, close string) RenderBuilder
- func (r *CRender) SetFile(open, close string) RenderBuilder
- func (r *CRender) SetLineAdded(open, close string) RenderBuilder
- func (r *CRender) SetLineRemoved(open, close string) RenderBuilder
- func (r *CRender) SetNormal(open, close string) RenderBuilder
- func (r *CRender) SetTextAdded(open, close string) RenderBuilder
- func (r *CRender) SetTextRemoved(open, close string) RenderBuilder
- type Diff
- func (d *Diff) EditGroup(index int) (unified string)
- func (d *Diff) EditGroupsLen() (count int)
- func (d *Diff) GetEdit(index int) (text string, ok bool)
- func (d *Diff) KeepAll()
- func (d *Diff) KeepEdit(index int) (ok bool)
- func (d *Diff) KeepGroup(index int)
- func (d *Diff) KeepLen() (count int)
- func (d *Diff) Len() (length int)
- func (d *Diff) ModifiedEdits() (modified string, err error)
- func (d *Diff) SetEdit(index int, text string) (ok bool)
- func (d *Diff) SkipAll()
- func (d *Diff) SkipEdit(index int) (ok bool)
- func (d *Diff) SkipGroup(index int)
- func (d *Diff) Unified() (unified string, err error)
- func (d *Diff) UnifiedEdit(index int) (unified string)
- func (d *Diff) UnifiedEdits() (unified string)
- type MarkupTag
- type RenderBuilder
- type Renderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddRemTags ¶
type CRender ¶
type CRender struct { File MarkupTag Normal MarkupTag Comment MarkupTag Line AddRemTags Text AddRemTags }
CRender implements the RenderBuilder and Renderer interfaces
func (*CRender) Clone ¶
func (r *CRender) Clone() RenderBuilder
func (*CRender) RenderDiff ¶
func (*CRender) RenderLine ¶
func (*CRender) SetComment ¶
func (r *CRender) SetComment(open, close string) RenderBuilder
func (*CRender) SetFile ¶
func (r *CRender) SetFile(open, close string) RenderBuilder
func (*CRender) SetLineAdded ¶
func (r *CRender) SetLineAdded(open, close string) RenderBuilder
func (*CRender) SetLineRemoved ¶
func (r *CRender) SetLineRemoved(open, close string) RenderBuilder
func (*CRender) SetNormal ¶
func (r *CRender) SetNormal(open, close string) RenderBuilder
func (*CRender) SetTextAdded ¶
func (r *CRender) SetTextAdded(open, close string) RenderBuilder
func (*CRender) SetTextRemoved ¶
func (r *CRender) SetTextRemoved(open, close string) RenderBuilder
type Diff ¶
type Diff struct {
// contains filtered or unexported fields
}
func New ¶
New constructs a new Diff instance with the given source and changed strings computed into a set of "edits" which can be selectively included in the Diff.UnifiedEdits and Diff.ModifiedEdits outputs
func (*Diff) EditGroupsLen ¶
EditGroupsLen returns the count of edit groups present
func (*Diff) KeepAll ¶
func (d *Diff) KeepAll()
KeepAll flags all edits to be included in the UnifiedEdits and ModifiedEdits output
func (*Diff) KeepEdit ¶
KeepEdit flags a particular edit to be included in the UnifiedEdits() and ModifiedEdits() output
func (*Diff) KeepGroup ¶
KeepGroup flags the given group index for including in the UnifiedEdits and ModifiedEdits outputs
func (*Diff) KeepLen ¶
KeepLen returns the total number of edits flagged to be included in the UnifiedEdits and ModifiedEdits output
func (*Diff) ModifiedEdits ¶
ModifiedEdits returns the source content modified by only kept edits
func (*Diff) SkipAll ¶
func (d *Diff) SkipAll()
SkipAll flags all edits to be excluded in the UnifiedEdits() and ModifiedEdits() output
func (*Diff) SkipEdit ¶
SkipEdit flags a particular edit to be excluded in the UnifiedEdits() output
func (*Diff) SkipGroup ¶
SkipGroup flags the given group index for exclusion from the UnifiedEdits and ModifiedEdits outputs
func (*Diff) UnifiedEdit ¶
UnifiedEdit returns the unified diff output for just the given edit
func (*Diff) UnifiedEdits ¶
UnifiedEdits returns the unified diff output for all kept edits
type RenderBuilder ¶
type RenderBuilder interface { // SetFile specifies the markup wrapping the entire unified diff SetFile(open, close string) RenderBuilder // SetNormal specifies the markup wrapping each normal line of unified diff SetNormal(open, close string) RenderBuilder // SetComment specifies the markup wrapping comment lines (starting with a backslash `\` or a hash `#`) SetComment(open, close string) RenderBuilder // SetLineAdded specifies the markup wrapping lines that were added SetLineAdded(open, close string) RenderBuilder // SetTextAdded specifies the markup wrapping additions within a line SetTextAdded(open, close string) RenderBuilder // SetLineRemoved specifies the markup wrapping lines that were removed SetLineRemoved(open, close string) RenderBuilder // SetTextRemoved specifies the markup wrapping removals within a line SetTextRemoved(open, close string) RenderBuilder // Make returns the built Renderer instance Make() Renderer }
RenderBuilder is the buildable interface for constructing new Renderer instances
func NewRenderer ¶
func NewRenderer() (tb RenderBuilder)
NewRenderer returns a new RenderBuilder instance
type Renderer ¶
type Renderer interface { // RenderLine compares to single-line strings and highlights the differences // with the CRender.Text markup strings RenderLine(a, b string) (ma, mb string) // RenderDiff parses a unified diff string and highlights the interesting // details using the CRender.Line, CRender.Comment and CRender.Normal // markup strings RenderDiff(unified string) (markup string) // Clone returns a new RenderBuilder instance configured exactly the same // as the one the Clone method is called upon Clone() RenderBuilder }
Renderer is the interface used to actual render unified diff content
var ( // TangoRender is a Renderer preset for the go-curses Tango markup // format used in the ctk.Label and other widgets TangoRender Renderer = &CRender{ Line: AddRemTags{ Add: MarkupTag{ Open: `<span foreground="#ffffff" background="#007700">`, Close: `</span>`, }, Rem: MarkupTag{ Open: `<span foreground="#eeeeee" background="#770000">`, Close: `</span>`, }, }, Text: AddRemTags{ Add: MarkupTag{ Open: `<span background="#004400" weight="bold">`, Close: `</span>`, }, Rem: MarkupTag{ Open: `<span background="#440000" weight="dim" strikethrough="true">`, Close: `</span>`, }, }, Normal: MarkupTag{ Open: `<span weight="dim">`, Close: `</span>`, }, Comment: MarkupTag{ Open: `<span style="italic" weight="dim">`, Close: `</span>`, }, } // HTMLRender is a Renderer preset for browser presentation HTMLRender Renderer = &CRender{ File: MarkupTag{ Open: `<ul style="list-style-type:none;margin:0;padding:0;">` + "\n", Close: `</ul>`, }, Normal: MarkupTag{ Open: `<li style="opacity:0.77;">`, Close: `</li>`, }, Comment: MarkupTag{ Open: `<li style="font-style:italic;opacity:0.77;">`, Close: `</li>`, }, Line: AddRemTags{ Add: MarkupTag{ Open: `<li style="color:#ffffff;background-color:#007700;">`, Close: `</li>`, }, Rem: MarkupTag{ Open: `<li style="color:#eeeeee;background-color:#770000;">`, Close: `</li>`, }, }, Text: AddRemTags{ Add: MarkupTag{ Open: `<span style="background-color:#004400;font-weight:bold;">`, Close: `</span>`, }, Rem: MarkupTag{ Open: `<span style="background-color:#440000;opacity:0.77;text-decoration:line-through;">`, Close: `</span>`, }, }, } )