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

Shrink/shorten columns on narrow screen #7

Open
applejag opened this issue Apr 17, 2023 · 1 comment
Open

Shrink/shorten columns on narrow screen #7

applejag opened this issue Apr 17, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@applejag
Copy link
Owner

applejag commented Apr 17, 2023

We don't want wrapping, as that's a big headache to render, and you can't really copy-paste from the terminal correctly then.

Instead, let's shrink columns when there's too much information.

Some columns should not get shrunk:

  • any that's not a static string (e.g "Age" is a timestamp)
  • if it only contains digits (i.e it's an integers)

Algorithm, when we need to shrink:

  1. Find the widest column
  2. Find the widest values in that column
  3. Remove two characters in the middle, replacing with ellipsis ()

Repeat above until we fit the width.

As an optimization, we could have this as a custom type that only deals with slices, like so:

type ShrunkenString struct {
	Start string
	End   string
}

func (s ShrunkenString) String() string {
	return s.Start + "…" + s.End
}

And then while shrinking multiple times, we don't have to generate a bunch of intermediate strings before we get the final value.

@applejag applejag added the enhancement New feature or request label Apr 17, 2023
@applejag
Copy link
Owner Author

Another idea to add on top: the current column spacing is 3 spaces. Could reduce down to 2 (on demand) to help save some space. Would be helpful when the output is just 1-2 characters too wide

@applejag applejag self-assigned this Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant