Skip to content

Commit

Permalink
fixed a couple of small UX glitches and some error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed Jan 30, 2023
1 parent c383d51 commit 3af6fcc
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 86 deletions.
178 changes: 93 additions & 85 deletions tui/diff_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,114 +45,122 @@ func RenderDiff(left, right *tview.TextView, diffView *tview.Flex, change *whatC
} else {
left.Clear()

table := tview.NewTable()
table.SetBorders(false)
table.SetBorderPadding(0, 0, 0, 0)
if change.Context.OriginalLine != nil {

table.SetCell(0, 0, tview.NewTableCell("Original Value").SetTextColor(CYAN_CELL_COLOR))
table.SetCell(0, 1, tview.NewTableCell("Line").SetTextColor(tcell.ColorGrey))
table.SetCell(0, 2, tview.NewTableCell("Column").SetTextColor(tcell.ColorGrey))
table := tview.NewTable()
table.SetBorders(false)
table.SetBorderPadding(0, 0, 0, 0)

if change.NewObject == nil {
switch change.Breaking {
case true:
table.SetCell(0, 3, tview.NewTableCell("Breaking").SetTextColor(tcell.ColorRed))
}
}
table.SetCell(0, 0, tview.NewTableCell("Original Value").SetTextColor(CYAN_CELL_COLOR))
table.SetCell(0, 1, tview.NewTableCell("Line").SetTextColor(tcell.ColorGrey))
table.SetCell(0, 2, tview.NewTableCell("Column").SetTextColor(tcell.ColorGrey))

table.SetCell(1, 0, tview.NewTableCell(change.Original))
table.SetCell(1, 1,
tview.NewTableCell(fmt.Sprint(*change.Context.OriginalLine)).SetAlign(tview.AlignCenter))
table.SetCell(1, 2,
tview.NewTableCell(fmt.Sprint(*change.Context.OriginalColumn)).SetAlign(tview.AlignCenter))

if change.NewObject == nil {
switch change.Breaking {
case true:
table.SetCell(1, 3, tview.NewTableCell("YES!").
SetTextColor(tcell.ColorRed).SetAlign(tview.AlignCenter))
if change.NewObject == nil {
switch change.Breaking {
case true:
table.SetCell(0, 3, tview.NewTableCell("Breaking").SetTextColor(tcell.ColorRed))
}
}

}
y := tview.NewFlex()
y.SetDirection(tview.FlexRow)
y.AddItem(table, 3, 1, false).
AddItem(left, 0, 1, false)
diffView.AddItem(y, 0, 1, false)
if change.Context.OriginalLine != nil && change.Context.OriginalColumn != nil {
table.SetCell(1, 0, tview.NewTableCell(change.Original))
table.SetCell(1, 1,
tview.NewTableCell(fmt.Sprint(*change.Context.OriginalLine)).SetAlign(tview.AlignCenter))
table.SetCell(1, 2,
tview.NewTableCell(fmt.Sprint(*change.Context.OriginalColumn)).SetAlign(tview.AlignCenter))
}

left.SetWrap(false)
data := string(curr.OldData)
parsed := strings.Split(data, "\n")
if change.NewObject == nil {
switch change.Breaking {
case true:
table.SetCell(1, 3, tview.NewTableCell("YES!").
SetTextColor(tcell.ColorRed).SetAlign(tview.AlignCenter))
}

var clipped []string
}
y := tview.NewFlex()
y.SetDirection(tview.FlexRow)
y.AddItem(table, 3, 1, false).
AddItem(left, 0, 1, false)
diffView.AddItem(y, 0, 1, false)

var startLine, currentLine, endLine int
left.SetWrap(false)
data := string(curr.OldData)
parsed := strings.Split(data, "\n")

if *change.Context.OriginalLine > 5 {
clipped = parsed[*change.Context.OriginalLine-5 : *change.Context.OriginalLine+8]
var clipped []string

startLine = *change.Context.OriginalLine - 4
currentLine = startLine
endLine = *change.Context.OriginalLine + 8
var startLine, currentLine, endLine int

for j := range clipped {
if j != 4 {
clipped[j] = fmt.Sprintf("[grey]%s[-:-]", clipped[j])
}
}
if change.Context.OriginalLine != nil && *change.Context.OriginalLine > 5 {
clipped = parsed[*change.Context.OriginalLine-5 : *change.Context.OriginalLine+8]

color := getColorForChange(originalView, changeNumber, startLine, currentLine)
startLine = *change.Context.OriginalLine - 4
currentLine = startLine
endLine = *change.Context.OriginalLine + 8

if !change.Breaking {
clipped[4] = fmt.Sprintf("[%s]%s[-:-]", color, clipped[4])
} else {
clipped[4] = fmt.Sprintf("[%s]%s[-:-]", "red", clipped[4])
}

} else {
startLine = *change.Context.OriginalLine
currentLine = startLine
endLine = *change.Context.OriginalLine + 13

for j := range clipped {
if j != *change.Context.OriginalLine {
clipped[j] = fmt.Sprintf("[%s]%s[-:-]", "grey", clipped[j])
for j := range clipped {
if j != 4 {
clipped[j] = fmt.Sprintf("[grey]%s[-:-]", clipped[j])
}
}
}

color := getColorForChange(originalView, changeNumber, startLine, currentLine)
color := getColorForChange(originalView, changeNumber, startLine, currentLine)

clipped = parsed[0 : *change.Context.OriginalLine+13]
if !change.Breaking {
clipped[4] = fmt.Sprintf("[%s]%s[-:-]", color, clipped[4])
} else {
clipped[4] = fmt.Sprintf("[%s]%s[-:-]", "red", clipped[4])
}

if !change.Breaking {
clipped[*change.Context.OriginalLine] = fmt.Sprintf("[%s]%s[-:-]",
color, clipped[*change.Context.OriginalLine])
} else {
clipped[*change.Context.OriginalLine] = fmt.Sprintf("[%s]%s[-:-]", "red",
clipped[*change.Context.OriginalLine])
if change.Context.OriginalLine != nil {
startLine = *change.Context.OriginalLine
currentLine = startLine
endLine = *change.Context.OriginalLine + 13

for j := range clipped {
if j != *change.Context.OriginalLine {
clipped[j] = fmt.Sprintf("[%s]%s[-:-]", "grey", clipped[j])
}
}

color := getColorForChange(originalView, changeNumber, startLine, currentLine)

clipped = parsed[0 : *change.Context.OriginalLine+13]

if !change.Breaking {
clipped[*change.Context.OriginalLine] = fmt.Sprintf("[%s]%s[-:-]",
color, clipped[*change.Context.OriginalLine])
} else {
clipped[*change.Context.OriginalLine] = fmt.Sprintf("[%s]%s[-:-]", "red",
clipped[*change.Context.OriginalLine])
}
}
}

}

for x := range clipped {
color := getColorForChange(originalView, lineNumber, currentLine, *change.Context.OriginalLine)
if !change.Breaking {
clipped[x] = fmt.Sprintf("%s[%s]%d|[-] %s",
printSpacing(currentLine, endLine), color, currentLine, clipped[x])
} else {
if currentLine != *change.Context.OriginalLine {
clipped[x] = fmt.Sprintf("%s[%s]%d|[-] %s",
printSpacing(currentLine, endLine), color, currentLine, clipped[x])
} else {
clipped[x] = fmt.Sprintf("%s[%s]%d|[-] %s",
printSpacing(currentLine, endLine), "red", currentLine, clipped[x])
if change.Context.OriginalLine != nil {

for x := range clipped {
color := getColorForChange(originalView, lineNumber, currentLine, *change.Context.OriginalLine)
if !change.Breaking {
clipped[x] = fmt.Sprintf("%s[%s]%d|[-] %s",
printSpacing(currentLine, endLine), color, currentLine, clipped[x])
} else {
if currentLine != *change.Context.OriginalLine {
clipped[x] = fmt.Sprintf("%s[%s]%d|[-] %s",
printSpacing(currentLine, endLine), color, currentLine, clipped[x])
} else {
clipped[x] = fmt.Sprintf("%s[%s]%d|[-] %s",
printSpacing(currentLine, endLine), "red", currentLine, clipped[x])
}
}
currentLine++
}
}
currentLine++
}

fmt.Fprintf(left, strings.Join(clipped, "\n"))

fmt.Fprintf(left, strings.Join(clipped, "\n"))
}
}
if change.NewObject == nil {
right.Clear()
Expand Down
2 changes: 1 addition & 1 deletion tui/main_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func BuildApplication(commitHistory []*model.Commit, version string) *tview.Appl

// build a grid to hold all views.
grid := tview.NewGrid().
SetRows(1, 8, 0, 16).
SetRows(1, 8, 12, 0).
SetColumns(0, 60).
SetBorders(true)
grid.SetGap(2, 2)
Expand Down

0 comments on commit 3af6fcc

Please sign in to comment.