Skip to content

Commit fddd973

Browse files
committed
feat: add 'overflowCharLimit' to allow commit message overflows
1 parent 5c83af7 commit fddd973

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ There is an additional `comet.json` file that includes the prefixes and descript
4848
- Default: 100
4949
- To adjust the total limit of characters in the *resulting* commit message, add the key `totalInputCharLimit` with the desired limit
5050
- Adding this key overrides scope- and message-specific limits
51+
- To allow typing beyond the character limit while still showing the count, add the key `overflowCharLimit` with the value `true`
52+
- Default: `false`
53+
- When enabled, the character count will turn orange when the limit is exceeded
5154
- To adjust the order of the scope completion values (i.e. longer or shorter strings first), add the key `scopeOrderCompletion` with either `"ascending"` or `"descending"`
5255
- Default: `"descending"`
5356
- To enable the storing of runtime statistics, add the key `storeRuntime` with the value `true`

comet.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"scopeInputCharLimit": 16,
44
"commitInputCharLimit": 100,
55
"totalInputCharLimit": 0,
6+
"overflowCharLimit": false,
67
"scopeCompletionOrder": "descending",
78
"findAllCommitMessages": false,
89
"storeRuntime": true,

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type config struct {
1717
ScopeInputCharLimit int `json:"scopeInputCharLimit"`
1818
CommitInputCharLimit int `json:"commitInputCharLimit"`
1919
TotalInputCharLimit int `json:"totalInputCharLimit"`
20+
OverflowCharLimit bool `json:"overflowCharLimit"`
2021
ScopeCompletionOrder string `json:"scopeCompletionOrder"`
2122
FindAllCommitMessages bool `json:"findAllCommitMessages"`
2223
StoreRuntime bool `json:"storeRuntime"`
@@ -113,6 +114,7 @@ func newConfig() *config {
113114
ScopeInputCharLimit: 16,
114115
CommitInputCharLimit: 100,
115116
TotalInputCharLimit: 0,
117+
OverflowCharLimit: false,
116118
ScopeCompletionOrder: "descending",
117119
FindAllCommitMessages: false,
118120
StoreRuntime: false,

gui.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
titleStyle = lipgloss.NewStyle().MarginLeft(2)
2929
itemStyle = lipgloss.NewStyle().PaddingLeft(4)
3030
characterCountColors = compat.AdaptiveColor{Light: lipgloss.Color("#8dacb6"), Dark: lipgloss.Color("240")}
31+
overflowCharColor = compat.AdaptiveColor{Light: lipgloss.Color("#d08770"), Dark: lipgloss.Color("#d08770")}
3132
// #d08770: nord12
3233
// #a3be8c: nord13
3334
selectedItemColors = compat.AdaptiveColor{Light: lipgloss.Color("#d08770"), Dark: lipgloss.Color("#a3be8c")}
@@ -91,6 +92,7 @@ type model struct {
9192
ynInput textinput.Model
9293
constrainInput bool
9394
totalInputCharLimit int
95+
overflowCharLimit bool
9496
previousInputTexts string
9597
typed int
9698
quitting bool
@@ -136,6 +138,11 @@ func newModel(c *config, stagedFiles []string, commitSearchTerm string) *model {
136138
commitInput.SetWidth(c.CommitInputCharLimit)
137139
}
138140

141+
if c != nil && c.OverflowCharLimit {
142+
scopeInput.CharLimit = 9999
143+
commitInput.CharLimit = 9999
144+
}
145+
139146
bodyConfirmation := textinput.New()
140147
bodyConfirmation.Placeholder = "y/N"
141148
bodyConfirmation.CharLimit = 1
@@ -161,6 +168,7 @@ func newModel(c *config, stagedFiles []string, commitSearchTerm string) *model {
161168
ynInput: bodyConfirmation,
162169
constrainInput: constrainInput,
163170
totalInputCharLimit: totalInputCharLimit,
171+
overflowCharLimit: c.OverflowCharLimit,
164172
stagedFiles: stagedFiles,
165173
scopeCompletionOrder: c.ScopeCompletionOrder,
166174
commitSearchTerm: commitSearchTerm,
@@ -382,7 +390,12 @@ func renderCurrentLimit(m *model, charLimit int, input string) string {
382390
padWidth := len(strconv.Itoa(limit))
383391
count := fmt.Sprintf(fmt.Sprintf("%%0%dd", padWidth), inputLength)
384392

385-
return lipgloss.NewStyle().Foreground(characterCountColors).Render(fmt.Sprintf(
393+
color := characterCountColors
394+
if m.overflowCharLimit && inputLength > limit {
395+
color = overflowCharColor
396+
}
397+
398+
return lipgloss.NewStyle().Foreground(color).Render(fmt.Sprintf(
386399
"[%s/%d]",
387400
count,
388401
limit,
@@ -400,7 +413,7 @@ func (m *model) View() tea.View {
400413
case !m.chosenScope:
401414
limit := renderCurrentLimit(m, m.scopeInput.CharLimit, m.scopeInput.Value())
402415

403-
if m.constrainInput {
416+
if m.constrainInput && !m.overflowCharLimit {
404417
m.scopeInput.CharLimit = m.totalInputCharLimit - m.typed
405418
if m.scopeInput.CharLimit == 0 {
406419
m.scopeInput.Placeholder = lengthExceedMessage
@@ -419,7 +432,7 @@ func (m *model) View() tea.View {
419432
case !m.chosenMsg:
420433
limit := renderCurrentLimit(m, m.msgInput.CharLimit, m.msgInput.Value())
421434

422-
if m.constrainInput {
435+
if m.constrainInput && !m.overflowCharLimit {
423436
m.msgInput.CharLimit = m.totalInputCharLimit - m.typed
424437
if m.msgInput.CharLimit == 0 {
425438
m.msgInput.Placeholder = lengthExceedMessage

0 commit comments

Comments
 (0)