Skip to content

Commit 4c8c0d5

Browse files
committed
build: now sharing common code between miniterm and miniterm-ffm
1 parent dc33474 commit 4c8c0d5

6 files changed

Lines changed: 230 additions & 304 deletions

File tree

miniterm-ffm/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@
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>
7290
<plugin>
7391
<groupId>org.apache.maven.plugins</groupId>
7492
<artifactId>maven-jar-plugin</artifactId>

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

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

77
import java.io.IOException;
8-
import java.nio.charset.Charset;
9-
import java.util.function.Consumer;
108

119
/**
1210
* Platform-independent terminal operations interface.
1311
*
1412
* <p>This interface abstracts the low-level terminal operations that differ between Unix
1513
* (Linux/macOS) and Windows platforms.
1614
*/
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 getSize() 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 getCharset();
115-
116-
/**
117-
* Checks if raw mode is currently enabled.
118-
*
119-
* @return true if raw mode is enabled
120-
*/
121-
boolean isRawModeEnabled();
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;
15+
public interface Terminal extends TerminalBase {
13716

13817
/**
13918
* Factory method to create a Terminal for the current platform using FFM (Java 22+).
@@ -175,34 +54,4 @@ public static Terminal create() throws IOException {
17554
throw new IOException(
17655
"Failed to create terminal for platform: " + System.getProperty("os.name"), last);
17756
}
178-
179-
public static class Size {
180-
181-
public final int height;
182-
public final int width;
183-
184-
public Size(int width, int height) {
185-
this.width = width;
186-
this.height = height;
187-
}
188-
189-
@Override
190-
public boolean equals(Object o) {
191-
if (this == o) return true;
192-
if (o == null || getClass() != o.getClass()) return false;
193-
Size size = (Size) o;
194-
if (height != size.height) return false;
195-
return width == size.width;
196-
}
197-
198-
@Override
199-
public int hashCode() {
200-
return 31 * height + width;
201-
}
202-
203-
@Override
204-
public String toString() {
205-
return width + "x" + height;
206-
}
207-
}
20857
}

miniterm/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@
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>
5270
<plugin>
5371
<groupId>org.apache.maven.plugins</groupId>
5472
<artifactId>maven-jar-plugin</artifactId>

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

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

77
import java.io.IOException;
8-
import java.nio.charset.Charset;
9-
import java.util.function.Consumer;
108

119
/**
1210
* Platform-independent terminal operations interface.
1311
*
1412
* <p>This interface abstracts the low-level terminal operations that differ between Unix
1513
* (Linux/macOS) and Windows platforms.
1614
*/
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 getSize() 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 getCharset();
115-
116-
/**
117-
* Checks if raw mode is currently enabled.
118-
*
119-
* @return true if raw mode is enabled
120-
*/
121-
boolean isRawModeEnabled();
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;
15+
public interface Terminal extends TerminalBase {
13716

13817
/**
13918
* Factory method to create a Terminal for the current platform.
@@ -175,34 +54,4 @@ public static Terminal create() throws IOException {
17554
throw new IOException(
17655
"Failed to create terminal for platform: " + System.getProperty("os.name"), last);
17756
}
178-
179-
public static class Size {
180-
181-
public final int height;
182-
public final int width;
183-
184-
public Size(int width, int height) {
185-
this.width = width;
186-
this.height = height;
187-
}
188-
189-
@Override
190-
public boolean equals(Object o) {
191-
if (this == o) return true;
192-
if (o == null || getClass() != o.getClass()) return false;
193-
Size size = (Size) o;
194-
if (height != size.height) return false;
195-
return width == size.width;
196-
}
197-
198-
@Override
199-
public int hashCode() {
200-
return 31 * height + width;
201-
}
202-
203-
@Override
204-
public String toString() {
205-
return width + "x" + height;
206-
}
207-
}
20857
}

0 commit comments

Comments
 (0)