Skip to content

Commit dc33474

Browse files
committed
feat: made Terminal implement Appendable
1 parent 3623921 commit dc33474

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

miniterm-ffm/src/main/java/org/codejive/miniterm/Terminal.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* <p>This interface abstracts the low-level terminal operations that differ between Unix
1515
* (Linux/macOS) and Windows platforms.
1616
*/
17-
public interface Terminal extends AutoCloseable {
17+
public interface Terminal extends Appendable, AutoCloseable {
1818

1919
/**
2020
* Enables raw mode on the terminal.
@@ -88,6 +88,24 @@ public interface Terminal extends AutoCloseable {
8888
*/
8989
void write(String s) throws IOException;
9090

91+
@Override
92+
default Appendable append(char c) throws IOException {
93+
write(new byte[] {(byte) c});
94+
return this;
95+
}
96+
97+
@Override
98+
default Appendable append(CharSequence csq) throws IOException {
99+
write(csq.toString());
100+
return this;
101+
}
102+
103+
@Override
104+
default Appendable append(CharSequence csq, int start, int end) throws IOException {
105+
write(csq.subSequence(start, end).toString());
106+
return this;
107+
}
108+
91109
/**
92110
* Returns the charset used for terminal I/O.
93111
*

miniterm/src/main/java/org/codejive/miniterm/Terminal.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* <p>This interface abstracts the low-level terminal operations that differ between Unix
1515
* (Linux/macOS) and Windows platforms.
1616
*/
17-
public interface Terminal extends AutoCloseable {
17+
public interface Terminal extends Appendable, AutoCloseable {
1818

1919
/**
2020
* Enables raw mode on the terminal.
@@ -88,6 +88,24 @@ public interface Terminal extends AutoCloseable {
8888
*/
8989
void write(String s) throws IOException;
9090

91+
@Override
92+
default Appendable append(char c) throws IOException {
93+
write(new byte[] {(byte) c});
94+
return this;
95+
}
96+
97+
@Override
98+
default Appendable append(CharSequence csq) throws IOException {
99+
write(csq.toString());
100+
return this;
101+
}
102+
103+
@Override
104+
default Appendable append(CharSequence csq, int start, int end) throws IOException {
105+
write(csq.subSequence(start, end).toString());
106+
return this;
107+
}
108+
91109
/**
92110
* Returns the charset used for terminal I/O.
93111
*

0 commit comments

Comments
 (0)