Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/git/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func newDiffCmd(opts DiffOptions) *gitCommand {
}

if opts.IsUntracked {
args = append(args, untrackedFileDiffArgs[:3]...)
args = append(args, untrackedFileDiffArgs[:]...)
}

if len(opts.FilePath) > 0 {
Expand Down
11 changes: 2 additions & 9 deletions internal/git/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,8 @@ func readFileStatusFromOutputComponent(component string) (FileStatus, error) {
}

func cleanedPathString(path string) string {
path = strings.TrimSuffix(path, " ")
path = strings.TrimPrefix(path, " ")

if strings.Contains(path, " ") &&
strings.HasPrefix(path, "\"") &&
strings.HasSuffix(path, "\"") {
path = path[1 : len(path)-1]
}

path = strings.Trim(path, " ")
path = strings.Trim(path, "\"")
return path
}

Expand Down
15 changes: 8 additions & 7 deletions internal/ui/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Model struct {
}

func New(branch string, stagedFileList git.FileStatusList) Model {
fileListContent := list.NewContent(
fileListContent := list.NewContainerContent(
list.New(
"Staged",
func(msg tea.Msg) tea.Cmd { return nil },
Expand All @@ -42,8 +42,8 @@ func New(branch string, stagedFileList git.FileStatusList) Model {

fileListContent.Model, _ = fileListContent.SetItems(createListItems(stagedFileList))

messageContainer := container.New(
textinput.NewContent(
messageContainer := textinput.NewContainer(
textinput.New(
fmt.Sprintf("%s [%s]", "Commit", branch),
"Enter commit message",
),
Expand Down Expand Up @@ -77,7 +77,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
m, cmd = m.toggleFocus()
cmds = append(cmds, cmd)
case key.Matches(msg, m.keys.commit):
if mc, ok := m.message.Content().(textinput.Content); ok {
if mc, ok := m.message.Content().(textinput.ContainerContent); ok {
return m, tea.Sequence(Execute(mc.Text()), dialog.Close())
}
}
Expand Down Expand Up @@ -114,9 +114,10 @@ func (m Model) Help() []key.Binding {
}

func (m Model) setMsg(msg string) (Model, tea.Cmd) {
if input, ok := m.message.Content().(textinput.Content); ok {
input = input.SetValue(msg)
input = input.SetCursorToStart()
if input, ok := m.message.Content().(textinput.ContainerContent); ok {
input.Model = input.Model.
SetValue(msg).
SetCursorToStart()
m.message = m.message.SetContent(input)
}
return m, nil
Expand Down
37 changes: 0 additions & 37 deletions internal/ui/commit/content.go

This file was deleted.

37 changes: 37 additions & 0 deletions internal/ui/commit/dialog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package commit

import (
tea "github.com/charmbracelet/bubbletea"
"github.com/michaelhass/gitglance/internal/ui/dialog"
)

// DialogContent is a wrapper to use the commit ui as dialog.DialogContent.
type DialogContent struct {
Model
}

func NewContent(commit Model) DialogContent {
return DialogContent{
Model: commit,
}
}

func (dc DialogContent) Init() tea.Cmd {
return dc.Model.Init()
}

func (dc DialogContent) Update(msg tea.Msg) (dialog.Content, tea.Cmd) {
model, cmd := dc.Model.Update(msg)
dc.Model = model

return dc, cmd
}

func (dc DialogContent) View() string {
return dc.Model.View()
}

func (dc DialogContent) SetSize(width, height int) dialog.Content {
dc.Model = dc.Model.SetSize(width, height)
return dc
}
4 changes: 2 additions & 2 deletions internal/ui/confirm/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (m Model) Init() tea.Cmd {
return nil
}

func (m Model) Update(msg tea.Msg) (dialog.Content, tea.Cmd) {
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
if keyMsg, ok := msg.(tea.KeyMsg); ok && key.Matches(keyMsg, m.keys.confirm) {
return m, tea.Sequence(m.confirmCmd, dialog.Close())
}
Expand All @@ -67,7 +67,7 @@ func (m Model) Help() []key.Binding {
}
}

func (m Model) SetSize(width, height int) dialog.Content {
func (m Model) SetSize(width, height int) Model {
m.width = width
m.height = height
return m
Expand Down
33 changes: 33 additions & 0 deletions internal/ui/confirm/dialog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package confirm

import (
tea "github.com/charmbracelet/bubbletea"
"github.com/michaelhass/gitglance/internal/ui/dialog"
)

type DialogContent struct {
Model
}

func NewDialogConent(confirm Model) DialogContent {
return DialogContent{Model: confirm}
}

func (dc DialogContent) Init() tea.Cmd {
return dc.Model.Init()
}

func (dc DialogContent) Update(msg tea.Msg) (dialog.Content, tea.Cmd) {
model, cmd := dc.Model.Update(msg)
dc.Model = model
return dc, cmd
}

func (dc DialogContent) View() string {
return dc.Model.View()
}

func (dc DialogContent) SetSize(width, height int) dialog.Content {
dc.Model = dc.Model.SetSize(width, height)
return dc
}
32 changes: 32 additions & 0 deletions internal/ui/diff/container.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package diff

import (
tea "github.com/charmbracelet/bubbletea"
"github.com/michaelhass/gitglance/internal/ui/container"
)

// ContainerContent is a wrapper to use the commit ui as container.ContainerContent.
type ContainerContent struct {
Model
}

func NewContent(model Model) ContainerContent {
return ContainerContent{Model: model}
}

func (c ContainerContent) Update(msg tea.Msg) (container.Content, tea.Cmd) {
model, cmd := c.Model.Update(msg)
c.Model = model
return c, cmd
}

func (c ContainerContent) UpdateFocus(isFocused bool) (container.Content, tea.Cmd) {
model, cmd := c.Model.UpdateFocus(isFocused)
c.Model = model
return c, cmd
}

func (c ContainerContent) SetSize(width, height int) container.Content {
c.Model = c.Model.SetSize(width, height)
return c
}
32 changes: 0 additions & 32 deletions internal/ui/diff/content.go

This file was deleted.

37 changes: 37 additions & 0 deletions internal/ui/list/container.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package list

import (
tea "github.com/charmbracelet/bubbletea"
"github.com/michaelhass/gitglance/internal/ui/container"
)

// ContainerContent is a wrapper to use the filelist ui as container.ContainerContent.
type ContainerContent struct {
Model
}

func NewContainerContent(model Model) ContainerContent {
return ContainerContent{Model: model}
}

func NewContainer(model Model) container.Model {
containerContent := NewContainerContent(model)
return container.New(containerContent)
}

func (c ContainerContent) Update(msg tea.Msg) (container.Content, tea.Cmd) {
model, cmd := c.Model.Update(msg)
c.Model = model
return c, cmd
}

func (c ContainerContent) UpdateFocus(isFocused bool) (container.Content, tea.Cmd) {
model, cmd := c.Model.UpdateFocus(isFocused)
c.Model = model
return c, cmd
}

func (c ContainerContent) SetSize(width, height int) container.Content {
c.Model = c.Model.SetSize(width, height)
return c
}
32 changes: 0 additions & 32 deletions internal/ui/list/content.go

This file was deleted.

16 changes: 8 additions & 8 deletions internal/ui/status/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,7 @@ func deleteFile(fileItem filelist.Item) tea.Cmd {
}),
list.ForceFocusUpdate,
)
confirmDialog := confirm.New(
title,
msg,
confirmCmd,
)

confirmDialog := confirm.NewDialogConent(confirm.New(title, msg, confirmCmd))
return dialog.Show(confirmDialog, nil, dialog.CenterDisplayMode)
}

Expand Down Expand Up @@ -210,8 +205,13 @@ func showCommitDialog(branchName string, files git.FileStatusList) tea.Cmd {
}

func showStashAllConfirmation() tea.Cmd {
confirm := confirm.New("Stash", "Do you want to stash all changes?", stashAll())
return dialog.Show(confirm, refreshStatus(), dialog.CenterDisplayMode)
confirmDialog := confirm.NewDialogConent(
confirm.New(
"Stash", "Do you want to stash all changes?",
stashAll(),
),
)
return dialog.Show(confirmDialog, refreshStatus(), dialog.CenterDisplayMode)
}

type stashedMsg struct {
Expand Down
Loading