Skip to content

Commit

Permalink
commit commands improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mrados7 committed Jan 15, 2024
1 parent 1ff0ac7 commit 3d1c534
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 53 deletions.
26 changes: 0 additions & 26 deletions .git-commands.json

This file was deleted.

74 changes: 48 additions & 26 deletions cmd/commit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import (
)

var (
focusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#6FD0FB")).Bold(true)
stepTitleStyle = lipgloss.NewStyle().Background(lipgloss.Color("#DA8BFF")).Foreground(lipgloss.Color("#000000")).Padding(0, 1)
focusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#DA8BFF")).Bold(true)
blurredStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("240"))
cursorStyle = focusedStyle.Copy()
noStyle = lipgloss.NewStyle()
stagedFilesStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#10ffcb"))
stagedFilesTitle = lipgloss.NewStyle().Foreground(lipgloss.Color("#a1e0fc")).Padding(1, 0)
focusedButton = focusedStyle.Copy().Render("[ Commit ]")
blurredButton = fmt.Sprintf("[ %s ]", blurredStyle.Render("Commit"))
)
Expand All @@ -37,7 +39,7 @@ func main() {
if !isGitRepo {
log.Fatal("Not a git repository")
}
p := tea.NewProgram(initialModel())
p := tea.NewProgram(initialModel(), tea.WithAltScreen())
if _, err := p.Run(); err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -87,7 +89,12 @@ func initialModel() model {

switch i {
case 0:
t.SetValue(fmt.Sprintf("[%s] [%s] ", branchType, ticketId))
if branchType != "" {
t.SetValue(fmt.Sprintf("[%s] ", branchType))
}
if ticketId != "" {
t.SetValue(t.Value() + fmt.Sprintf("[%s] ", ticketId))
}
t.Focus()
t.PromptStyle = focusedStyle
t.TextStyle = focusedStyle
Expand Down Expand Up @@ -193,46 +200,61 @@ func (m *model) updateInputs(msg tea.Msg) tea.Cmd {
}

func (m model) View() string {
var b strings.Builder
s := ""

stagedFilesView := ""
stagedFilesView += lipgloss.JoinVertical(lipgloss.Top, "Staged files:")
stagedFilesView += "\n"
for index, elem := range m.stagedFiles {
stagedFilesView += lipgloss.JoinVertical(lipgloss.Top, stagedFilesStyle.Render(fmt.Sprintf("• %s", elem)))
if index != len(m.stagedFiles)-1 {
stagedFilesView += "\n"
}
}

currentBranch := lipgloss.NewStyle().Foreground(lipgloss.Color("#fcbda1")).SetString(fmt.Sprintf("Branch: %s", m.branch))

b.WriteString(currentBranch.Render())
b.WriteRune('\n')
b.WriteRune('\n')
s += lipgloss.JoinVertical(lipgloss.Top, currentBranch.Render())

currentCommitCommand := lipgloss.NewStyle().Foreground(lipgloss.Color("#a1e0fc")).SetString(fmt.Sprintf("git commit -m \"%s\" %s", m.inputs[0].Value(), m.inputs[1].Value()))
//b.WriteString(currentBranch.Render())
//b.WriteRune('\n')
//b.WriteRune('\n')

b.WriteString(currentCommitCommand.Render())
b.WriteRune('\n')
b.WriteRune('\n')
//currentCommitCommand := lipgloss.NewStyle().Foreground(lipgloss.Color("#a1e0fc")).SetString(fmt.Sprintf("git commit -m \"%s\" %s", m.inputs[0].Value(), m.inputs[1].Value()))
//
//b.WriteString(currentCommitCommand.Render())
//b.WriteRune('\n')
//b.WriteRune('\n')
s += "\n\n"

inputLabels := []string{"Commit message ", "Commit flags "}
inputLabels := []string{"Commit message:", "Commit flags (optional):"}

for i := range m.inputs {
if i == m.focusInputIndex {
b.WriteString(lipgloss.NewStyle().Foreground(lipgloss.Color("#6FD0FB")).Bold(true).SetString(inputLabels[i]).Render())
} else {
b.WriteString(inputLabels[i])
}
b.WriteString(m.inputs[i].View())
b.WriteRune('\n')
s += lipgloss.JoinVertical(1, inputLabels[i])
s += "\n"
s += lipgloss.JoinVertical(0.5, m.inputs[i].View())
if i < len(m.inputs)-1 {
b.WriteRune('\n')
s += "\n"
}
}

button := &blurredButton
if m.focusInputIndex == len(m.inputs) {
button = &focusedButton
}
fmt.Fprintf(&b, "\n\n%s\n\n", *button)
s += "\n\n"
s += lipgloss.JoinVertical(1, *button)

stagedFilesStyle := lipgloss.NewStyle().MarginLeft(8).Border(lipgloss.NormalBorder()).Padding(0, 1)

b.WriteString("Staged changes: ")
b.WriteRune('\n')
b.WriteString(stagedFilesStyle.Render(strings.Join(m.stagedFiles, "\n")))
f := lipgloss.JoinHorizontal(lipgloss.Left, s, stagedFilesStyle.Render(stagedFilesView))
//fmt.Fprintf(&b, "\n%s\n\n", *button)

b.WriteRune('\n')
//b.WriteString("Staged changes: ")
//b.WriteRune('\n')
//b.WriteString()
//
//b.WriteRune('\n')

return b.String()
return f
}
12 changes: 11 additions & 1 deletion cmd/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ func GetStagedFiles() []string {
return []string{}
}

return strings.Split(string(out), "\n")
return filterEmpty(strings.Split(string(out), "\n"))
}

func filterEmpty(s []string) []string {
var r []string
for _, str := range s {
if str != "" {
r = append(r, str)
}
}
return r
}

func GetCurrentGitBranch() (string, error) {
Expand Down

0 comments on commit 3d1c534

Please sign in to comment.