1
2
3
4
5
6
7
8
9 package jline;
10
11 import java.io.IOException;
12 import java.io.InputStream;
13 import java.io.OutputStream;
14
15 import jline.internal.Log;
16 import jline.internal.ShutdownHooks;
17 import jline.internal.ShutdownHooks.Task;
18
19
20
21
22
23
24
25 public abstract class TerminalSupport
26 implements Terminal
27 {
28 public static final int DEFAULT_WIDTH = 80;
29
30 public static final int DEFAULT_HEIGHT = 24;
31
32 private Task shutdownTask;
33
34 private boolean supported;
35
36 private boolean echoEnabled;
37
38 private boolean ansiSupported;
39
40 protected TerminalSupport(final boolean supported) {
41 this.supported = supported;
42 }
43
44 public void init() throws Exception {
45 if (shutdownTask != null) {
46 ShutdownHooks.remove(shutdownTask);
47 }
48
49 this.shutdownTask = ShutdownHooks.add(new Task()
50 {
51 public void run() throws Exception {
52 restore();
53 }
54 });
55 }
56
57 public void restore() throws Exception {
58 TerminalFactory.resetIf(this);
59 if (shutdownTask != null) {
60 ShutdownHooks.remove(shutdownTask);
61 shutdownTask = null;
62 }
63 }
64
65 public void reset() throws Exception {
66 restore();
67 init();
68 }
69
70 public final boolean isSupported() {
71 return supported;
72 }
73
74 public synchronized boolean isAnsiSupported() {
75 return ansiSupported;
76 }
77
78 protected synchronized void setAnsiSupported(final boolean supported) {
79 this.ansiSupported = supported;
80 Log.debug("Ansi supported: ", supported);
81 }
82
83
84
85
86
87 public OutputStream wrapOutIfNeeded(OutputStream out) {
88 return out;
89 }
90
91
92
93
94 public boolean hasWeirdWrap() {
95 return true;
96 }
97
98 public int getWidth() {
99 return DEFAULT_WIDTH;
100 }
101
102 public int getHeight() {
103 return DEFAULT_HEIGHT;
104 }
105
106 public synchronized boolean isEchoEnabled() {
107 return echoEnabled;
108 }
109
110 public synchronized void setEchoEnabled(final boolean enabled) {
111 this.echoEnabled = enabled;
112 Log.debug("Echo enabled: ", enabled);
113 }
114
115 public InputStream wrapInIfNeeded(InputStream in) throws IOException {
116 return in;
117 }
118
119 public String getOutputEncoding() {
120
121 return null;
122 }
123 }