ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/client/javacli/TerminalScreen.java
Revision: 1.4
Committed: Tue May 21 16:47:11 2002 UTC (22 years, 6 months ago) by tdb
Branch: MAIN
Changes since 1.3: +2 -1 lines
Log Message:
Added URL to GPL headers.

File Contents

# User Rev Content
1 tdb 1.3 /*
2 tdb 1.4 * i-scream central monitoring system
3     * http://www.i-scream.org.uk
4 tdb 1.3 * Copyright (C) 2000-2002 i-scream
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     */
20    
21 pjm2 1.2 // pjm2@ukc.ac.uk
22     // class for laying out text in a terminal window. (in Java!)
23     // After hours of fiddling, anything is possible... ;-)
24    
25     public class TerminalScreen {
26    
27     private static final String ESCAPE_SEQUENCE = "[";
28    
29     public static final int BOLD = 1;
30     public static final int BLACK_BG = 7;
31     public static final int BLUE = 34;
32     public static final int PINK = 35;
33     public static final int RED = 31;
34    
35     // No-args constructor.
36     public TerminalScreen() {
37     // reserved.
38     }
39    
40     // Set the cursor position.
41     public void gotoxy(int x, int y) {
42     System.out.print(ESCAPE_SEQUENCE+y+";"+x+"H");
43     }
44    
45     // Print a string at the current position.
46     public void print(String s) {
47     System.out.print(s);
48     }
49    
50     // Print a string at the current position with the
51     // specified colour.
52     public void print(String s, int colour) {
53     System.out.print(ESCAPE_SEQUENCE+colour+"m");
54     System.out.print(s);
55     System.out.print(ESCAPE_SEQUENCE+"0m");
56     }
57    
58     // Print a string at the current position with a specified
59     // foreground and background colour.
60     public void print(String s, int colour, int other) {
61     System.out.print(ESCAPE_SEQUENCE+other+"m");
62     this.print(s, colour);
63     }
64    
65     // Clears the terminal screen and then resets the cursor position.
66     public void clear() {
67     System.out.print(ESCAPE_SEQUENCE+"2J");
68     System.out.print(ESCAPE_SEQUENCE+"1;24r");
69     }
70    
71     // Main method for testing!
72     public static void main(String[] args) throws InterruptedException {
73    
74     TerminalScreen screen = new TerminalScreen();
75    
76     screen.clear();
77    
78     screen.gotoxy(34, 10);
79     screen.print(" i - s c r e a m ", TerminalScreen.BOLD, TerminalScreen.BLACK_BG);
80     screen.gotoxy(27, 12);
81     screen.print("Central Monitoring System Client", TerminalScreen.BLUE);
82     screen.gotoxy(32,13);
83     screen.print("Unix/Linux version 1.0");
84    
85    
86     screen.gotoxy(1,1);
87     screen.print("Top left");
88     screen.gotoxy(79,24);
89     screen.print("E");
90    
91     screen.gotoxy(1,24);
92    
93     Thread.sleep(3000);
94    
95     screen.clear();
96    
97    
98    
99     }
100    
101     }