diff --git a/git/display.go b/git/display.go index be0b56f3..2e11edd4 100644 --- a/git/display.go +++ b/git/display.go @@ -10,6 +10,10 @@ func (widget *Widget) display() { widget.View.Clear() 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) widget.View.SetTitle(fmt.Sprintf(" Git: %s ", title)) diff --git a/git/widget.go b/git/widget.go index 52bc6d08..55969baf 100644 --- a/git/widget.go +++ b/git/widget.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" "time" - "github.com/gdamore/tcell" "github.com/olebedev/config" @@ -78,7 +77,15 @@ func (widget *Widget) Prev() { /* -------------------- Unexported Functions -------------------- */ func (widget *Widget) currentData() *GitRepo { - return widget.Data[widget.Idx] + if len(widget.Data) == 0 { + return nil + } + + if widget.Idx < 0 || widget.Idx >= len(widget.Data) { + return nil + } + + return widget.Data[widget.Idx] } func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {