com.gridsystems.config.tools.console
Class ConsoleTools

java.lang.Object
  extended by com.gridsystems.config.tools.console.ConsoleTools

public final class ConsoleTools
extends java.lang.Object

Helper functions for console interaction.

Version:
1.0
Author:
Rodrigo Ruiz Aguayo

Method Summary
static java.lang.String center(java.lang.String s, int width)
          Centers s in a line of "width" characters by adding spaces to its left.
static void clear()
          Clears the screen.
static void fill(java.lang.StringBuffer sb, char c, int count)
          Adds count characters "c" to the end of sb.
static void paintBox(java.lang.String title, java.lang.Object[] contents, int width)
          Displays a bordered box in the console, with the specified title, contents and width.
static java.lang.String readLine(java.lang.String prompt)
          Reads a line of text from the console.
static java.lang.String readPassword(java.lang.String prompt, char replaceChar)
          Reads a line, masking the typed characters so they are not visible for casual observers.
static void setup(boolean ansi, boolean acs)
          Sets the console configuration regarding to ANSI compliance and Alternate Character Set support.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setup

public static void setup(boolean ansi,
                         boolean acs)
Sets the console configuration regarding to ANSI compliance and Alternate Character Set support.

Parameters:
ansi - true if the console supports ANSI escape sequences
acs - true if the console supports ACS for line-drawing

clear

public static void clear()
Clears the screen. It works far better in an ANSI compliant terminal.


readLine

public static java.lang.String readLine(java.lang.String prompt)
                                 throws java.io.IOException
Reads a line of text from the console.

Parameters:
prompt - The user prompt
Returns:
The typed text
Throws:
java.io.IOException - In case of I/O error

readPassword

public static java.lang.String readPassword(java.lang.String prompt,
                                            char replaceChar)
                                     throws java.io.IOException
Reads a line, masking the typed characters so they are not visible for casual observers.

Parameters:
prompt - The prompt for the user
replaceChar - The character to show instead of the typed ones
Returns:
The typed text
Throws:
java.io.IOException - In case of I/O error

fill

public static void fill(java.lang.StringBuffer sb,
                        char c,
                        int count)
Adds count characters "c" to the end of sb.

Parameters:
sb - The buffer to fill
c - The character to add
count - The number of characters to add

center

public static java.lang.String center(java.lang.String s,
                                      int width)
Centers s in a line of "width" characters by adding spaces to its left.

Parameters:
s - The string to center
width - The width of the line in characters
Returns:
The padded version of s

paintBox

public static void paintBox(java.lang.String title,
                            java.lang.Object[] contents,
                            int width)
Displays a bordered box in the console, with the specified title, contents and width.

Parameters:
title - The box title
contents - The box contents
width - The box width in characters


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.