Skip to content

Commit

Permalink
cleanup: refactor goToRow functionality into its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
avamsi committed Sep 11, 2023
1 parent cf91ff6 commit d287f8d
Showing 1 changed file with 22 additions and 49 deletions.
71 changes: 22 additions & 49 deletions viddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,81 +628,54 @@ func (v *Viddy) Run() error {
return app.Run()
}

func (v *Viddy) goToRow(row int) {
if row < 0 {
row = 0
} else if count := v.historyView.GetRowCount(); row >= count {
row = count - 1
}
var (
cell = v.historyView.GetCell(row, 0)
id, err = strconv.ParseInt(cell.Text, 10, 64)
)
if err == nil { // if _no_ error
v.setSelection(id)
}
}

func (v *Viddy) goToPastOnTimeMachine() {
count := v.historyView.GetRowCount()
selection, _ := v.historyView.GetSelection()

if selection+1 < count {
cell := v.historyView.GetCell(selection+1, 0)
if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil {
v.setSelection(id)
}
}
v.goToRow(selection + 1)
}

func (v *Viddy) goToFutureOnTimeMachine() {
selection, _ := v.historyView.GetSelection()
if 0 <= selection-1 {
cell := v.historyView.GetCell(selection-1, 0)
if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil {
v.setSelection(id)
}
}
v.goToRow(selection - 1)
}

func (v *Viddy) goToMorePastOnTimeMachine() {
count := v.historyView.GetRowCount()
selection, _ := v.historyView.GetSelection()

if selection+10 < count {
cell := v.historyView.GetCell(selection+10, 0)
if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil {
v.setSelection(id)
}
} else {
cell := v.historyView.GetCell(count-1, 0)
if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil {
v.setSelection(id)
}
}
v.goToRow(selection + 10)
}

func (v *Viddy) goToMoreFutureOnTimeMachine() {
selection, _ := v.historyView.GetSelection()
if 0 <= selection-10 {
cell := v.historyView.GetCell(selection-10, 0)
if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil {
v.setSelection(id)
}
} else {
cell := v.historyView.GetCell(0, 0)
if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil {
v.setSelection(id)
}
}
v.goToRow(selection - 10)
}

func (v *Viddy) goToNowOnTimeMachine() {
cell := v.historyView.GetCell(0, 0)
if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil {
v.setSelection(id)
}
v.goToRow(0)
}

func (v *Viddy) goToOldestOnTimeMachine() {
count := v.historyView.GetRowCount()
cell := v.historyView.GetCell(count-1, 0)

if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil {
v.setSelection(id)
}
v.goToRow(v.historyView.GetRowCount() - 1)
}

var helpTemplate = `Press ESC or q to go back
[::b]Key Bindings[-:-:-]
[::u]General[-:-:-]
[::u]General[-:-:-]
Toggle time machine mode : [yellow]SPACE[-:-:-]
Toggle suspend execution : [yellow]s[-:-:-]
Expand Down

0 comments on commit d287f8d

Please sign in to comment.