0

So I'm writing an application that would output an array of strings, but I would like those strings to be outputted in a very neat columns. The number of those columns depends on the width of the opened Windows console window, as well as the width of the strings themselves, naturally.

An example of what I want would be running dir /w in the Windows command line:

C:\cygwin64>dir /w
 Volume in drive C is 
 Volume Serial Number is 1337-N00B

 Directory of C:\cygwin64

[.]                   [..]                  [bin]                 Cygwin-Terminal.ico   Cygwin.bat
Cygwin.ico            [dev]                 [etc]                 [home]                [lib]
[sbin]                setup-x86_64.exe      [tmp]                 [usr]                 [var]
               4 File(s)      1 081 410 bytes
              11 Dir(s)  311 541 256 192 bytes free

If you go into your console properties and resize the window, you will notice that the dir /w output will always perfectly fit the width of your window.

QUESTION: Is there a native JDK way to do this "easily"? Alternatively, is there an open source library that can do this? If the answer is "no" to both, would you kindly give some pointers on how you would approach this problem?

Note: I'm only interested in the Windows implementation of this, no need for cross-platform solutions.

Pt. Terk
  • 462
  • 4
  • 13
  • I think the part where things printed in the terminal window resize themselves is a special feature of your terminal. Not of the program that produced the output. And for the program to know what size the window has: http://stackoverflow.com/questions/1286461/can-i-find-the-console-width-with-java – zapl Oct 17 '15 at 11:02
  • @zapl, for unix-based systems that is correct, but the Windows console window doesn't resize the text automatically. If you've opened your Windows cmd.exe properties and changed the size, you only get your columns reformatted after you run the `dir /w` command again. Therefore, I believe it's safe to assume that it is indeed the special feature of the program, not the terminal. – Pt. Terk Oct 17 '15 at 11:19
  • Windows 10 has text rewrap like http://askubuntu.com/questions/54995/dynamic-line-wrapping-in-the-gnome-terminal and can finally resize the window by simply resizing it with the mouse. – zapl Oct 17 '15 at 11:22

0 Answers0