1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Handle cases in which there is no git repo data

This commit is contained in:
Chris Cummer 2018-04-18 11:43:30 -07:00
parent f1a2f65bf1
commit 9ec1b516c1
2 changed files with 13 additions and 2 deletions

View File

@ -10,6 +10,10 @@ func (widget *Widget) display() {
widget.View.Clear() widget.View.Clear()
repoData := widget.currentData() repoData := widget.currentData()
if repoData == nil {
fmt.Fprintf(widget.View, "%s", " Git repo data is unavailable (1)")
return
}
title := fmt.Sprintf("[green]%s[white]\n", repoData.Repository) title := fmt.Sprintf("[green]%s[white]\n", repoData.Repository)
widget.View.SetTitle(fmt.Sprintf(" Git: %s ", title)) widget.View.SetTitle(fmt.Sprintf(" Git: %s ", title))

View File

@ -5,7 +5,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/olebedev/config" "github.com/olebedev/config"
"github.com/senorprogrammer/wtf/wtf" "github.com/senorprogrammer/wtf/wtf"
@ -78,6 +77,14 @@ func (widget *Widget) Prev() {
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
func (widget *Widget) currentData() *GitRepo { func (widget *Widget) currentData() *GitRepo {
if len(widget.Data) == 0 {
return nil
}
if widget.Idx < 0 || widget.Idx >= len(widget.Data) {
return nil
}
return widget.Data[widget.Idx] return widget.Data[widget.Idx]
} }