Skip to content

Commit 0085eab

Browse files
committed
feat: add some functionality to the left panels
Signed-off-by: Ayush <mail@ayuch.dev>
1 parent dab40b0 commit 0085eab

File tree

6 files changed

+399
-61
lines changed

6 files changed

+399
-61
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
)
1313

1414
require (
15+
github.com/atotto/clipboard v0.1.4 // indirect
1516
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1617
github.com/charmbracelet/colorprofile v0.3.2 // indirect
1718
github.com/charmbracelet/x/ansi v0.10.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
2+
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
13
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
24
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
35
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=

internal/git/branch.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,18 @@ func (g *GitCommands) Switch(branchName string) (string, error) {
151151

152152
return string(output), nil
153153
}
154+
155+
// RenameBranch renames a branch.
156+
func (g *GitCommands) RenameBranch(oldName, newName string) (string, error) {
157+
if oldName == "" || newName == "" {
158+
return "", fmt.Errorf("both old and new branch names are required")
159+
}
160+
161+
cmd := ExecCommand("git", "branch", "-m", oldName, newName)
162+
output, err := cmd.CombinedOutput()
163+
if err != nil {
164+
return string(output), fmt.Errorf("failed to rename branch: %v", err)
165+
}
166+
167+
return string(output), nil
168+
}

internal/tui/model.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ package tui
33
import (
44
"github.com/charmbracelet/bubbles/help"
55
"github.com/charmbracelet/bubbles/key"
6+
"github.com/charmbracelet/bubbles/textinput"
67
"github.com/charmbracelet/bubbles/viewport"
78
tea "github.com/charmbracelet/bubbletea"
89
"github.com/gitxtui/gitx/internal/git"
910
)
1011

12+
// appMode defines the different operational modes of the TUI.
13+
type appMode int
14+
15+
const (
16+
modeNormal appMode = iota
17+
modeInput
18+
modeConfirm
19+
)
20+
1121
// Model represents the state of the TUI.
1222
type Model struct {
1323
width int
@@ -26,6 +36,13 @@ type Model struct {
2636
git *git.GitCommands
2737
repoName string
2838
branchName string
39+
// New fields for pop-ups
40+
mode appMode
41+
promptTitle string
42+
confirmMessage string
43+
textInput textinput.Model
44+
inputCallback func(string) tea.Cmd
45+
confirmCallback func(bool) tea.Cmd
2946
}
3047

3148
// initialModel creates the initial state of the application.
@@ -35,7 +52,6 @@ func initialModel() Model {
3552
repoName, branchName, _ := gc.GetRepoInfo()
3653
initialContent := initialContentLoading
3754

38-
// Create a slice to hold all UI panels.
3955
panels := make([]panel, totalPanels)
4056
for i := range panels {
4157
vp := viewport.New(0, 0)
@@ -46,6 +62,11 @@ func initialModel() Model {
4662
}
4763
}
4864

65+
ti := textinput.New()
66+
ti.Focus()
67+
ti.CharLimit = 256
68+
ti.Width = 50
69+
4970
return Model{
5071
theme: Themes[themeNames[0]],
5172
themeNames: themeNames,
@@ -59,6 +80,8 @@ func initialModel() Model {
5980
repoName: repoName,
6081
branchName: branchName,
6182
panels: panels,
83+
mode: modeNormal,
84+
textInput: ti,
6285
}
6386
}
6487

0 commit comments

Comments
 (0)