ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/client/javacli/TerminalScreen.java
(Generate patch)

Comparing projects/cms/source/client/javacli/TerminalScreen.java (file contents):
Revision 1.1 by pjm2, Wed Jan 10 18:42:20 2001 UTC vs.
Revision 1.3 by tdb, Sat May 18 18:15:56 2002 UTC

# Line 1 | Line 1
1 < // pjm2@ukc.ac.uk
2 < // Class for laying out text in a terminal screen in Java!
3 < // After hours of fiddling, it is possible ;-)
4 <
5 < public class TerminalScreen {
6 <    
7 <    private static final String ESCAPE_SEQUENCE = "[";
8 <    
9 <    private static final int BOLD = 1;
10 <    private static final int BLACK_BG = 7;
11 <    private static final int BLUE = 34;
12 <    private static final int PINK = 35;
13 <    private static final int RED = 31;
14 <
15 <    // No-args constructor.
16 <    public TerminalScreen() {
17 <        // reserved.
18 <    }
19 <    
20 <    // Set the cursor position.
21 <    public void gotoxy(int x, int y) {
22 <        System.out.print(ESCAPE_SEQUENCE+y+";"+x+"H");
23 <    }
24 <    
25 <    // Print a string at the current position.
26 <    public void print(String s) {
27 <        System.out.print(s);
28 <    }
29 <    
30 <    // Print a string at the current position with the
31 <    // specified colour.
32 <    public void print(String s, int colour) {
33 <        System.out.print(ESCAPE_SEQUENCE+colour+"m");
34 <        System.out.print(s);
35 <        System.out.print(ESCAPE_SEQUENCE+"0m");
36 <    }
37 <
38 <    // Print a string at the current position with a specified
39 <    // foreground and background colour.
40 <    public void print(String s, int colour, int other) {
41 <        System.out.print(ESCAPE_SEQUENCE+other+"m");
42 <        this.print(s, colour);
43 <    }
44 <    
45 <    // Clears the terminal screen and then resets the cursor position.
46 <    public void clear() {
47 <        System.out.print(ESCAPE_SEQUENCE+"2J");
48 <        System.out.print(ESCAPE_SEQUENCE+"1;24r");
49 <    }
50 <    
51 <    // Main method for testing!
52 <    public static void main(String[] args) throws InterruptedException {
53 <        
54 <        TerminalScreen screen = new TerminalScreen();
55 <    
56 <        screen.clear();
57 <        
58 <        screen.gotoxy(34, 10);
59 <        screen.print(" i - s c r e a m ", TerminalScreen.BOLD, TerminalScreen.BLACK_BG);
60 <        screen.gotoxy(27, 12);
61 <        screen.print("Central Monitoring System Client", TerminalScreen.BLUE);
62 <        screen.gotoxy(32,13);
63 <        screen.print("Unix/Linux version 1.0");
64 <        
65 <        
66 <        screen.gotoxy(1,1);
67 <        screen.print("Top left");
68 <        screen.gotoxy(79,24);
69 <        screen.print("E");
70 <        
71 <        screen.gotoxy(1,24);
72 <        
73 <        Thread.sleep(3000);
74 <        
75 <        screen.clear();
76 <        
77 <        
78 <        
79 <    }
80 <    
81 < }
1 > /*
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@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 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines