--- projects/cms/source/client/javacli/TerminalScreen.java 2001/01/10 18:42:20 1.1 +++ projects/cms/source/client/javacli/TerminalScreen.java 2001/01/14 21:58:11 1.2 @@ -1,81 +1,81 @@ -// pjm2@ukc.ac.uk -// Class for laying out text in a terminal screen in Java! -// After hours of fiddling, it is possible ;-) - -public class TerminalScreen { - - private static final String ESCAPE_SEQUENCE = "["; - - private static final int BOLD = 1; - private static final int BLACK_BG = 7; - private static final int BLUE = 34; - private static final int PINK = 35; - private static final int RED = 31; - - // No-args constructor. - public TerminalScreen() { - // reserved. - } - - // Set the cursor position. - public void gotoxy(int x, int y) { - System.out.print(ESCAPE_SEQUENCE+y+";"+x+"H"); - } - - // Print a string at the current position. - public void print(String s) { - System.out.print(s); - } - - // Print a string at the current position with the - // specified colour. - public void print(String s, int colour) { - System.out.print(ESCAPE_SEQUENCE+colour+"m"); - System.out.print(s); - System.out.print(ESCAPE_SEQUENCE+"0m"); - } - - // Print a string at the current position with a specified - // foreground and background colour. - public void print(String s, int colour, int other) { - System.out.print(ESCAPE_SEQUENCE+other+"m"); - this.print(s, colour); - } - - // Clears the terminal screen and then resets the cursor position. - public void clear() { - System.out.print(ESCAPE_SEQUENCE+"2J"); - System.out.print(ESCAPE_SEQUENCE+"1;24r"); - } - - // Main method for testing! - public static void main(String[] args) throws InterruptedException { - - TerminalScreen screen = new TerminalScreen(); - - screen.clear(); - - screen.gotoxy(34, 10); - screen.print(" i - s c r e a m ", TerminalScreen.BOLD, TerminalScreen.BLACK_BG); - screen.gotoxy(27, 12); - screen.print("Central Monitoring System Client", TerminalScreen.BLUE); - screen.gotoxy(32,13); - screen.print("Unix/Linux version 1.0"); - - - screen.gotoxy(1,1); - screen.print("Top left"); - screen.gotoxy(79,24); - screen.print("E"); - - screen.gotoxy(1,24); - - Thread.sleep(3000); - - screen.clear(); - - - - } - -} +// pjm2@ukc.ac.uk +// class for laying out text in a terminal window. (in Java!) +// After hours of fiddling, anything is possible... ;-) + +public class TerminalScreen { + + private static final String ESCAPE_SEQUENCE = "["; + + public static final int BOLD = 1; + public static final int BLACK_BG = 7; + public static final int BLUE = 34; + public static final int PINK = 35; + public static final int RED = 31; + + // No-args constructor. + public TerminalScreen() { + // reserved. + } + + // Set the cursor position. + public void gotoxy(int x, int y) { + System.out.print(ESCAPE_SEQUENCE+y+";"+x+"H"); + } + + // Print a string at the current position. + public void print(String s) { + System.out.print(s); + } + + // Print a string at the current position with the + // specified colour. + public void print(String s, int colour) { + System.out.print(ESCAPE_SEQUENCE+colour+"m"); + System.out.print(s); + System.out.print(ESCAPE_SEQUENCE+"0m"); + } + + // Print a string at the current position with a specified + // foreground and background colour. + public void print(String s, int colour, int other) { + System.out.print(ESCAPE_SEQUENCE+other+"m"); + this.print(s, colour); + } + + // Clears the terminal screen and then resets the cursor position. + public void clear() { + System.out.print(ESCAPE_SEQUENCE+"2J"); + System.out.print(ESCAPE_SEQUENCE+"1;24r"); + } + + // Main method for testing! + public static void main(String[] args) throws InterruptedException { + + TerminalScreen screen = new TerminalScreen(); + + screen.clear(); + + screen.gotoxy(34, 10); + screen.print(" i - s c r e a m ", TerminalScreen.BOLD, TerminalScreen.BLACK_BG); + screen.gotoxy(27, 12); + screen.print("Central Monitoring System Client", TerminalScreen.BLUE); + screen.gotoxy(32,13); + screen.print("Unix/Linux version 1.0"); + + + screen.gotoxy(1,1); + screen.print("Top left"); + screen.gotoxy(79,24); + screen.print("E"); + + screen.gotoxy(1,24); + + Thread.sleep(3000); + + screen.clear(); + + + + } + +}