Skip to content

Feature/style #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 10, 2023
4 changes: 3 additions & 1 deletion cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
package cmd

import (
"fmt"

"github.com/cocoide/commitify/static"
"github.com/fatih/color"
"github.com/spf13/cobra"
Expand All @@ -15,7 +17,7 @@ var docsCmd = &cobra.Command{
Short: "Document of commitify",
Run: func(cmd *cobra.Command, args []string) {
b, _ := static.Logo.ReadFile("logo.txt")
color.Cyan(string(b))
fmt.Print(color.CyanString(string(b)) + "\n\n ・Languageは日本語と英語が選択できます\n\n ・CodeFormatはPrefix (例: feat: A)とEmoji (例: 🐛 Bugix), Normal (例: Feat A)が選べます")
},
}

Expand Down
10 changes: 3 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ import (

var rootCmd = &cobra.Command{
Use: "commitify",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Short: "CLI for thinking commit message",
Long: `By "commitify config" command, you can change commit message format or language,
( To know details about format or language, enter commitify docs )`,
}

func Execute() {
Expand Down
65 changes: 44 additions & 21 deletions cmd/suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@ import (
"os"
"strings"

"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/cocoide/commitify/internal/entity"
"github.com/cocoide/commitify/internal/gateway"
"github.com/cocoide/commitify/util"
"github.com/fatih/color"
"github.com/spf13/cobra"
)

var (
textStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("252")).Render
spinnerStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("69"))
helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render
)

type model struct {
choices []string
currentIdx int
errorMsg string
isLoading bool
isEditing bool
textInput textinput.Model
isEditing bool
spinner spinner.Model
textInput textinput.Model
}

func (m *model) Init() tea.Cmd {
Expand All @@ -38,13 +47,16 @@ func (m *model) Init() tea.Cmd {
gi = gateway.NewGrpcServeGateway()
}

messages, err := gi.FetchCommitMessages()
if err != nil {
log.Fatal("コミットメッセージの生成に失敗: ", err)
os.Exit(-1)
}
m.choices = messages
m.isLoading = false
go func() {
messages, err := gi.FetchCommitMessages()
if err != nil {
log.Fatal("コミットメッセージの生成に失敗: ", err)
os.Exit(-1)
}
m.choices = messages
m.isLoading = false
}()

return textinput.Blink
}

Expand Down Expand Up @@ -78,28 +90,39 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyCtrlC, tea.KeyEsc:
return m, tea.Quit
}
case spinner.TickMsg:
var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg)
return m, cmd
}
return m, nil
return m, m.spinner.Tick
}

func (m *model) resetSpinner() {
m.spinner = spinner.New()
m.spinner.Style = spinnerStyle
m.spinner.Spinner = spinner.Globe
}

func (m *model) View() string {
if m.errorMsg != "" {
return color.RedString(m.errorMsg)
}
if m.isLoading {
return "🌎 Generating commit messages ..."
s := fmt.Sprintf("\n %s %s\n\n", m.spinner.View(), textStyle("コミットメッセージ生成中"))
return s
}
var b strings.Builder
if m.errorMsg != "" {
b.WriteString(color.RedString(m.errorMsg) + "\n\n")
}
if m.isEditing{
if m.isEditing {
return m.textInput.View()
}

b.WriteString(color.WhiteString("🍕Please select an option:"))
b.WriteString(color.WhiteString("\n Use arrow ↑↓ to navigate and press Enter to select.\n\n"))

b.WriteString(color.WhiteString("🍕 Please select and enter to commit"))
b.WriteString(color.WhiteString("\n Use arrow ↑↓ to navigate and press Enter to select."))
b.WriteString(color.WhiteString("\n ( enter Tab key to edit message )\n\n"))

for i, choice := range m.choices {
if i == m.currentIdx {
Expand All @@ -116,22 +139,22 @@ func initialModel() model {
ti.Focus()

return model{
choices :[]string{""},
currentIdx :0,
errorMsg :"",
choices: []string{""},
currentIdx: 0,
errorMsg: "",
isLoading: true,
isEditing: false,
textInput: ti,
isEditing: false,
textInput: ti,
}
}


var suggestCmd = &cobra.Command{
Use: "suggest",
Short: "Suggestion of commit message for staging repository",
Aliases: []string{"s", "suggest"},
Run: func(cmd *cobra.Command, args []string) {
m := initialModel()
m.resetSpinner()
p := tea.NewProgram(&m)
p.Run()
},
Expand Down
35 changes: 0 additions & 35 deletions cmd/version.go

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.19
require (
github.com/charmbracelet/bubbles v0.16.1
github.com/charmbracelet/bubbletea v0.24.2
github.com/charmbracelet/lipgloss v0.7.1
github.com/fatih/color v1.15.0
github.com/golang/mock v1.4.4
github.com/sashabaranov/go-openai v1.15.1
Expand Down