745ed4cd200d59fff75b08c1f34b4d796d022214

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

Return errMsg when config is not set

Diff

 1diff --git a/tui/bubble.go b/tui/bubble.go
 2index 062548ac2b8a038837acd23c1c404c8baa10de07..e0ebb9ea62b40f0f5ea0d1f8503b6f4e83304e49 100644
 3--- a/tui/bubble.go
 4+++ b/tui/bubble.go
 5@@ -61,12 +61,16 @@ type Bubble struct {
 6 }
 7 
 8 func NewBubble(cfg *Config, sCfg *SessionConfig) *Bubble {
 9+	var repoSource *git.RepoSource = nil
10+	if cfg != nil {
11+		repoSource = cfg.RepoSource
12+	}
13 	b := &Bubble{
14 		config:      cfg,
15 		styles:      style.DefaultStyles(),
16 		width:       sCfg.Width,
17 		height:      sCfg.Height,
18-		repoSource:  cfg.RepoSource,
19+		repoSource:  repoSource,
20 		repoMenu:    make([]MenuEntry, 0),
21 		boxes:       make([]tea.Model, 2),
22 		initialRepo: sCfg.InitialRepo,
23@@ -156,7 +160,11 @@ func (b *Bubble) viewForBox(i int) string {
24 
25 func (b Bubble) headerView() string {
26 	w := b.width - b.styles.App.GetHorizontalFrameSize()
27-	return b.styles.Header.Copy().Width(w).Render(b.config.Name)
28+	name := ""
29+	if b.config != nil {
30+		name = b.config.Name
31+	}
32+	return b.styles.Header.Copy().Width(w).Render(name)
33 }
34 
35 func (b Bubble) footerView() string {
36diff --git a/tui/commands.go b/tui/commands.go
37index e88856e99e926d8e3fa73045a60a9bb275e04b27..4f7c6d45259e13c77632a2f4fb6f43b1c4ccb99d 100644
38--- a/tui/commands.go
39+++ b/tui/commands.go
40@@ -19,6 +19,9 @@ func (e errMsg) Error() string {
41 }
42 
43 func (b *Bubble) setupCmd() tea.Msg {
44+	if b.config == nil || b.config.RepoSource == nil {
45+		return errMsg{err: fmt.Errorf("config not set")}
46+	}
47 	ct := time.Now()
48 	lipgloss.SetColorProfile(termenv.ANSI256)
49 	b.repos = b.repoSource.AllRepos()