mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
fix: change bindings to actually work for the commit message
This commit is contained in:
@@ -14,10 +14,12 @@ import (
|
|||||||
"github.com/charmbracelet/bubbles/textarea"
|
"github.com/charmbracelet/bubbles/textarea"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
"github.com/inancgumus/screen"
|
||||||
)
|
)
|
||||||
|
|
||||||
type KeyMap struct {
|
type KeyMap struct {
|
||||||
EndWithMes key.Binding
|
EndWithMes key.Binding
|
||||||
|
NewLine key.Binding
|
||||||
}
|
}
|
||||||
|
|
||||||
func newKeyMap() *KeyMap {
|
func newKeyMap() *KeyMap {
|
||||||
@@ -25,6 +27,9 @@ func newKeyMap() *KeyMap {
|
|||||||
EndWithMes: key.NewBinding(
|
EndWithMes: key.NewBinding(
|
||||||
key.WithKeys("enter"),
|
key.WithKeys("enter"),
|
||||||
),
|
),
|
||||||
|
NewLine: key.NewBinding(
|
||||||
|
key.WithKeys("shift+tab"),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,8 +43,10 @@ func Entry_CM() string {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if m.(model_cm).textarea.Value() == "" {
|
if m.(model_cm).textarea.Value() == "" {
|
||||||
|
screen.Clear()
|
||||||
|
screen.MoveTopLeft()
|
||||||
fmt.Println("No commit message provided. Exiting...")
|
fmt.Println("No commit message provided. Exiting...")
|
||||||
os.Exit(1)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
return m.(model_cm).textarea.Value() + "\n"
|
return m.(model_cm).textarea.Value() + "\n"
|
||||||
}
|
}
|
||||||
@@ -55,6 +62,8 @@ type model_cm struct {
|
|||||||
func initialModel_cm() model_cm {
|
func initialModel_cm() model_cm {
|
||||||
ti := textarea.New()
|
ti := textarea.New()
|
||||||
ti.FocusedStyle = textarea.Style{Base: lipgloss.NewStyle().Foreground(lipgloss.Color("170"))}
|
ti.FocusedStyle = textarea.Style{Base: lipgloss.NewStyle().Foreground(lipgloss.Color("170"))}
|
||||||
|
ti.SetWidth(80)
|
||||||
|
ti.SetHeight(8)
|
||||||
|
|
||||||
ti.Placeholder = "Write your commit message here..."
|
ti.Placeholder = "Write your commit message here..."
|
||||||
ti.Focus()
|
ti.Focus()
|
||||||
@@ -73,11 +82,16 @@ func (m model_cm) Init() tea.Cmd {
|
|||||||
func (m model_cm) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model_cm) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
var cmds []tea.Cmd
|
var cmds []tea.Cmd
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch {
|
switch {
|
||||||
case key.Matches(msg, m.keys.EndWithMes):
|
case key.Matches(msg, m.keys.EndWithMes) && msg.Alt == true:
|
||||||
|
return m, tea.Quit
|
||||||
|
case key.Matches(msg, m.keys.NewLine):
|
||||||
|
m.textarea.SetValue(m.textarea.Value() + "\n")
|
||||||
|
return m, nil
|
||||||
|
case msg.String() == "esc":
|
||||||
|
m.textarea.SetValue("")
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
@@ -106,6 +120,6 @@ func (m model_cm) View() string {
|
|||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"Commit message:\n\n%s\n\n%s",
|
"Commit message:\n\n%s\n\n%s",
|
||||||
m.textarea.View(),
|
m.textarea.View(),
|
||||||
"(alt+enter | Submit)\n(ctrl+c | Cancel)",
|
"(enter | Submit)\n(shift+tab | Newline)\n(ctrl+c | Cancel)",
|
||||||
) + "\n\n"
|
) + "\n\n"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user