Skip to content
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

feat: separate layout items with spaces #91

Merged
merged 9 commits into from
Mar 22, 2023
Merged

Conversation

joshmedeski
Copy link
Contributor

@joshmedeski joshmedeski commented Mar 8, 2023

Fixes #90

Purpose

Adds a space at the end of every layout component.

Approach

  • Properly adds a space, after every layout component.
  • Update the default layout to not include a forward space on the dash separator.

@arl
Copy link
Owner

arl commented Mar 8, 2023

Thank you @joshmedeski
Can you add some unit test please?

@joshmedeski
Copy link
Contributor Author

Sure thing!

@joshmedeski
Copy link
Contributor Author

The way the tests are written make it hard to debug. I recommend moving away from a for loop for tests so when a test fails you get immediate feedback and a proper line number for what test failed.

@arl
Copy link
Owner

arl commented Mar 8, 2023

Each test in the for loop is a sub test. You can run a single sub test with go test -run TEST NAME/SUBTESTNAME

@joshmedeski
Copy link
Contributor Author

I'm wondering if this should be a flag that doesn't cause a breaking change to the way everything is rendered now? (like tailing_spaces?)

Let me know your thoughts.

@arl
Copy link
Owner

arl commented Mar 8, 2023

I'm wondering if this should be a flag that doesn't cause a breaking change to the way everything is rendered now? (like tailing_spaces?)

Let me know your thoughts.

Yep this might be needed if the change is too important. Let me think about it

@joshmedeski
Copy link
Contributor Author

I got the tests working and I got the feature working to the best of my ability for now.

But if someone doesn't like having the trailing spaces between each layout component we'll have to write more code to handle that.

@arl
Copy link
Owner

arl commented Mar 12, 2023

Adds a space at the end of every layout component.
@joshmedeski

What's the difference between adding spaces manually in the layout section?

For example, this is the default layout section:

layout: [branch, remote-branch, divergence, "- ", flags]

This is the one I've been using:

layout: [branch, ' ', remote-branch, divergence, ' - ', flags, ' ', stats]

@joshmedeski
Copy link
Contributor Author

So in your second example, when divergence, flags, and / or stats have nothing to show. You end up with extra white spaces in the tmux status bar (see the screenshots from the issue). I'd rather trim the whitespace if there's nothing to render.

@arl arl force-pushed the separate-layout branch from ed60020 to f5efa6a Compare March 22, 2023 13:02
@arl arl force-pushed the separate-layout branch from f5efa6a to 4f334db Compare March 22, 2023 13:02
Copy link
Owner

@arl arl left a comment

Choose a reason for hiding this comment

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

@joshmedeski
Hey thanks for the feature and the pull-request. It really makes sense.

I had a look at the code and I thought there was a much simpler way to do it, but it required a refactoring of how gitmux components are handled. The gist of it is that every function that computes a gitmux component returns a string.

The format() function is the one that puts it all together by adding spacing between components, but only when they're not empty or else we'd end up with 2 (or more depending on the cases) consecutive spaces. This logic can only be done cleanly and correctly in the tmux/Formatter.format function.

So I went ahead and did it on top of your pull-request.

@arl arl merged commit 395d66d into arl:main Mar 22, 2023
@arl
Copy link
Owner

arl commented Mar 22, 2023

@joshmedeski I've tagged a new release with both your pull-requests (v0.10.0)
Thanks again for the help!

@joshmedeski joshmedeski deleted the separate-layout branch March 22, 2023 14:48
@joshmedeski
Copy link
Contributor Author

That makes more sense. This was my first time in the codebase so I'm starting to get my way around.

I had the same idea later on to move this logic in the place that chains the layout components together, thanks for doing it!

@arl
Copy link
Owner

arl commented Mar 22, 2023

Sure, no worries. You did a great job 🎉

@joshmedeski
Copy link
Contributor Author

Can we update to make sure the final component includes a space if anything is rendered?

Screenshot 2023-03-22 at 9 54 39 AM

@arl
Copy link
Owner

arl commented Mar 22, 2023

Can we update to make sure the final component includes a space if anything is rendered?

Screenshot 2023-03-22 at 9 54 39 AM

I don't understand. Do you mean a trailing space?

@joshmedeski
Copy link
Contributor Author

Exactly

@arl
Copy link
Owner

arl commented Mar 22, 2023

Ah i think I got it. I think you mean a trailing space, in case anything was rendered. That's a particular case though. Majority of people, myself included, do not have anything after gitmux status shown on their tmux status bar.
Isn't that something you can fix by adding a trailing space to your config layout?

@joshmedeski
Copy link
Contributor Author

Fair point, so my tmux status is {session_name} {gitmux} {windows}. But sometimes I load tmux sessions that don't have a gitmux session so I'm hoping to have {session_name} {windows} render without any extra spaces.

It's a little tricky. Maybe I can add a trailing_space option to support this situation? Just adding a space at the end of my layout potentially creates two spaces when I was hoping for just one on tmux sessions that don't render anything in gitmux.

Hope all that makes sense.

@arl
Copy link
Owner

arl commented Mar 22, 2023

That seems a little specific to your use case to be honest

I think you might be able to do that with the help of a simple script, called instead of gitmux, from your tmux.conf, and depending on whether gitmux string is empty, you add a trailing space or not.
With some tmux status string ninja-foo, you might even be able to do that without the help of an addition script.

It's not that I'm against that feature or anything, but I need to set the bar for features everybody can benefit from. sorry.
If you're willing to open an issue for that, and let see if there are other users with that need.

@joshmedeski
Copy link
Contributor Author

I implemented the feature, see #94

This is a non-breaking change but is very useful for people who want to place gitmux between other elements in their tmux status bar. Hopefully you find it not too invasive and decide to merge it.

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.

[FEATURE] Conditional Spacing
2 participants