Skip to content

Increase word wrap with auto-detected terminal width#109

Merged
amstuta merged 2 commits intoovh:mainfrom
TheoBrigitte:wordwrap-increase
Dec 3, 2025
Merged

Increase word wrap with auto-detected terminal width#109
amstuta merged 2 commits intoovh:mainfrom
TheoBrigitte:wordwrap-increase

Conversation

@TheoBrigitte
Copy link
Contributor

Description

I found it quite difficult to read through some of the output of some commands sometimes, notably the domain-zone get might be quite long, with many entries and very wide entries sometimes, like with the Let's Encrypt and other kind of TXT records. I though this could be improved by making use of the full width available in the terminal window rather than being constrained to 80 columns.

This PR proposes a changes in the way the output is rendered when displaying some markdown content. It does so by trying to read the terminal width and if found use it as word wrap limit, otherwise keep the current behavior of 80 word wrap.

Before

image

note that the table does not end here and continues afterward

After

image

here I can see the entire records table in one go

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have commented my code
  • I updated the documentation by running make doc
  • I ran go mod tidy
  • I have added tests that prove my fix is effective or that my feature works

@TheoBrigitte TheoBrigitte requested a review from a team as a code owner November 29, 2025 01:15
Signed-off-by: Theo Brigitte <theo.brigitte@gmail.com>
wordWrap := 80
termFd := os.Stdout.Fd()
if term.IsTerminal(termFd) {
termWidth, _, _ := term.GetSize(os.Stdout.Fd())
Copy link
Member

Choose a reason for hiding this comment

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

style: could be more compact

Suggested change
termWidth, _, _ := term.GetSize(os.Stdout.Fd())
if termWidth, _, _ := term.GetSize(termFd); termWidth > 0 {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I also missed using termFd here. I've changed that.

// Use 80 characters by default, or the terminal width if available.
wordWrap := 80
termFd := os.Stdout.Fd()
if term.IsTerminal(termFd) {
Copy link
Member

Choose a reason for hiding this comment

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

Limit the scope of termFd:

Suggested change
if term.IsTerminal(termFd) {
if termFd := os.Stdout.Fd(); term.IsTerminal(termFd) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also changed this.

Signed-off-by: Theo Brigitte <theo.brigitte@gmail.com>
Copy link
Collaborator

@amstuta amstuta left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution @TheoBrigitte ! This is a nice improvement :)

@amstuta amstuta merged commit 386cd24 into ovh:main Dec 3, 2025
3 checks passed
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