52938
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2016, the original author or authors.
|
|
3 |
*
|
|
4 |
* This software is distributable under the BSD license. See the terms of the
|
|
5 |
* BSD license in the documentation provided with this software.
|
|
6 |
*
|
58903
|
7 |
* https://opensource.org/licenses/BSD-3-Clause
|
52938
|
8 |
*/
|
|
9 |
package jdk.internal.org.jline.terminal.impl;
|
|
10 |
|
|
11 |
import java.io.IOError;
|
|
12 |
import java.io.IOException;
|
|
13 |
import java.nio.charset.Charset;
|
|
14 |
import java.util.Objects;
|
|
15 |
import java.util.function.IntConsumer;
|
|
16 |
|
|
17 |
import jdk.internal.org.jline.terminal.Attributes;
|
|
18 |
import jdk.internal.org.jline.terminal.Cursor;
|
|
19 |
import jdk.internal.org.jline.terminal.Size;
|
|
20 |
import jdk.internal.org.jline.terminal.spi.Pty;
|
|
21 |
|
|
22 |
public abstract class AbstractPosixTerminal extends AbstractTerminal {
|
|
23 |
|
|
24 |
protected final Pty pty;
|
|
25 |
protected final Attributes originalAttributes;
|
|
26 |
|
|
27 |
public AbstractPosixTerminal(String name, String type, Pty pty) throws IOException {
|
|
28 |
this(name, type, pty, null, SignalHandler.SIG_DFL);
|
|
29 |
}
|
|
30 |
|
|
31 |
public AbstractPosixTerminal(String name, String type, Pty pty, Charset encoding, SignalHandler signalHandler) throws IOException {
|
|
32 |
super(name, type, encoding, signalHandler);
|
|
33 |
Objects.requireNonNull(pty);
|
|
34 |
this.pty = pty;
|
|
35 |
this.originalAttributes = this.pty.getAttr();
|
|
36 |
}
|
|
37 |
|
|
38 |
public Pty getPty() {
|
|
39 |
return pty;
|
|
40 |
}
|
|
41 |
|
|
42 |
public Attributes getAttributes() {
|
|
43 |
try {
|
|
44 |
return pty.getAttr();
|
|
45 |
} catch (IOException e) {
|
|
46 |
throw new IOError(e);
|
|
47 |
}
|
|
48 |
}
|
|
49 |
|
|
50 |
public void setAttributes(Attributes attr) {
|
|
51 |
try {
|
|
52 |
pty.setAttr(attr);
|
|
53 |
} catch (IOException e) {
|
|
54 |
throw new IOError(e);
|
|
55 |
}
|
|
56 |
}
|
|
57 |
|
|
58 |
public Size getSize() {
|
|
59 |
try {
|
|
60 |
return pty.getSize();
|
|
61 |
} catch (IOException e) {
|
|
62 |
throw new IOError(e);
|
|
63 |
}
|
|
64 |
}
|
|
65 |
|
|
66 |
public void setSize(Size size) {
|
|
67 |
try {
|
|
68 |
pty.setSize(size);
|
|
69 |
} catch (IOException e) {
|
|
70 |
throw new IOError(e);
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
public void close() throws IOException {
|
|
75 |
super.close();
|
|
76 |
pty.setAttr(originalAttributes);
|
|
77 |
pty.close();
|
|
78 |
}
|
|
79 |
|
|
80 |
@Override
|
|
81 |
public Cursor getCursorPosition(IntConsumer discarded) {
|
|
82 |
return CursorSupport.getCursorPosition(this, discarded);
|
|
83 |
}
|
|
84 |
|
|
85 |
}
|