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

Add option to limit length of tab titles #5718

Merged
merged 1 commit into from
Nov 29, 2022
Merged

Add option to limit length of tab titles #5718

merged 1 commit into from
Nov 29, 2022

Conversation

fratajczak
Copy link
Contributor

This PR adds an option to truncate tab titles above a certain length.

I find it annoying sometimes to have very long commands take up lots of screen space for their tab titles. Related to #1494, but it's not exactly what was requested: tab_min_length would need to be added to have a fixed tab size, but I find just setting a max length good enough for my use case.

@kovidgoyal
Copy link
Owner

You dont need ctype in the option definition as this option is only used by python code.

@fratajczak
Copy link
Contributor Author

You dont need ctype in the option definition as this option is only used by python code.

Okay, fixed

@kovidgoyal kovidgoyal merged commit d6dcdf0 into kovidgoyal:master Nov 29, 2022
@page-down
Copy link
Contributor

page-down commented Nov 29, 2022

@fratajczak

I believe the naming of this configuration option is not accurate, however I did not raise it in time before the merge.
This option should be named tab_title_max_length. (We already have tab_title_template, prefixed by tab_title_)

I also have a question about the placement of this option in definition.py, why is it in between a bunch of tab_bar_?
Logically, similar configuration options should be placed together as much as possible and ordered according to importance and dependency.

@page-down
Copy link
Contributor

page-down commented Nov 29, 2022

I looked at it again and the option name look accurate, however I am not sure this is what the user expects.

The length of the tab includes left and right decorations, abbreviations ..., and I think it is more useful to limit the length of the title rather than the total length of the tab.

@fratajczak
Copy link
Contributor Author

Indeed, I think it would be better to truncate the title instead.

@kovidgoyal I think your commit 5c50e38 doesn't actually fix the problem: try

tab_bar_style fade
tab_title_max_length 5

The fading separators get cropped.

Screenshot from 2022-11-29 16-39-25

The max_tab_length parameter of draw_title doesn't do anything, it's just used to tell how much title length is available in the title_template.

Something like:

 def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int, max_title_length: int = 0) -> None:
+    tab_title = tab.title
+    if draw_data.max_title_length > 0 and len(tab_title) > draw_data.max_title_length:
+            tab_title = tab.title[:draw_data.max_title_length] + '…'
     ta = TabAccessor(tab.tab_id)
     data = {
         'index': index,
         'layout_name': tab.layout_name,
         'num_windows': tab.num_windows,
         'num_window_groups': tab.num_window_groups,
-        'title': tab.title,
+        'title': tab_title,
         'tab': ta,

Would crop only the title

@kovidgoyal
Copy link
Owner

max_tab_length is not used in draw_title its used after draw title.

@kovidgoyal
Copy link
Owner

And you cant use python string lengths to truncate strings, they dont correspond to visual lengths, you need to use truncate_point_for_length. And you cant truncate just the tab title, since the actual remdered title is based on a template that can process the tab title in arbitrary ways.

@kovidgoyal
Copy link
Owner

See 722a102

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.

3 participants