Skip to content

Commit 9d4fc43

Browse files
committed
refactor: removed TerminalBase because of build issues
1 parent 36d8712 commit 9d4fc43

6 files changed

Lines changed: 305 additions & 206 deletions

File tree

miniterm-ffm/pom.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,6 @@
6969
<release>22</release>
7070
</configuration>
7171
</plugin>
72-
<plugin>
73-
<groupId>org.codehaus.mojo</groupId>
74-
<artifactId>build-helper-maven-plugin</artifactId>
75-
<executions>
76-
<execution>
77-
<id>add-shared-sources</id>
78-
<phase>generate-sources</phase>
79-
<goals>
80-
<goal>add-source</goal>
81-
</goals>
82-
<configuration>
83-
<sources>
84-
<source>${project.basedir}/../src/main/java</source>
85-
</sources>
86-
</configuration>
87-
</execution>
88-
</executions>
89-
</plugin>
9072
<plugin>
9173
<groupId>org.apache.maven.plugins</groupId>
9274
<artifactId>maven-jar-plugin</artifactId>

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

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,165 @@
55
package org.codejive.miniterm;
66

77
import java.io.IOException;
8+
import java.nio.charset.Charset;
9+
import java.util.function.Consumer;
810

911
/**
1012
* Platform-independent terminal operations interface.
1113
*
1214
* <p>This interface abstracts the low-level terminal operations that differ between Unix
1315
* (Linux/macOS) and Windows platforms.
1416
*/
15-
public interface Terminal extends TerminalBase {
17+
public interface Terminal extends Appendable, AutoCloseable {
18+
19+
/**
20+
* Enables raw mode on the terminal.
21+
*
22+
* <p>Raw mode disables line buffering, echo, and special character processing, allowing direct
23+
* character-by-character input.
24+
*
25+
* @throws IOException if raw mode cannot be enabled
26+
*/
27+
void enableRawMode() throws IOException;
28+
29+
/**
30+
* Disables raw mode and restores original terminal attributes.
31+
*
32+
* @throws IOException if raw mode cannot be disabled
33+
*/
34+
void disableRawMode() throws IOException;
35+
36+
/**
37+
* Gets the current terminal size.
38+
*
39+
* @return the terminal size
40+
* @throws IOException if the size cannot be determined
41+
*/
42+
Size size() throws IOException;
43+
44+
/**
45+
* Reads a single character from the terminal with timeout.
46+
*
47+
* @param timeoutMs timeout in milliseconds (-1 for infinite, 0 for non-blocking)
48+
* @return the character read, -1 for EOF, or -2 for timeout
49+
* @throws IOException if reading fails
50+
*/
51+
int read(int timeoutMs) throws IOException;
52+
53+
/**
54+
* Peeks at the next character without consuming it.
55+
*
56+
* @param timeoutMs timeout in milliseconds
57+
* @return the character peeked, -1 for EOF, or -2 for timeout
58+
* @throws IOException if reading fails
59+
*/
60+
int peek(int timeoutMs) throws IOException;
61+
62+
/**
63+
* Writes data to the terminal.
64+
*
65+
* @param data the data to write
66+
* @throws IOException if writing fails
67+
*/
68+
void write(byte[] data) throws IOException;
69+
70+
/**
71+
* Writes a portion of a byte array to the terminal.
72+
*
73+
* <p>This method allows writing from a reusable buffer without creating intermediate byte array
74+
* copies.
75+
*
76+
* @param buffer the byte array containing data
77+
* @param offset the start offset in the buffer
78+
* @param length the number of bytes to write
79+
* @throws IOException if writing fails
80+
*/
81+
void write(byte[] buffer, int offset, int length) throws IOException;
82+
83+
/**
84+
* Writes a string to the terminal.
85+
*
86+
* @param s the string to write
87+
* @throws IOException if writing fails
88+
*/
89+
void write(String s) throws IOException;
90+
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+
109+
/**
110+
* Returns the charset used for terminal I/O.
111+
*
112+
* @return the terminal charset
113+
*/
114+
Charset charset();
115+
116+
/**
117+
* Checks if raw mode is currently enabled.
118+
*
119+
* @return true if raw mode is enabled
120+
*/
121+
boolean rawModeEnabled();
122+
123+
/**
124+
* Registers a handler to be called when the terminal is resized.
125+
*
126+
* @param handler the handler to call on resize, or null to remove
127+
*/
128+
void onResize(Consumer<Size> handler);
129+
130+
/**
131+
* Closes the terminal and releases resources.
132+
*
133+
* @throws IOException if closing fails
134+
*/
135+
@Override
136+
void close() throws IOException;
137+
138+
public static class Size {
139+
140+
public final int height;
141+
public final int width;
142+
143+
public Size(int width, int height) {
144+
this.width = width;
145+
this.height = height;
146+
}
147+
148+
@Override
149+
public boolean equals(Object o) {
150+
if (this == o) return true;
151+
if (o == null || getClass() != o.getClass()) return false;
152+
Size size = (Size) o;
153+
if (height != size.height) return false;
154+
return width == size.width;
155+
}
156+
157+
@Override
158+
public int hashCode() {
159+
return 31 * height + width;
160+
}
161+
162+
@Override
163+
public String toString() {
164+
return width + "x" + height;
165+
}
166+
}
16167

17168
/**
18169
* Factory method to create a Terminal for the current platform using FFM (Java 22+).

miniterm/pom.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,6 @@
4949
<release>8</release>
5050
</configuration>
5151
</plugin>
52-
<plugin>
53-
<groupId>org.codehaus.mojo</groupId>
54-
<artifactId>build-helper-maven-plugin</artifactId>
55-
<executions>
56-
<execution>
57-
<id>add-shared-sources</id>
58-
<phase>generate-sources</phase>
59-
<goals>
60-
<goal>add-source</goal>
61-
</goals>
62-
<configuration>
63-
<sources>
64-
<source>${project.basedir}/../src/main/java</source>
65-
</sources>
66-
</configuration>
67-
</execution>
68-
</executions>
69-
</plugin>
7052
<plugin>
7153
<groupId>org.apache.maven.plugins</groupId>
7254
<artifactId>maven-jar-plugin</artifactId>

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

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,165 @@
55
package org.codejive.miniterm;
66

77
import java.io.IOException;
8+
import java.nio.charset.Charset;
9+
import java.util.function.Consumer;
810

911
/**
1012
* Platform-independent terminal operations interface.
1113
*
1214
* <p>This interface abstracts the low-level terminal operations that differ between Unix
1315
* (Linux/macOS) and Windows platforms.
1416
*/
15-
public interface Terminal extends TerminalBase {
17+
public interface Terminal extends Appendable, AutoCloseable {
18+
19+
/**
20+
* Enables raw mode on the terminal.
21+
*
22+
* <p>Raw mode disables line buffering, echo, and special character processing, allowing direct
23+
* character-by-character input.
24+
*
25+
* @throws IOException if raw mode cannot be enabled
26+
*/
27+
void enableRawMode() throws IOException;
28+
29+
/**
30+
* Disables raw mode and restores original terminal attributes.
31+
*
32+
* @throws IOException if raw mode cannot be disabled
33+
*/
34+
void disableRawMode() throws IOException;
35+
36+
/**
37+
* Gets the current terminal size.
38+
*
39+
* @return the terminal size
40+
* @throws IOException if the size cannot be determined
41+
*/
42+
Size size() throws IOException;
43+
44+
/**
45+
* Reads a single character from the terminal with timeout.
46+
*
47+
* @param timeoutMs timeout in milliseconds (-1 for infinite, 0 for non-blocking)
48+
* @return the character read, -1 for EOF, or -2 for timeout
49+
* @throws IOException if reading fails
50+
*/
51+
int read(int timeoutMs) throws IOException;
52+
53+
/**
54+
* Peeks at the next character without consuming it.
55+
*
56+
* @param timeoutMs timeout in milliseconds
57+
* @return the character peeked, -1 for EOF, or -2 for timeout
58+
* @throws IOException if reading fails
59+
*/
60+
int peek(int timeoutMs) throws IOException;
61+
62+
/**
63+
* Writes data to the terminal.
64+
*
65+
* @param data the data to write
66+
* @throws IOException if writing fails
67+
*/
68+
void write(byte[] data) throws IOException;
69+
70+
/**
71+
* Writes a portion of a byte array to the terminal.
72+
*
73+
* <p>This method allows writing from a reusable buffer without creating intermediate byte array
74+
* copies.
75+
*
76+
* @param buffer the byte array containing data
77+
* @param offset the start offset in the buffer
78+
* @param length the number of bytes to write
79+
* @throws IOException if writing fails
80+
*/
81+
void write(byte[] buffer, int offset, int length) throws IOException;
82+
83+
/**
84+
* Writes a string to the terminal.
85+
*
86+
* @param s the string to write
87+
* @throws IOException if writing fails
88+
*/
89+
void write(String s) throws IOException;
90+
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+
109+
/**
110+
* Returns the charset used for terminal I/O.
111+
*
112+
* @return the terminal charset
113+
*/
114+
Charset charset();
115+
116+
/**
117+
* Checks if raw mode is currently enabled.
118+
*
119+
* @return true if raw mode is enabled
120+
*/
121+
boolean rawModeEnabled();
122+
123+
/**
124+
* Registers a handler to be called when the terminal is resized.
125+
*
126+
* @param handler the handler to call on resize, or null to remove
127+
*/
128+
void onResize(Consumer<Size> handler);
129+
130+
/**
131+
* Closes the terminal and releases resources.
132+
*
133+
* @throws IOException if closing fails
134+
*/
135+
@Override
136+
void close() throws IOException;
137+
138+
public static class Size {
139+
140+
public final int height;
141+
public final int width;
142+
143+
public Size(int width, int height) {
144+
this.width = width;
145+
this.height = height;
146+
}
147+
148+
@Override
149+
public boolean equals(Object o) {
150+
if (this == o) return true;
151+
if (o == null || getClass() != o.getClass()) return false;
152+
Size size = (Size) o;
153+
if (height != size.height) return false;
154+
return width == size.width;
155+
}
156+
157+
@Override
158+
public int hashCode() {
159+
return 31 * height + width;
160+
}
161+
162+
@Override
163+
public String toString() {
164+
return width + "x" + height;
165+
}
166+
}
16167

17168
/**
18169
* Factory method to create a Terminal for the current platform.

mousetrack/src/main/java/org/codejive/miniterm/mousetrack/MouseTracking.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private MouseTracking() {}
165165
*
166166
* <p>Sends {@code ESC [ ? <n> h} to {@code out}.
167167
*
168-
* @param out the terminal's output (typically the {@code TerminalBase} / {@code Appendable}
168+
* @param out the terminal's output (typically the {@code Terminal} / {@code Appendable}
169169
* connected to the TTY)
170170
* @param protocol the tracking protocol to enable
171171
* @throws IOException if writing to {@code out} fails

0 commit comments

Comments
 (0)