Skip to content

max width of markdown is hardcoded, should be configurable #9627

Closed

Description

@smemsh

Description

The maximum width of Markdown renders on the terminal (example: gh pr view output) is currently the lower of the actual terminal width or 120. It should have a configurable maximum rather than being hardcoded, for those of us that prefer narrower paragraphs.

Proposed solution

Suggest to check an environment variable for override of the 120 hardcode. If not present, the existing default 120 will be used. Alternative idea would be a gh config variable.

Environment variable is my preference as it's easy to put in one's shell profile, standard method for many terminal apps, and configures any system without having to run a config command on each one (the usual deposit of shell profile would happen anyways). An example of analogous variable is $MANWIDTH.

Suggested variable name is $GH_MDWIDTH. The GH_ prefix appears to be used by a few other environment variables already.

Additional context

A patch is proposed already at #9626. The previous hardcode of 80 was raised to 120 in #6016.

Activity

  1. added
    enhancement
    on Sep 16, 2024
  2. added
    needs-triage
    on Sep 16, 2024
  3. andyfeller commented on Sep 18, 2024

    @andyfeller
    Contributor

    One of my favorite debatable topics, @smemsh! 😆 In all seriousness, line length or text width is a genuine concern especially as lines longer than 80 characters have been considered as inaccessible by W3C.

    Environment variable is my preference as it's easy to put in one's shell profile, standard method for many terminal apps, and configures any system without having to run a config command on each one (the usual deposit of shell profile would happen anyways). An example of analogous variable is $MANWIDTH.

    Suggested variable name is $GH_MDWIDTH. The GH_ prefix appears to be used by a few other environment variables already.

    I agree if we adopted this we'd want to give users the ability to set it via env var or gh config, also that we prefer prefixing our env vars to avoid conflicting with others.

    Questions

    1. How many commands rendering markdown are in scope?

      All of the following commands render Markdown in different ways:

      • gh gist view
      • gh issue view
      • gh issue view --comments
      • gh pr create
      • gh pr review
      • gh pr view
      • gh pr view --comments
      • gh project view
      • gh reference
      • gh release view
      • gh repo view
      • gh workflow view
    2. Is this contained to gh or to any extension using cli/go-gh?

    3. Does this need to account for offset rendering?

      Some of the commands above specify without indentation, however there are places where content is wrapped but it is indented.

      For example, gh issue view https://github.com/cli/cli/issues/9627 --comments will render the issue body as well as the comments, which are wrapped by text width and indented.

  4. added
    more-info-needed
    on Sep 18, 2024
  5. andyfeller commented on Sep 19, 2024

    @andyfeller
    Contributor

    The only other thought I want to toss out is following more of the $LINES and $COLUMNS conventions used by Bash, lines and cols used by termcap.

    My concern with width nomenclature is that it doesn't convey units where most terminals / shells / CLIs deal in terms of columns and lines.

  6. smemsh commented on Sep 20, 2024

    @smemsh
    ContributorAuthor

    One of my favorite debatable topics

    It becomes less controversial when it's only opt-in, user-settable, and we don't change the existing default.

    lines longer than 80 characters have been considered as inaccessible by W3C

    (If only that applied to source code lines! 😉)

    How many commands rendering markdown are in scope? All of the following commands render Markdown in different ways

    It would be all callers of markdown.Render() that pass markdown.WithWrap(), which is where my proposed patch applies. Your list is correct, but they don't render differently that I can tell, they all pass markdown.WithWrap() and all pass terminal width, except workflow/view/view.go is passing 0 as the wrap width, which means "don't wrap at all," because that use case probably knows better. Likewise root/help_reference.go passes terminal width if a tty, else wrap 0. And I don't think --comments variants render any differently, they just show all rather than only the last comment.

    (Aside: none of the commands wrap anyways if output isn't a terminal -- for example, is a pager -- which is really a bug, it should only consider whether stdin is a tty, not stdout. But that would be a separate issue.)

    Terminals are already of variable width, and some people do still use 80 column terminals (perhaps tiling them). Those people will get the 80 column behavior without any changes, so they already encounter whatever issues that width would have. This proposal is only for people that want to set an upper limit, despite their terminal width.

    Does this need to account for offset rendering? Some of the commands above specify without indentation, however there are places where content is wrapped but it is indented.

    It seems to already work correctly, for example if I set width 40 then all the right margins align the same, including comments and accounting for indent. There's a couple stray miswraps like this (shown here with 60):

      │ Environment variable is my preference as it's easy to
      │ put in one's shell profile, standard method for many
      │ terminal apps, and configures any system without
      having
      │ to run a config command on each one (the usual deposit
      │ of shell profile would happen anyways). An example of
      │ analogous variable is $MANWIDTH.Suggested variable
      name
      │ is $GH_MDWIDTH. The GH_ prefix appears to be used by a
      │ few other environment variables already.
    

    but those already exist, I see one with it set to 80, and also at 120 (ie without changing anything), and none at 40, so there is probably a math error in there somewhere, or like you said somewhere not accounting for indentation. But it's already there, and I would consider it a separate issue. I don't think the patch as written introduces any new bugs, and is opt-in. It only allows to override a hardcode which is somewhat arbitrary.

    Is this contained to gh or to any extension using cli/go-gh?

    The former. I'm only proposing to change this particular user of ghMarkdown.WithWrap(), not within go-gh.

    [use some naming based on the idea of columns rather than width]

    Yeah, I did show the precedent of $MANWIDTH, but I'm indifferent to the naming and we can change it to anything that works. Personally I think "width" is more descriptive of what's going on. It's a terminal, so we already know that the addressing dimensions are lines and columns of character cells. That said, any naming scheme works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementmore-info-neededneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions