Skip to content

Commit

Permalink
Clean-up diff box.
Browse files Browse the repository at this point in the history
  • Loading branch information
udhos committed Feb 23, 2017
1 parent 0198f4b commit c75b2f0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ install:
- go get github.com/icza/gowut/gwu
- go get github.com/udhos/lockfile
- go get github.com/udhos/equalfile
- go get github.com/udhos/difflib
- go get gopkg.in/yaml.v2
- go get golang.org/x/crypto/ssh
- go get github.com/aws/aws-sdk-go/aws
Expand Down
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ if [ -z "$JAZIGO_S3_FOLDER" ]; then
echo >&2 JAZIGO_S3_FOLDER undefined -- for S3 testing, set JAZIGO_S3_FOLDER=bucket/folder
fi
go test github.com/udhos/jazigo/store

msg test jazigo
go test github.com/udhos/jazigo/jazigo
61 changes: 38 additions & 23 deletions jazigo/web_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ func deviceWinName(id string) string {
return "device-" + id
}

func splitBufLines(b []byte) []string {
list := strings.Split(string(b), "\n")
last := len(list) - 1
if last < 0 {
return list
}
if list[last] == "" {
return list[:last]
}
return list
}

func buildDeviceWindow(jaz *app, e gwu.Event, devID string) string {
winName := deviceWinName(devID)
s := e.Session()
Expand Down Expand Up @@ -246,45 +258,48 @@ func buildDeviceWindow(jaz *app, e gwu.Event, devID string) string {
diffPanel.Add(gwu.NewLabel(fmt.Sprintf("Could not read '%s': %v", from, errReadTo)))
}

seqFrom := strings.Split(string(bufFrom), "\n")
seqTo := strings.Split(string(bufTo), "\n")
seqFrom := splitBufLines(bufFrom)
seqTo := splitBufLines(bufTo)
diff := difflib.Diff(seqFrom, seqTo)

diffBox := gwu.NewTable()
diffBox.Style().AddClass("diffbox")

colLineNumFrom := 0
colLineTextFrom := 1
colLineTextTo := 2
colLineNumTo := 3

var f, t int

for _, d := range diff {

switch d.Delta {
case difflib.LeftOnly:
diffBox.Add(gwu.NewLabel(strconv.Itoa(f+1)), f, 0)
diffBox.CellFmt(f, 0).Style().AddClass("diffbox_linenum")

diffBox.Add(gwu.NewLabel(strconv.Itoa(f+1)), f, colLineNumFrom)
diffBox.CellFmt(f, colLineNumFrom).Style().AddClass("diffbox_linenum")
lab := gwu.NewLabel(d.Payload)
lab.Style().AddClass("diffbox_deleted")
lab.Style().AddClass("diffbox_text_cell")
diffBox.Add(lab, f, 1)
diffBox.Add(lab, f, colLineTextFrom)
diffBox.CellFmt(f, colLineTextFrom).Style().AddClass("diffbox_deleted")
diffBox.CellFmt(f, colLineTextFrom).Style().AddClass("diffbox_text_cell")
f++
case difflib.RightOnly:
diffBox.Add(gwu.NewLabel(strconv.Itoa(t+1)), t, 3)
diffBox.CellFmt(t, 3).Style().AddClass("diffbox_linenum")

diffBox.Add(gwu.NewLabel(strconv.Itoa(t+1)), t, colLineNumTo)
diffBox.CellFmt(t, colLineNumTo).Style().AddClass("diffbox_linenum")
lab := gwu.NewLabel(d.Payload)
lab.Style().AddClass("diffbox_added")
lab.Style().AddClass("diffbox_text_cell")
diffBox.Add(lab, t, 2)
diffBox.Add(lab, t, colLineTextTo)
diffBox.CellFmt(t, colLineTextTo).Style().AddClass("diffbox_added")
diffBox.CellFmt(t, colLineTextTo).Style().AddClass("diffbox_text_cell")
t++
case difflib.Common:
diffBox.Add(gwu.NewLabel(strconv.Itoa(f+1)), f, 0)
diffBox.CellFmt(f, 0).Style().AddClass("diffbox_linenum")
diffBox.Add(gwu.NewLabel(strconv.Itoa(t+1)), t, 3)
diffBox.CellFmt(t, 3).Style().AddClass("diffbox_linenum")

diffBox.Add(gwu.NewLabel(d.Payload), f, 1)
diffBox.Add(gwu.NewLabel(d.Payload), t, 2)
diffBox.CellFmt(f, 1).Style().AddClass("diffbox_text_cell")
diffBox.CellFmt(t, 2).Style().AddClass("diffbox_text_cell")
diffBox.Add(gwu.NewLabel(strconv.Itoa(f+1)), f, colLineNumFrom)
diffBox.CellFmt(f, colLineNumFrom).Style().AddClass("diffbox_linenum")
diffBox.Add(gwu.NewLabel(strconv.Itoa(t+1)), t, colLineNumTo)
diffBox.CellFmt(t, colLineNumTo).Style().AddClass("diffbox_linenum")
diffBox.Add(gwu.NewLabel(d.Payload), f, colLineTextFrom)
diffBox.Add(gwu.NewLabel(d.Payload), t, colLineTextTo)
diffBox.CellFmt(f, colLineTextFrom).Style().AddClass("diffbox_text_cell")
diffBox.CellFmt(t, colLineTextTo).Style().AddClass("diffbox_text_cell")
f++
t++
}
Expand Down
7 changes: 7 additions & 0 deletions www/jazigo.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@
border: 1px solid blue;
}

.diffbox {
border: 2px solid gray;
padding: 2px;
}

.diffbox_linenum {
border: 1px solid blue;
}

.diffbox_text_cell {
font-family: Courier;
border-spacing: 0.5rem;
}

.diffbox_added {
Expand Down

0 comments on commit c75b2f0

Please sign in to comment.