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 a truncater to prevent overlength output cascades in spingroup #36

Merged
merged 2 commits into from
Jul 5, 2018

Conversation

burke
Copy link
Member

@burke burke commented Jun 29, 2018

screen shot 2018-06-29 at 4 20 48 pm

@burke burke requested a review from a team June 29, 2018 20:21
end
end

return text if !truncation_index || width <= printing_width
Copy link
Contributor

Choose a reason for hiding this comment

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

why would we need to check width <= printing_width, shouldnt we just need to check truncation index?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing this case causes Truncater.call("foo\x1b[0m", 3) to truncate. It's specifically for the case where we decided "Yes, this is the point at which we'd have to add a truncation!" but it's actually the end of the string.

Copy link
Contributor

Choose a reason for hiding this comment

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

That might be a useful comment to leave

truncation_index ||= index
when 1
truncation_index ||= index
end

Choose a reason for hiding this comment

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

Could this be if width >= printing_width instead of width <=> printing_width?

Should we break out of the block at this point?

#
def render(index, force = true)
return full_render(index) if force || @force_full_render
def render(index, force = true, width: CLI::UI::Terminal.width)

Choose a reason for hiding this comment

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

Not really for this PR,, but can we dynamically evaluate the terminal width? I'm thinking, what if people resize while we're spinning.

Copy link
Contributor

Choose a reason for hiding this comment

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

We dont really ever support resizing once you've started since we don't redraw anything above, though since this does redraw the line, maybe it does make sense to do this

SEMICOLON = 0x3b

# EMOJI_RANGE in particular is super inaccurate. This is best-effort.
# Make it better if you need it better.
Copy link
Contributor

Choose a reason for hiding this comment

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

Open source project: "PRs to make this better will be gratefully accepted."

when NUMERIC_RANGE, SEMICOLON
when LC_ALPHA_RANGE, UC_ALPHA_RANGE
mode = PARSE_ROOT
end
Copy link
Contributor

Choose a reason for hiding this comment

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

else raise? Or can we drop when NUMERIC_RANGE, SEMICOLON?


def width(printable_codepoint)
case printable_codepoint
when EMOJI_RANGE
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems close enough for now. Maybe if this starts seeming inadequate.

@burke
Copy link
Member Author

burke commented Jul 4, 2018

Comments addressed

@burke burke merged commit 34f794f into master Jul 5, 2018
@burke burke deleted the truncater branch July 5, 2018 16:01
@lugray lugray temporarily deployed to production November 9, 2018 18:39 Inactive
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