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

Added support for 'length' attribute for plugins. #131

Merged
merged 5 commits into from
Jan 7, 2016

Conversation

taylorzane
Copy link
Contributor

This feature allows one to truncate the line length of any line (title or menu bar item) to a specified length, per line.

I have also implemented a default line length of 20 characters, to prevent scripts from outputting an unnecessarily long title, or menu bar item, such as in #124.

One may override the default line length by using the length attribute.

Example:

'This is a very long string of text that needs to be longer than 20 characters | length=100'
||
'This is a very long string that can be any length so we will disable the truncation | length=-1'

I will also have to submit a PR for the plugins repo to list this attribute.

@johngibb
Copy link

johngibb commented Jan 7, 2016

Why not just truncate in your shell script?

$ echo "this is a long string" | cut -c1-10
this is a 

#124

@jcaille
Copy link
Contributor

jcaille commented Jan 7, 2016

That's nice !

Should we provide a way to see the full text though ? Maybe by hovering over the menu item ?
What happens if we pass length=0 ? Could that make is so that the text is not truncated ?

NSString * title = [params objectForKey:@"title"];
NSString * fullTitle = params[@"title"];

CGFloat lineLength = params[@"length"] ? [params[@"length"] floatValue] : 20;
Copy link

Choose a reason for hiding this comment

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

you could define these values somewhere, so they are not hardcoded

@taylorzane
Copy link
Contributor Author

@jcaille I figure some people may have a need for a zero-length string, so making length=0 would prevent users from doing that.

We definitely need a way to view the full length though. I think that hovering is our safest bet. Scrolling would be tough because our script should ideally be stateless,

@0wnrepo You're probably right. Especially if BitBar ever gets a config file, and this ends up as one of the config variables.

@taylorzane
Copy link
Contributor Author

@jcaille So having a tooltip provide the full string doesn't look terrible. I was also thinking that we could do what most native menu's do, and provide more detail (i.e. the full string) when you press and hold the option key.

This is a 100 character tooltip truncated to the default 20 characters:
screen shot 2016-01-07 at 08 58 52

This is a 300 character tooltip truncated to the default 20 characters:
screen shot 2016-01-07 at 09 04 23

@matryer
Copy link
Owner

matryer commented Jan 7, 2016

When it's truncated, we should add , don't you think?

@taylorzane
Copy link
Contributor Author

Heh, probably. Otherwise people may not realize why their output is missing.

@taylorzane
Copy link
Contributor Author

So the option key modifier works well, as long as your string isn't ridiculously long...It seems like anything over ~200 characters gets automatically truncated. So we may be better off with the tooltip, obviously it's up to the community to decide.

No option modifier:
screen shot 2016-01-07 at 10 12 50

With option modifier:
screen shot 2016-01-07 at 10 14 18

(Also, I implemented the ellipsis per request.)

@matryer
Copy link
Owner

matryer commented Jan 7, 2016

I think the tooltip is a good idea - maybe we can push the default limit up a bit?

We should keep the option alternative as something people can provide for themselves later. That'd be cool.

Like:

Hello | alt="world"

@taylorzane
Copy link
Contributor Author

I agree. I've found, even with some simple scripts, that 20 characters is a bit too small. Are you referring to passing an option param after the string? Or were you just referring to people who want that, can implement it themselves?

@matryer
Copy link
Owner

matryer commented Jan 7, 2016

(see my edit)

@matryer
Copy link
Owner

matryer commented Jan 7, 2016

Yes. But that interface might not work - because it's essentially a different option completely. Needs some thought.

@jcaille
Copy link
Contributor

jcaille commented Jan 7, 2016

I think the length keyword is a good idea, but I would personally remove the default for the following reasons

  • It does not encourage plugin writer to be succinct.
  • The cut might be weirdly placed, or cut off important information.
  • It might be seen as a bug by new developers who might wonder why their text is being truncated (and maintaining option is not easily discoverable)
  • It might break existing plugins
  • Bitbar can display errors inline (allowing to easily see what went wrong). Truncating those errors make it less obvious.
  • There is no easy way to disable the truncation.

Just keeping the length parameter available would allow plugins that might output very long text to toggle the option.

@matryer
Copy link
Owner

matryer commented Jan 7, 2016

@jcaille makes some good points.

@taylorzane
Copy link
Contributor Author

Fair enough. I didn't consider the issue with errors. But being considered a bug by anyone is definitely not ideal. That's good enough of an argument for me. I'll kill the default, and implement the tooltips.

…trings. Added tooltips to strings that are truncated.
@taylorzane
Copy link
Contributor Author

I pushed a new commit. It includes the following:

  • Default limit is gone. You must specify length=some_positive_integer for any truncation to occur.
    • length=0 will simply leave an ellipsis with a tooltip of the full message.
  • An ellipsis will be appended to any truncated string.
  • A tooltip will be added to any truncated menu item, that will display the full string.

I tested this param with multiple different cases:

  • With params color, size, font (all possible combinations)
  • With param bash
  • With param dropdown=false

All mentioned tests worked flawlessly.

@matryer
Copy link
Owner

matryer commented Jan 7, 2016

Excellent - I wonder if you could update the README too? Here: https://github.com/matryer/bitbar#plugin-api

Something like:

length=.. ensures the content will never grow beyond length+1 characters (full content is available in tooltip)

@taylorzane
Copy link
Contributor Author

Absolutely. I didn't realize that the API section was moved here.

@matryer
Copy link
Owner

matryer commented Jan 7, 2016

Nice work :)

@matryer
Copy link
Owner

matryer commented Jan 7, 2016

... while you're in there, could you stick this link on the shebang word? https://en.wikipedia.org/wiki/Shebang_(Unix)

@taylorzane
Copy link
Contributor Author

Haha certainly

@taylorzane
Copy link
Contributor Author

Alright, README has been updated with the shebang link and the necessary length documentation.

matryer added a commit that referenced this pull request Jan 7, 2016
Added support for 'length' attribute for plugins.
@matryer matryer merged commit 58d6057 into matryer:master Jan 7, 2016
@matryer
Copy link
Owner

matryer commented Jan 8, 2016

Excellent. Nice work. Thanks to everyone for their input.

@alex-ruehe
Copy link

Is there a way to pad a string using the length parameter?

The output from the ping plugin has different widths, depending on the ping time - I would love to have a fixed width - say 10 characters so that the output doesn't "jump" when it's getting longer/shorter. Or is there a way to do it with bash? I tried using printf (printf "%10s" "$MSG") but this didn't work. It works in the terminal but somehow the leading spaces are removed.

@mm2270
Copy link

mm2270 commented Mar 1, 2016

Hi. Not sure if this is the appropriate place to ask this, but since I know this is part of the feature above, is there any way to add tooltips manually to each line of script output for a plug-in? For example, if my lines are not long enough to end up being truncated, can I add a manual tooltip with custom text to the line? Something that when hovered over will pop up explaining what the line is referencing? I could definitely make use of such a feature, and I think it might be useful since it would prevent the need to include a verbose string on a menu line, i.e., the less relevant info can go under a tooltip to make the menu appear tidier.
Thoughts? Should I open a new issue/request for this instead?

@iosdeveloper
Copy link
Collaborator

@mm2270 Please open a new issue.

@mm2270
Copy link

mm2270 commented Mar 1, 2016

Will do. Thanks.

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.

None yet

8 participants