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.4 by tdb, Tue May 21 16:47:11 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 > * http://www.i-scream.org.uk
4 > * 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@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 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines