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

Truncate long filename in header #58

Closed
wants to merge 1 commit into from
Closed

Truncate long filename in header #58

wants to merge 1 commit into from

Conversation

juntuu
Copy link

@juntuu juntuu commented Apr 8, 2020

The filename will be truncated if it would not fully fit on the screen
with the other data on the header.

Addresses some of the problems mentioned in #57

The filename will be truncated if it would not fully fit on the screen
with the other data on the header.
@juntuu juntuu changed the title Truncate long filename in header #57 Truncate long filename in header Apr 8, 2020
Copy link
Owner

@asottile asottile left a comment

Choose a reason for hiding this comment

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

thanks for taking a stab at this!

I'd suggest splitting this out into a function such that it can be tested better -- we probably also want to always leave space for the modification indicator (such that the header doesn't wiggle when it appears)

maybe a signature like this?

def _header(*, width: int, filename; str, modified: bool) -> str:
    ...

don't worry about getting the truncation perfect -- a first pass at this is ok (ideally we'd collapse folders first and then the filename last and never leave any partial-end-of-folders, etc.)

centered = filename.center(self.margin.cols)[version_width:]
s = f' {VERSION_STR} {files}{centered}{files}'

before, after = f' {VERSION_STR} {files}', f'{files}'
Copy link
Owner

Choose a reason for hiding this comment

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

the second fstring here does nothing

Copy link
Author

Choose a reason for hiding this comment

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

A question about this:
As far as I understand this, the right hand side files indicator would always be offscreen.
Firstly, am I correct in my understanding of this?
Second, is this intentional, should it be shown, or should it just go away?

Copy link
Owner

Choose a reason for hiding this comment

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

yeah that's a mistake on my part 😆 -- it should just go away. that's what you get for writing code while streaming 😆

before, after = f' {VERSION_STR} {files}', f'{files}'
room_for_filename = self.margin.cols - 2 * len(before)
if len(filename) > room_for_filename:
truncate = '... '
Copy link
Owner

Choose a reason for hiding this comment

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

the rest of the project utilizes the ellipsis character -- this also makes truncation preserve more characters

@juntuu
Copy link
Author

juntuu commented Apr 8, 2020

Thanks for the feedback, I'll factor the logic out to a function and try to improve this based on the suggestions.

@asottile asottile deleted the branch asottile:master March 24, 2022 18:42
@asottile asottile closed this Mar 24, 2022
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.

2 participants