@@ -14,7 +14,7 @@ To use the builtins module, add the following dependency to your project:
14
14
<dependency >
15
15
<groupId >org.jline</groupId >
16
16
<artifactId >jline-builtins</artifactId >
17
- <version >3.25 .0</version >
17
+ <version >3.29 .0</version >
18
18
</dependency >
19
19
```
20
20
@@ -43,20 +43,20 @@ public class FileOperationsExample {
43
43
public static void main (String [] args ) throws IOException {
44
44
Terminal terminal = TerminalBuilder . builder(). build();
45
45
PrintWriter writer = terminal. writer();
46
-
46
+
47
47
// Create a line reader with file operations completers
48
48
LineReader reader = LineReaderBuilder . builder()
49
49
.terminal(terminal)
50
50
.completer(new ArgumentCompleter (
51
51
new StringsCompleter (" ls" , " cat" , " less" ),
52
52
new FilesCompleter (Paths . get(" ." ))))
53
53
.build();
54
-
54
+
55
55
// Main command loop
56
56
while (true ) {
57
57
String line = reader. readLine(" builtin> " );
58
58
String [] arguments = line. split(" \\ s+" );
59
-
59
+
60
60
try {
61
61
if (arguments. length > 0 ) {
62
62
switch (arguments[0 ]) {
@@ -67,7 +67,7 @@ public class FileOperationsExample {
67
67
Commands . ls(terminal, writer, path, false , false , false , false );
68
68
break ;
69
69
// highlight-end
70
-
70
+
71
71
case " cat" :
72
72
// Display file contents
73
73
if (arguments. length > 1 ) {
@@ -76,7 +76,7 @@ public class FileOperationsExample {
76
76
writer. println(" Usage: cat <file>" );
77
77
}
78
78
break ;
79
-
79
+
80
80
case " less" :
81
81
// Display file contents with paging
82
82
if (arguments. length > 1 ) {
@@ -85,10 +85,10 @@ public class FileOperationsExample {
85
85
writer. println(" Usage: less <file>" );
86
86
}
87
87
break ;
88
-
88
+
89
89
case " exit" :
90
90
return ;
91
-
91
+
92
92
default :
93
93
writer. println(" Unknown command: " + arguments[0 ]);
94
94
}
@@ -126,7 +126,7 @@ public class TableFormattingExample {
126
126
public static void main (String [] args ) throws IOException {
127
127
Terminal terminal = TerminalBuilder . builder(). build();
128
128
PrintWriter writer = terminal. writer();
129
-
129
+
130
130
// highlight-start
131
131
// Define table columns
132
132
List<Column > columns = Arrays . asList(
@@ -136,25 +136,25 @@ public class TableFormattingExample {
136
136
new Column (" Salary" , ColumnType . Number )
137
137
);
138
138
// highlight-end
139
-
139
+
140
140
// Create table data
141
141
List<List<String > > data = new ArrayList<> ();
142
142
data. add(Arrays . asList(" 1" , " John Doe" , " Developer" , " 75000" ));
143
143
data. add(Arrays . asList(" 2" , " Jane Smith" , " Manager" , " 85000" ));
144
144
data. add(Arrays . asList(" 3" , " Bob Johnson" , " Designer" , " 65000" ));
145
-
145
+
146
146
// Print the table
147
147
Tables . TableBuilder tableBuilder = new Tables .TableBuilder (columns);
148
148
tableBuilder. addAll(data);
149
-
149
+
150
150
// Format and display the table
151
151
Tables . Table table = tableBuilder. build();
152
152
String result = table. toStringWithColumns(
153
- terminal. getWidth(),
153
+ terminal. getWidth(),
154
154
true , // display borders
155
155
true // display header
156
156
);
157
-
157
+
158
158
writer. println(result);
159
159
writer. flush();
160
160
}
@@ -183,25 +183,25 @@ public class WidgetsExample {
183
183
public static void main (String [] args ) throws IOException {
184
184
Terminal terminal = TerminalBuilder . builder(). build();
185
185
DefaultParser parser = new DefaultParser ();
186
-
186
+
187
187
LineReader reader = LineReaderBuilder . builder()
188
188
.terminal(terminal)
189
189
.parser(parser)
190
190
.build();
191
-
191
+
192
192
// highlight-start
193
193
// Create command descriptions for TailTip widget
194
194
Map<String , List<String > > commandDescriptions = new HashMap<> ();
195
195
commandDescriptions. put(" help" , Arrays . asList(" Display help information" ));
196
196
commandDescriptions. put(" exit" , Arrays . asList(" Exit the application" ));
197
197
commandDescriptions. put(" ls" , Arrays . asList(" [path]" , " List directory contents" ));
198
198
commandDescriptions. put(" cat" , Arrays . asList(" <file>" , " Display file contents" ));
199
-
199
+
200
200
// Create and install the TailTip widget
201
201
TailTipWidgets widgets = new TailTipWidgets (reader, commandDescriptions, 5 , TipType . COMPLETER );
202
202
widgets. enable();
203
203
// highlight-end
204
-
204
+
205
205
// Main command loop
206
206
while (true ) {
207
207
String line = reader. readLine(" widgets> " );
@@ -240,33 +240,33 @@ public class SystemRegistryExample {
240
240
public static void main (String [] args ) throws IOException {
241
241
Terminal terminal = TerminalBuilder . builder(). build();
242
242
DefaultParser parser = new DefaultParser ();
243
-
243
+
244
244
// highlight-start
245
245
// Create the registry
246
246
SystemRegistry registry = new SystemRegistryImpl (parser, terminal, () - > Paths . get(" ." ), null );
247
-
247
+
248
248
// Create builtins
249
249
Builtins builtins = new Builtins (registry:: commandRegistry, () - > Paths . get(" ." ), null , null );
250
250
// highlight-end
251
-
251
+
252
252
// Register commands
253
253
registry. register(" help" , builtins:: help);
254
254
registry. register(" ls" , builtins:: ls);
255
255
registry. register(" cat" , builtins:: cat);
256
256
registry. register(" less" , builtins:: less);
257
-
257
+
258
258
// Set up completers
259
259
SystemCompleter completer = builtins. compileCompleters();
260
-
260
+
261
261
// Create line reader
262
262
LineReader reader = LineReaderBuilder . builder()
263
263
.terminal(terminal)
264
264
.completer(completer)
265
265
.parser(parser)
266
266
.build();
267
-
267
+
268
268
registry. setLineReader(reader);
269
-
269
+
270
270
// Main command loop
271
271
PrintWriter writer = terminal. writer();
272
272
while (true ) {
@@ -275,7 +275,7 @@ public class SystemRegistryExample {
275
275
if (line. trim(). equalsIgnoreCase(" exit" )) {
276
276
break ;
277
277
}
278
-
278
+
279
279
// Execute the command
280
280
registry. execute(line);
281
281
} catch (HelpException e) {
@@ -306,14 +306,14 @@ import java.nio.file.Paths;
306
306
public class NanoEditorExample {
307
307
public static void main (String [] args ) throws IOException {
308
308
Terminal terminal = TerminalBuilder . builder(). build();
309
-
309
+
310
310
// highlight-start
311
311
// Configure Nano
312
312
NanoConfig config = new NanoConfig .Builder ()
313
313
.tabSize(4 )
314
314
.tabToSpaces(true )
315
315
.build();
316
-
316
+
317
317
// Launch Nano editor
318
318
Nano nano = new Nano (terminal, config);
319
319
nano. open(Paths . get(" example.txt" ));
0 commit comments