Skip to content

Commit 7503cce

Browse files
committed
refactor: moved widget demos to tui and made them use App
1 parent 6f952fc commit 7503cce

3 files changed

Lines changed: 22 additions & 56 deletions

File tree

twinkle-core/src/test/java/examples/ListDemo.java

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package examples;
2+
3+
import org.codejive.twinkle.core.text.Line;
4+
import org.codejive.twinkle.tui.application.App;
5+
import org.codejive.twinkle.tui.widgets.Framed;
6+
import org.codejive.twinkle.tui.widgets.list.List;
7+
8+
public class ListDemo {
9+
public static void main(String[] args) throws Exception {
10+
List l =
11+
List.ofStrings(
12+
"First Item", "Second Item", "Third Item", "Fourth Item", "Fifth Item");
13+
Framed f = Framed.of(l).title(Line.of(" Simple List "));
14+
App.run(f);
15+
}
16+
}

twinkle-core/src/test/java/examples/RgbColorDemo.java renamed to twinkle-tui/src/test/java/examples/RgbColorDemo.java

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,24 @@
11
// The code for this demo was largely copied from the tamboui project:
22
package examples;
33

4-
import java.io.Reader;
54
import java.util.ArrayList;
65
import java.util.List;
7-
import org.codejive.twinkle.ansi.Ansi;
86
import org.codejive.twinkle.ansi.Color;
97
import org.codejive.twinkle.ansi.Style;
10-
import org.codejive.twinkle.core.terminal.RobotTerminal;
11-
import org.codejive.twinkle.core.text.Buffer;
128
import org.codejive.twinkle.core.text.Canvas;
139
import org.codejive.twinkle.core.text.Line;
1410
import org.codejive.twinkle.core.util.Size;
1511
import org.codejive.twinkle.core.widget.Widget;
16-
import org.codejive.twinkle.widgets.Framed;
12+
import org.codejive.twinkle.tui.application.App;
13+
import org.codejive.twinkle.tui.widgets.Framed;
1714
import org.jspecify.annotations.NonNull;
1815

1916
public class RgbColorDemo {
2017
public static void main(String[] args) throws Exception {
21-
System.out.print(Ansi.hideCursor() + Ansi.autoWrap(false));
22-
try (RobotTerminal term = new RobotTerminal(Size.of(40, 20))) {
23-
term.delay(5000).resize(Size.of(80, 40)).delay(5000).key('q');
24-
Size size = term.size();
25-
RgbColorWidget w = new RgbColorWidget();
26-
Widget f = new FpsFrameWidget().widget(w);
27-
Buffer buf = Buffer.of(size);
28-
term.onResize(buf::resize);
29-
30-
Reader rdr = term.reader();
31-
while (true) {
32-
while (rdr.ready()) {
33-
int ch = rdr.read();
34-
if (ch == 'q' || ch == 'Q') {
35-
return;
36-
}
37-
}
38-
f.render(buf);
39-
System.out.print(Ansi.cursorHome());
40-
System.out.print(buf.toAnsiString());
41-
// Thread.sleep(1);
42-
}
43-
} finally {
44-
System.out.print(Ansi.showCursor() + Ansi.autoWrap(true));
45-
}
18+
RgbColorWidget w = new RgbColorWidget();
19+
Widget f = new FpsFrameWidget().widget(w);
20+
App.run(f);
21+
//App.using(f).quitOnQ(true).limitFps(30).start();
4622
}
4723

4824
static class RgbColorWidget implements Widget {

0 commit comments

Comments
 (0)