ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/client/javacli/TerminalScreen.java
Revision: 1.3
Committed: Sat May 18 18:15:56 2002 UTC (22 years, 6 months ago) by tdb
Branch: MAIN
Changes since 1.2: +19 -0 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

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