Skip to content

Commit bfb9885

Browse files
committed
updates to reflect the new api changes
1 parent dcb48e9 commit bfb9885

6 files changed

Lines changed: 150 additions & 22 deletions

File tree

content/docs/readline/clipboard.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ readline.readline(connection, new Prompt("$ "), input -> {
144144
}, null, null, null, null, flags);
145145
```
146146

147+
Or more concisely with `ReadlineRequest` and `ReadlineFlags`:
148+
149+
```java
150+
import org.aesh.readline.ReadlineRequest;
151+
import org.aesh.readline.ReadlineFlags;
152+
153+
readline.readline(ReadlineRequest.builder()
154+
.connection(connection)
155+
.prompt("$ ")
156+
.requestHandler(input -> { /* handle input */ })
157+
.flags(ReadlineFlags.of(ReadlineFlag.NO_CLIPBOARD))
158+
.build());
159+
```
160+
147161
## Manual Usage
148162

149163
For applications that manage their own rendering (outside of `Readline`), use the `Connection` method directly:

content/docs/readline/connectivity.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ public class WebTerminal {
416416

417417
public static synchronized void main(String[] args) throws Exception {
418418
NettyWebsocketTtyBootstrap bootstrap = new NettyWebsocketTtyBootstrap()
419-
.setHost("localhost")
420-
.setPort(8080);
419+
.host("localhost")
420+
.port(8080);
421421

422422
bootstrap.start(WebTerminal::handleConnection).get(10, TimeUnit.SECONDS);
423423

@@ -451,10 +451,10 @@ public class WebTerminal {
451451

452452
| Method | Type | Description |
453453
|--------|------|-------------|
454-
| `setHost(String)` | `String` | Bind address (default: "localhost") |
455-
| `setPort(int)` | `int` | HTTP port (default: 8080) |
456-
| `setResourcePath(String)` | `String` | Classpath path for static files (default: "/org/aesh/terminal/http") |
457-
| `setServeStaticFiles(boolean)` | `boolean` | Enable/disable static file serving (default: true) |
454+
| `host(String)` | `String` | Bind address (default: "localhost") |
455+
| `port(int)` | `int` | HTTP port (default: 8080) |
456+
| `resourcePath(String)` | `String` | Classpath path for static files (default: "/org/aesh/terminal/http") |
457+
| `serveStaticFiles(boolean)` | `boolean` | Enable/disable static file serving (default: true) |
458458

459459
The WebSocket endpoint is always available at `/ws`.
460460

@@ -465,9 +465,9 @@ By default, terminal-http serves a built-in HTML page with xterm.js. To use your
465465
```java
466466
// Use custom resources from your classpath
467467
NettyWebsocketTtyBootstrap bootstrap = new NettyWebsocketTtyBootstrap()
468-
.setHost("localhost")
469-
.setPort(8080)
470-
.setResourcePath("/com/myapp/web"); // Your classpath location
468+
.host("localhost")
469+
.port(8080)
470+
.resourcePath("/com/myapp/web"); // Your classpath location
471471
```
472472

473473
Place your `index.html` at `src/main/resources/com/myapp/web/index.html`.
@@ -510,9 +510,9 @@ For applications that serve HTML from a separate web server:
510510
```java
511511
// Disable static file serving - only handle WebSocket at /ws
512512
NettyWebsocketTtyBootstrap bootstrap = new NettyWebsocketTtyBootstrap()
513-
.setHost("localhost")
514-
.setPort(8080)
515-
.setServeStaticFiles(false);
513+
.host("localhost")
514+
.port(8080)
515+
.serveStaticFiles(false);
516516
```
517517

518518
### Browser Client with xterm.js
@@ -864,7 +864,7 @@ public class MultiProtocolServer {
864864

865865
// WebSocket on port 8080
866866
NettyWebsocketTtyBootstrap http = new NettyWebsocketTtyBootstrap()
867-
.setPort(8080);
867+
.port(8080);
868868

869869
// Start all servers
870870
ssh.start();

content/docs/readline/edit-modes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import org.aesh.readline.editing.EditMode;
1414
import org.aesh.readline.editing.EditModeBuilder;
1515

1616
// Create default edit mode (Emacs)
17-
EditMode editMode = EditModeBuilder.builder().create();
17+
EditMode editMode = EditModeBuilder.builder().build();
1818

1919
// Create Vi mode
2020
EditMode viMode = EditModeBuilder.builder()
2121
.mode(EditMode.Mode.VI)
22-
.create();
22+
.build();
2323
```
2424

