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

[FEAT] Truncate field in format #1043

Closed
aarondill opened this issue Jun 26, 2024 · 5 comments
Closed

[FEAT] Truncate field in format #1043

aarondill opened this issue Jun 26, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@aarondill
Copy link

aarondill commented Jun 26, 2024

Wanted features:

I would like to be able to truncate format fields to arbitrary lengths.
For example, this could be implemented like this format: "{1:10}" which would display the first 10 characters of field 1.
Thoughts:

  • Should this show an ellipsis (...)?
  • Should unnumbered fields be supported (format: "{:10}")?

Motivation:

I'd like to be able to shorten very long hardware names (in order to avoid wrapped lines in smaller terminals), such as Sound cards, Cameras, and Cpus.

For an example of this issue. This is shown without the logo, but when the logo is displayed and a terminal is tiled across half the screen, then the text in each line will wrap, interrupting the logo:

> fastfetch -s monitor:cpu:gpu:sound:camera -l none
Monitor (AUO20EC): 1366x768 px - 344x193 mm (15.53 inches, 100.91 ppi)
CPU: 11th Gen Intel(R) Core(TM) i5-1135G7 (8) @ 4.20 GHz
GPU: Intel Iris Xe Graphics @ 1.30 GHz [Integrated]
Sound: Tiger Lake-LP Smart Sound Technology Audio Controller Speaker (13%)
Camera: HP TrueVision HD Camera: HP Tru - sRGB (640x360 px)

While modifying format strings can fix some of these issues, very long hardware names (like Tiger Lake-LP Smart Sound Technology Audio Controller Speaker) are impossible to fix without removing the information or writing a COMMAND module.

Why this should be added to the format specs

  • While these specific hardware items could have options or fields added to shorten their output, this is just bandaging the larger problem of very long fields.
  • Adding this option to the format specs allows greater flexibility for user freedom. For example, I could truncate the name of playing songs in the media module.
@aarondill aarondill added the enhancement New feature or request label Jun 26, 2024
@CarterLi
Copy link
Member

$ ./fastfetch -l none -s command --command-text 'echo 1234567890' --command-format '{1}'
Command: 1234567890
$ ./fastfetch -l none -s command --command-text 'echo 1234567890' --command-format '{1:5}'
Command: 12345
$ ./fastfetch -l none -s command --command-text 'echo 1234567890' --command-format '{1:-5}'
Command: 12345…
$ ./fastfetch -l none -s command --command-text 'echo 1234567890' --command-format '{:5}'
Command: 12345
$ ./fastfetch -l none -s command --command-text 'echo 1234567890' --command-format '{:-5}'
Command: 12345…
$ ./fastfetch -l none -s command --command-text 'echo 1234567890' --command-format '{:0}'
Command:
$ ./fastfetch -l none -s command --command-text 'echo 1234567890' --command-format '{:}'
Command:

Please test the dev branch

@aarondill
Copy link
Author

@CarterLi This works great! I just have one slight request that I didn't think about in the original issue.
Is it possible to make it trim whitespace after truncating the field?
This way, when using truncation, it looks a bit nicer when truncated on a space.

For example:

$ ./fastfetch -l none -s command --command-text 'echo 12345 67890' --command-format 'output({1})'
Command: output(12345 67890)
$ ./fastfetch -l none -s command --command-text 'echo 12345 67890' --command-format 'output({1:6})'
Command: output(12345)
$ ./fastfetch -l none -s command --command-text 'echo 12345 67890' --command-format 'output({1:-6})'
Command: output(12345…)
$ ./fastfetch -l none -s command --command-text 'echo 12345 67890' --command-format 'output({:6})'
Command: output(12345)
$ ./fastfetch -l none -s command --command-text 'echo 12345 67890' --command-format 'output({:-6})'
Command: output(12345…)
$ ./fastfetch -l none -s command --command-text 'echo 12345 67890' --command-format 'output({:0})'
Command: output()
$ ./fastfetch -l none -s command --command-text 'echo 12345 67890' --command-format 'output({:})'
Command: output()

I don't see any usecase in which someone would want the field to sometimes end in a space, depending on where it truncated.

@CarterLi
Copy link
Member

White spaces can be used for aligning texts

@aarondill
Copy link
Author

@CarterLi wouldn't one want these to be hard coded into the format string then? rather than generated from the truncated fields?

@CarterLi
Copy link
Member

4370c09

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

2 participants