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

        Emmanuel Bourg created issue -
        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.
        Jim Jagielski made changes -
        Field Original Value New Value
        Assignee Jim Jagielski [ jimjag ]
        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.
        Jim Jagielski made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        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.
        Sebb made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        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.
        Jim Jagielski made changes -
        Status Reopened [ 4 ] Closed [ 6 ]
        Resolution Won't Fix [ 2 ]
        Mark Thomas made changes -
        Workflow jira [ 12436200 ] Default workflow, editable Closed status [ 12601507 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        302d 23h 29m 1 Jim Jagielski 27/May/09 16:00
        Resolved Resolved Reopened Reopened
        5h 57m 1 Sebb 27/May/09 21:57
        Reopened Reopened Closed Closed
        19h 25m 1 Jim Jagielski 28/May/09 17:23

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development