2525
## Emacs Mode
@@ -34,7 +34,7 @@ import org.aesh.readline.ReadlineBuilder;
3434
Readline readline = ReadlineBuilder.builder()
3535
.editMode(EditModeBuilder.builder()
3636
.mode(EditMode.Mode.EMACS)
37-
.create())
37+
.build())
3838
.build();
3939
```
4040

@@ -75,7 +75,7 @@ import org.aesh.readline.ReadlineBuilder;
7575
Readline readline = ReadlineBuilder.builder()
7676
.editMode(EditModeBuilder.builder()
7777
.mode(EditMode.Mode.VI)
78-
.create())
78+
.build())
7979
.build();
8080
```
8181

content/docs/readline/prompt.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,17 @@ Prompt prompt = new Prompt(parts);
8383

8484
## Methods
8585

86-
### getPromptAsString()
86+
### getPromptCharacters()
8787

8888
Returns the prompt text without ANSI codes:
8989

9090
```java
9191
Prompt prompt = new Prompt("[user]$ ");
92-
String text = prompt.getPromptAsString(); // "[user]$ "
92+
String text = prompt.getPromptCharacters(); // "[user]$ "
9393
```
9494

95+
> **Note:** `getPromptAsString()` is deprecated — use `getPromptCharacters()` instead.
96+
9597
### getMask()
9698

9799
Returns the mask character, or `null` if no masking:
@@ -128,6 +130,49 @@ Prompt original = new Prompt("$ ");
128130
Prompt copy = original.copy();
129131
```
130132

133+
## Prompt Builder
134+
135+
`Prompt.builder()` provides a fluent API for constructing prompts, as an alternative to the telescoping constructors:
136+
137+
```java
138+
// Simple text prompt
139+
Prompt prompt = Prompt.builder()
140+
.message("$ ")
141+
.build();
142+
143+
// Password prompt with mask
144+
Prompt prompt = Prompt.builder()
145+
.message("Password: ")
146+
.mask('*')
147+
.build();
148+
149+
// Styled prompt with TerminalString
150+
Prompt prompt = Prompt.builder()
151+
.terminalString(new TerminalString("[admin]# ",
152+
new TerminalColor(Color.RED, Color.DEFAULT),
153+
CharacterType.BOLD))
154+
.build();
155+
156+
// Prompt with ANSI string
157+
Prompt prompt = Prompt.builder()
158+
.message("$ ")
159+
.ansi("\u001B[32m$ \u001B[0m")
160+
.build();
161+
```
162+
163+
### Builder Methods
164+
165+
| Method | Type | Description |
166+
|--------|------|-------------|
167+
| `message(String)` | `String` | Set the prompt text |
168+
| `ansi(String)` | `String` | Set the ANSI-formatted display string |
169+
| `mask(char)` | `char` | Set mask character for hidden input |
170+
| `promptCodePoints(int[])` | `int[]` | Set prompt as Unicode code points |
171+
| `terminalString(TerminalString)` | `TerminalString` | Set a styled prompt |
172+
| `characters(List<TerminalCharacter>)` | `List` | Set individually formatted characters |
173+
174+
When multiple sources are set, the builder uses this precedence (highest first): `characters`, `terminalString`, `promptCodePoints`, `message`.
175+
131176
## Using Prompts
132177

133178
### With Readline

content/docs/readline/readline-api.md

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Readline readline = ReadlineBuilder.builder().build();
5151
Readline readline = ReadlineBuilder.builder()
5252
.editMode(EditModeBuilder.builder()
5353
.mode(EditMode.Mode.EMACS)
54-
.create())
54+
.build())
5555
.history(new FileHistory(new File(".history"), 500, true))
5656
.enableHistory(true)
5757
.historySize(1000)
@@ -204,6 +204,61 @@ readline.readline(connection, prompt, handler, completions,
204204
preProcessors, history, listener, flags);
205205
```
206206

