Skip to content

Conversation

@GMkonan
Copy link

@GMkonan GMkonan commented Jun 23, 2022

Really simple implementation of a simple warning for when you commit message pass a certain number, from this issue:

If someone wants any changes in what I did feel free to point out, I thought about adding commitLengthWarning to CommitLengthConfig but I'm not sure since they are related but are not exact the same thing (one is the counter and the other is an effect in the actual message).

Thank you!

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments :)

}

func (gui *Gui) checkCommitLengthWarning() {
commitLength, _ := strconv.Atoi(strings.Trim(gui.Views.CommitMessage.Subtitle, " "))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't depend on the view's subtitle to access the length of the content. If we wanted to just access the integer I'd change getBufferLength to return an int i.e. directly return strings.Count(view.TextArea.GetContent(), "")-1 and then in RenderCommitLength I'd go:

commitLength := getBufferLength(gui.Views.CommitMessage)
gui.Views.CommitMessage.Subtitle = fmt.Sprintf(" %d ", commitLength)

With that said: when people talk about limiting the length of a commit message's lines: they're talking about a line-by-line basis, so looking at the entirety of the commit message won't suffice: we need to instead check if any line exceeds the threshold.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't even consider that, I have a zshrc config that points if I've passed 72 chars only in the commit title. But yeah it makes a lot of sense to extend this to multiple lines.

UnstagedChangesColor: []string{"red"},
},
CommitLength: CommitLengthConfig{Show: true},
CommitLengthWarning: 72,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd bundle this inside CommitLengthConfig. I'd also call it WarningThreshold. I'd also default it to disabled (which we can encode via 0) because people have different opinions about whether commit length matters.

@GMkonan GMkonan force-pushed the commit-message-length-warning branch 3 times, most recently from 4c9b72e to dcd02d0 Compare July 6, 2022 21:52
@GMkonan GMkonan requested a review from jesseduffield July 6, 2022 21:53
@GMkonan GMkonan force-pushed the commit-message-length-warning branch from dcd02d0 to 0996f9e Compare July 6, 2022 21:57
@GMkonan
Copy link
Author

GMkonan commented Jul 6, 2022

I'm quite unsure about how this should work and would like a second opinion. Right now ALL the text turns red when you pass the amount of chars specified, but comes back to normal when you go to another line, so you have a warning that is based on each line but the text color doesn't persist for each line.

Is this the best way or should the text persist? And if it needs to persist, is there any already made way to change the line color and not all text?

@simon-abbott
Copy link

simon-abbott commented Oct 13, 2022

I'm quite unsure about how this should work and would like a second opinion.

My vision for this feature is to have each line validated separately, with any text past the threshold either turning a different color, or, ideally, autowrapping (maybe have a setting overflow with possible values warn, wrap, and ignore). It would also be nice if the length counter in the corner would display the current line length, either in addition to, or instead of, the total message length.

For example, the commit message

Hello world, this is the subject

This is a long body that will wrap over the 72 character limit on the
next line. When this happens it would be great for it to have some sort of warning

With overflow: warn: ( = cursor position)

┌─Commit message─────────────────────────────────────────────────────────────────────── 82 / 186 ─────┐
│ Hello world, this is the subject                                                                    │
│                                                                                                     │
│ This is a long body that will wrap over the 72 character limit on the                               │
│ next line. When this happens it would be great for it to have some sort of warning█                 │
│                                                                         ^^^^^^^^^^-this text is red │
└─────────────────────────────────────────────────────────────────────────────────────────────────────┘

With overflow: wrap:

┌─Commit message─────────────────────────────────────────── 10 / 186 ─────┐
│ Hello world, this is the subject                                        │
│                                                                         │
│ This is a long body that will wrap over the 72 character limit on the   │
│ next line. When this happens it would be great for it to have some sort |
│ of warning█                                                             │
└─────────────────────────────────────────────────────────────────────────┘

However I recognize that this is an ideal form for me, and will be harder to implement. If possible it would be amazing for my productivity, but I'd settle for anything that gives me an indication of the line length (maybe a vertical ruler, even turning the whole text/line red would technically work, just wouldn't be ideal).

@stefanhaller
Copy link
Collaborator

Closing as obsolete, now that we have #3173.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants