Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: 1.3
    • Component/s: Help formatter
    • Labels:
      None

      Description

      HelpFormatter could be improved by adjusting automatically its width to the width of the terminal. The width of the terminal can be retrieved by the stty command on unix systems, on Windows it requires a native call. The JLine project on SourceForge already implements this logic.

      http://jline.sourceforge.net

      I suggest to add a setAutoWidth(boolean) method in HelpFormatter that will try to get the terminal width. If it fails it'll fall back to the width provided by getWidth().

        Activity

        Hide
        Emmanuel Bourg added a comment -

        I'm pondering if this feature shouldn't be marked as Won't Fix. The best we can do is to support the feature on Unix only. Supporting Windows means duplicating a part of JLine and getting headaches on the native stuff. And if we can't support Windows it'll be useless. People developing multiplatform applications will use JLine directly, and we would have wasted our time implementing and testing a half baked feature.

        I suggest documenting in a FAQ how to achieve the automatic width and delegate the work to JLine. It's as simple as this:

        HelpFormatter hf = new HelpFormatter();
        hf.setWidth(Math.min(Terminal.getTerminal().getTerminalWidth(), 120));
        
        Show
        Emmanuel Bourg added a comment - I'm pondering if this feature shouldn't be marked as Won't Fix. The best we can do is to support the feature on Unix only. Supporting Windows means duplicating a part of JLine and getting headaches on the native stuff. And if we can't support Windows it'll be useless. People developing multiplatform applications will use JLine directly, and we would have wasted our time implementing and testing a half baked feature. I suggest documenting in a FAQ how to achieve the automatic width and delegate the work to JLine. It's as simple as this: HelpFormatter hf = new HelpFormatter(); hf.setWidth( Math .min(Terminal.getTerminal().getTerminalWidth(), 120));
        Hide
        Jim Jagielski added a comment -

        Just yesterday this was added to 1.3, but yes, for Unix only. As long as it doesn't break anything and provides additional capability, than can be turned on and off, I don't see the harm in having it.

        Show
        Jim Jagielski added a comment - Just yesterday this was added to 1.3, but yes, for Unix only. As long as it doesn't break anything and provides additional capability, than can be turned on and off, I don't see the harm in having it.
        Hide
        Jim Jagielski added a comment -

        HelpFormatter can now conditionally try to attempt to determine the terminal width and adjust, via setAutoWidth(true). Since this is conditional, with a failback to the default width, having this just for Unix (as it is currently) is likely good enough.

        Show
        Jim Jagielski added a comment - HelpFormatter can now conditionally try to attempt to determine the terminal width and adjust, via setAutoWidth(true). Since this is conditional, with a failback to the default width, having this just for Unix (as it is currently) is likely good enough.
        Hide
        Sebb added a comment -

        The code change in r778895 assumes that all non-Windows systems support stty, which is not the case.

        Also, the autoWidth variable should be private.

        I think the Javadoc for setAutoWidth() should mention that it may run a system command.

        However, I'm not sure that it's a good idea to include system calls in library code at all.

        Also, it's not very secure to rely on the PATH to find commands such as sh.

        Show
        Sebb added a comment - The code change in r778895 assumes that all non-Windows systems support stty, which is not the case. Also, the autoWidth variable should be private. I think the Javadoc for setAutoWidth() should mention that it may run a system command. However, I'm not sure that it's a good idea to include system calls in library code at all. Also, it's not very secure to rely on the PATH to find commands such as sh.
        Hide
        Henri Yandell added a comment -

        Agreed. System bad.

        Show
        Henri Yandell added a comment - Agreed. System bad.
        Hide
        Jim Jagielski added a comment -

        So reverse out or provide more docs so people know what they are in for?

        Show
        Jim Jagielski added a comment - So reverse out or provide more docs so people know what they are in for?
        Hide
        Sebb added a comment -

        IMO - reverse out until such time as there is a standard Java way to do this on all systems.
        At which point, I'd suggest setting the default width directly, without relying on the user to setAuthWidth().

        Meanwhile, perhaps one could set the default terminal width from a system property or resource file?

        Otherwise, it's easy enough for the user to call setWidth() themselves.

        Show
        Sebb added a comment - IMO - reverse out until such time as there is a standard Java way to do this on all systems. At which point, I'd suggest setting the default width directly, without relying on the user to setAuthWidth(). Meanwhile, perhaps one could set the default terminal width from a system property or resource file? Otherwise, it's easy enough for the user to call setWidth() themselves.
        Hide
        Jim Jagielski added a comment -

        reverted in r779646

        Show
        Jim Jagielski added a comment - reverted in r779646
        Hide
        Jim Jagielski added a comment -

        Until there is a universal, pure-Java way to do this, we'll wait.

        Show
        Jim Jagielski added a comment - Until there is a universal, pure-Java way to do this, we'll wait.

          People

          • Assignee:
            Jim Jagielski
            Reporter:
            Emmanuel Bourg
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development