207+
### ReadlineFlags Helper
208+
209+
The `ReadlineFlags` utility class provides a concise way to create flag sets without manual `EnumMap` construction:
210+
211+
```java
212+
import org.aesh.readline.ReadlineFlags;
213+
214+
// No flags
215+
ReadlineFlags.none();
216+
217+
// Specific flags
218+
ReadlineFlags.of(ReadlineFlag.NO_SYNCHRONIZED_OUTPUT);
219+
ReadlineFlags.of(ReadlineFlag.NO_CLIPBOARD, ReadlineFlag.NO_SHELL_INTEGRATION);
220+
221+
// All flags
222+
ReadlineFlags.all();
223+
```
224+
225+
> **Note:** `ReadlineFlags` produces `EnumSet<ReadlineFlag>` values. These are accepted by the `ReadlineRequest` builder's `flags()` method and the `readline()` overloads.
226+
227+
### ReadlineRequest Builder
228+
229+
For calls that use several optional parameters, `ReadlineRequest` provides a builder pattern that avoids passing `null` for unused fields:
230+
231+
```java
232+
import org.aesh.readline.ReadlineRequest;
233+
234+
ReadlineRequest request = ReadlineRequest.builder()
235+
.connection(connection)
236+
.prompt(new Prompt("$ "))
237+
.requestHandler(input -> processInput(input))
238+
.completions(myCompletions)
239+
.history(customHistory)
240+
.cursorListener(listener)
241+
.build();
242+
243+
readline.readline(request);
244+
```
245+
246+
**Required fields:** `connection`, `prompt`, `requestHandler`.
247+
248+
| Builder Method | Type | Description |
249+
|----------------|------|-------------|
250+
| `connection(Connection)` | `Connection` | Terminal connection (required) |
251+
| `prompt(Prompt)` | `Prompt` | Prompt to display (required) |
252+
| `prompt(String)` | `String` | Prompt string (convenience, creates a Prompt) |
253+
| `requestHandler(Consumer<String>)` | `Consumer` | Input handler callback (required) |
254+
| `completions(List<Completion>)` | `List` | Tab completions |
255+
| `preProcessors(List<Function<String, Optional<String>>>)` | `List` | Input transformers |
256+
| `history(History)` | `History` | Custom history for this read |
257+
| `cursorListener(CursorListener)` | `CursorListener` | Cursor movement events |
258+
| `flags(EnumMap<ReadlineFlag, Integer>)` | `EnumMap` | Behavior flags |
259+
260+
> **Note:** The existing `readline()` overloads with positional parameters are deprecated in favor of `ReadlineRequest`. They continue to work but new code should prefer the builder.
261+
207262
## Completion
208263

209264
### Completion Class
@@ -378,7 +433,7 @@ public enum Mode {
378433
```java
379434
EditMode editMode = EditModeBuilder.builder()
380435
.mode(EditMode.Mode.EMACS)
381-
.create();
436+
.build();
382437

383438
Readline readline = ReadlineBuilder.builder()
384439
.editMode(editMode)
@@ -478,7 +533,7 @@ public class InteractiveShell {
478533
this.readline = ReadlineBuilder.builder()
479534
.editMode(EditModeBuilder.builder()
480535
.mode(EditMode.Mode.EMACS)
481-
.create())
536+
.build())
482537
.history(new FileHistory(new File(".myshell_history"), 1000, true))
483538
.enableHistory(true)
484539
.historySize(1000)

content/docs/readline/synchronized-output.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ readline.readline(connection, new Prompt("$ "), input -> {
140140
}, null, null, null, null, flags);
141141
```
142142

143+
Or more concisely with `ReadlineRequest` and `ReadlineFlags`:
144+
145+
```java
146+
import org.aesh.readline.ReadlineRequest;
147+
import org.aesh.readline.ReadlineFlags;
148+
149+
readline.readline(ReadlineRequest.builder()
150+
.connection(connection)
151+
.prompt("$ ")
152+
.requestHandler(input -> { /* handle input */ })
153+
.flags(ReadlineFlags.of(ReadlineFlag.NO_SYNCHRONIZED_OUTPUT))
154+
.build());
155+
```
156+
143157
## Manual Usage
144158

145159
For applications that manage their own rendering loop (outside of `Readline`), use

0 commit comments

Comments
 (0)