You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Emmanuel Bourg (JIRA)" <ji...@apache.org> on 2008/07/28 17:31:32 UTC

[jira] Created: (CLI-166) Terminal width detection

Terminal width detection
------------------------

                 Key: CLI-166
                 URL: https://issues.apache.org/jira/browse/CLI-166
             Project: Commons CLI
          Issue Type: New Feature
          Components: Help formatter
            Reporter: Emmanuel Bourg
             Fix For: 1.3


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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CLI-166) Terminal width detection

Posted by "Jim Jagielski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-166?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jim Jagielski resolved CLI-166.
-------------------------------

    Resolution: Fixed

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.

> Terminal width detection
> ------------------------
>
>                 Key: CLI-166
>                 URL: https://issues.apache.org/jira/browse/CLI-166
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: Help formatter
>            Reporter: Emmanuel Bourg
>            Assignee: Jim Jagielski
>             Fix For: 1.3
>
>
> 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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CLI-166) Terminal width detection

Posted by "Jim Jagielski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-166?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jim Jagielski updated CLI-166:
------------------------------

    Assignee: Jim Jagielski

> Terminal width detection
> ------------------------
>
>                 Key: CLI-166
>                 URL: https://issues.apache.org/jira/browse/CLI-166
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: Help formatter
>            Reporter: Emmanuel Bourg
>            Assignee: Jim Jagielski
>             Fix For: 1.3
>
>
> 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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CLI-166) Terminal width detection

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12714022#action_12714022 ] 

Sebb commented on CLI-166:
--------------------------

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.

> Terminal width detection
> ------------------------
>
>                 Key: CLI-166
>                 URL: https://issues.apache.org/jira/browse/CLI-166
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: Help formatter
>            Reporter: Emmanuel Bourg
>            Assignee: Jim Jagielski
>             Fix For: 1.3
>
>
> 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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (CLI-166) Terminal width detection

Posted by "Jim Jagielski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-166?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jim Jagielski closed CLI-166.
-----------------------------

    Resolution: Won't Fix

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

> Terminal width detection
> ------------------------
>
>                 Key: CLI-166
>                 URL: https://issues.apache.org/jira/browse/CLI-166
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: Help formatter
>            Reporter: Emmanuel Bourg
>            Assignee: Jim Jagielski
>             Fix For: 1.3
>
>
> 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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CLI-166) Terminal width detection

Posted by "Jim Jagielski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12713556#action_12713556 ] 

Jim Jagielski commented on CLI-166:
-----------------------------------

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.

> Terminal width detection
> ------------------------
>
>                 Key: CLI-166
>                 URL: https://issues.apache.org/jira/browse/CLI-166
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: Help formatter
>            Reporter: Emmanuel Bourg
>             Fix For: 1.3
>
>
> 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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CLI-166) Terminal width detection

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12714004#action_12714004 ] 

Henri Yandell commented on CLI-166:
-----------------------------------

Agreed. System bad.

> Terminal width detection
> ------------------------
>
>                 Key: CLI-166
>                 URL: https://issues.apache.org/jira/browse/CLI-166
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: Help formatter
>            Reporter: Emmanuel Bourg
>            Assignee: Jim Jagielski
>             Fix For: 1.3
>
>
> 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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (CLI-166) Terminal width detection

Posted by "Sebb (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-166?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb reopened CLI-166:
----------------------


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.

> Terminal width detection
> ------------------------
>
>                 Key: CLI-166
>                 URL: https://issues.apache.org/jira/browse/CLI-166
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: Help formatter
>            Reporter: Emmanuel Bourg
>            Assignee: Jim Jagielski
>             Fix For: 1.3
>
>
> 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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CLI-166) Terminal width detection

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12713472#action_12713472 ] 

Emmanuel Bourg commented on CLI-166:
------------------------------------

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:

{code:java}
HelpFormatter hf = new HelpFormatter();
hf.setWidth(Math.min(Terminal.getTerminal().getTerminalWidth(), 120));
{code}

> Terminal width detection
> ------------------------
>
>                 Key: CLI-166
>                 URL: https://issues.apache.org/jira/browse/CLI-166
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: Help formatter
>            Reporter: Emmanuel Bourg
>             Fix For: 1.3
>
>
> 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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CLI-166) Terminal width detection

Posted by "Jim Jagielski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12714042#action_12714042 ] 

Jim Jagielski commented on CLI-166:
-----------------------------------

reverted in r779646

> Terminal width detection
> ------------------------
>
>                 Key: CLI-166
>                 URL: https://issues.apache.org/jira/browse/CLI-166
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: Help formatter
>            Reporter: Emmanuel Bourg
>            Assignee: Jim Jagielski
>             Fix For: 1.3
>
>
> 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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CLI-166) Terminal width detection

Posted by "Jim Jagielski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12714010#action_12714010 ] 

Jim Jagielski commented on CLI-166:
-----------------------------------

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

> Terminal width detection
> ------------------------
>
>                 Key: CLI-166
>                 URL: https://issues.apache.org/jira/browse/CLI-166
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: Help formatter
>            Reporter: Emmanuel Bourg
>            Assignee: Jim Jagielski
>             Fix For: 1.3
>
>
> 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().

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.