GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor: show no tests message as a modal dialog on top · testlens-app/cli@d69a1ef

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • build.gradle.kts
  • src/main/java/app/testlens/cli/tui
    • PrDetailsController.java
    • PrDetailsView.java
    • PrTestsTableController.java
    • PrTestsTableView.java
    • PrTui.java
    • PrTuiView.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎build.gradle.kts‎

Copy file name to clipboardExpand all lines: build.gradle.kts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ application {
5656
mainModule = "app.testlens.cli"
5757
mainClass = "app.testlens.cli.Testlens"
5858
applicationName = "testlens"
59-
applicationDefaultJvmArgs = listOf("--enable-native-access=dev.tamboui.panama.backend")
59+
// tamboui 0.5.0 DialogElement uses dev.tamboui.widgets.Clear, which the widgets module does not export to toolkit
60+
applicationDefaultJvmArgs =
61+
listOf(
62+
"--enable-native-access=dev.tamboui.panama.backend",
63+
"--add-exports=dev.tamboui.widgets/dev.tamboui.widgets=dev.tamboui.toolkit",
64+
)
6065
}
6166

6267
tasks.test {
Collapse file

‎src/main/java/app/testlens/cli/tui/PrDetailsController.java‎

Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/tui/PrDetailsController.java
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ void onSelectedExecution(Consumer<Execution> onSelectedExecution) {
3636
updateDetailsArea();
3737
}
3838

39+
@Nullable
3940
ExecutedTest selectedTest() {
40-
return requireNonNull(selectedTest);
41+
return selectedTest;
4142
}
4243

4344
int selectedExecutionIndex() {
@@ -53,7 +54,7 @@ boolean isFocused() {
5354
}
5455

5556
Execution selectedExecution() {
56-
return selectedTest().getExecutions().get(selectedExecutionIndex());
57+
return requireNonNull(selectedTest).getExecutions().get(selectedExecutionIndex());
5758
}
5859

5960
void selectTest(ExecutedTest test) {
@@ -63,11 +64,14 @@ void selectTest(ExecutedTest test) {
6364
}
6465

6566
EventResult handleKey(KeyEvent event) {
67+
if (selectedTest == null) {
68+
return keyHandler.apply(event).isHandled() ? EventResult.HANDLED : EventResult.UNHANDLED;
69+
}
6670
if (keyHandler.apply(event).isHandled()) {
6771
return EventResult.HANDLED;
6872
}
6973
// handled regardless of focus, so executions can be switched while browsing tests
70-
var executionCount = selectedTest().getExecutions().size();
74+
var executionCount = requireNonNull(selectedTest).getExecutions().size();
7175
if (event.isLeft()) {
7276
var previousExecution = selectedExecutionIndex();
7377
tabsState.select(Math.max(0, previousExecution - 1));
@@ -88,7 +92,7 @@ EventResult handleKey(KeyEvent event) {
8892
}
8993

9094
private void updateDetailsArea() {
91-
if (onSelectedExecution != null) {
95+
if (onSelectedExecution != null && selectedTest != null) {
9296
onSelectedExecution.accept(selectedExecution());
9397
}
9498
}
Collapse file

‎src/main/java/app/testlens/cli/tui/PrDetailsView.java‎

Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/tui/PrDetailsView.java
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ final class PrDetailsView {
5353

5454
Element render() {
5555
var test = controller.selectedTest();
56+
if (test == null) {
57+
return panel(detailsArea.fill()).rounded().borderColor(Color.DARK_GRAY).fill();
58+
}
5659
var executionIndex = controller.selectedExecutionIndex();
5760
var executions = test.getExecutions();
5861

Collapse file

‎src/main/java/app/testlens/cli/tui/PrTestsTableController.java‎

Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/tui/PrTestsTableController.java
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ void selectTest(int index) {
5757
}
5858

5959
EventResult handleKey(KeyEvent event) {
60+
if (tests.isEmpty()) {
61+
return keyHandler.apply(event).isHandled() ? EventResult.HANDLED : EventResult.UNHANDLED;
62+
}
6063
if (keyHandler.apply(event).isHandled()) {
6164
return EventResult.HANDLED;
6265
}
Collapse file

‎src/main/java/app/testlens/cli/tui/PrTestsTableView.java‎

Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/tui/PrTestsTableView.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ final class PrTestsTableView {
6666
Element render() {
6767
table.borderColor(controller.isFocused() ? Color.CYAN : Color.DARK_GRAY);
6868
var tests = controller.tests();
69-
return testTableWithScrollbar(
70-
Constraint.length(Math.min(tests.size(), MAX_VISIBLE_TESTS) + TABLE_CHROME_HEIGHT)
71-
);
69+
// reserve space for a full table even when empty, so the popup has a natural backdrop
70+
var rowCount = tests.isEmpty() ? MAX_VISIBLE_TESTS : tests.size();
71+
return testTableWithScrollbar(Constraint.length(Math.min(rowCount, MAX_VISIBLE_TESTS) + TABLE_CHROME_HEIGHT));
7272
}
7373

7474
private Element testTableWithScrollbar(Constraint constraint) {
Collapse file

‎src/main/java/app/testlens/cli/tui/PrTui.java‎

Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/tui/PrTui.java
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,24 @@
44
import app.testlens.cli.client.model.PullRequestResponse;
55
import app.testlens.cli.client.model.PullRequestTestsResponse;
66
import dev.tamboui.toolkit.app.ToolkitRunner;
7+
import dev.tamboui.toolkit.event.EventResult;
8+
import dev.tamboui.tui.event.KeyEvent;
79

810
public final class PrTui {
911

1012
public static void run(PullRequestResponse prResponse, PullRequestTestsResponse testsResponse) throws Exception {
1113
try (var runner = ToolkitRunner.create()) {
1214
var controller = new PrTuiController(prResponse, testsResponse, runner.focusManager());
1315
var view = new PrTuiView(controller);
16+
// the modal "no tests" dialog consumes all keys before unfocused-element routing,
17+
// so quit has to be handled globally, ahead of the dialog
18+
runner.eventRouter().addGlobalHandler(event -> {
19+
if (event instanceof KeyEvent keyEvent && keyEvent.isQuit()) {
20+
runner.quit();
21+
return EventResult.HANDLED;
22+
}
23+
return EventResult.UNHANDLED;
24+
});
1425
runner.run(view::render);
1526
}
1627
}
Collapse file

‎src/main/java/app/testlens/cli/tui/PrTuiView.java‎

Copy file name to clipboard
+15-17Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package app.testlens.cli.tui;
33

4+
import static dev.tamboui.style.Color.YELLOW;
45
import static dev.tamboui.toolkit.Toolkit.column;
6+
import static dev.tamboui.toolkit.Toolkit.dialog;
7+
import static dev.tamboui.toolkit.Toolkit.stack;
58
import static dev.tamboui.toolkit.Toolkit.text;
6-
import static java.util.Objects.requireNonNull;
79

810
import dev.tamboui.toolkit.element.Element;
9-
import org.jspecify.annotations.Nullable;
1011

1112
final class PrTuiView {
1213

1314
private final PrTuiController controller;
1415

1516
private final PrHeaderView header;
16-
private final @Nullable PrTestsTableView testTable;
17-
private final @Nullable PrDetailsView details;
17+
private final PrTestsTableView testTable;
18+
private final PrDetailsView details;
1819
private final PrFooterView footer;
1920

2021
PrTuiView(PrTuiController controller) {
2122
this.controller = controller;
2223
this.header = new PrHeaderView(controller);
23-
if (controller.hasTests()) {
24-
this.testTable = new PrTestsTableView(controller.testTableController());
25-
this.details = new PrDetailsView(controller.detailsController());
26-
} else {
27-
this.testTable = null;
28-
this.details = null;
29-
}
24+
this.testTable = new PrTestsTableView(controller.testTableController());
25+
this.details = new PrDetailsView(controller.detailsController());
3026
this.footer = new PrFooterView();
3127
}
3228

3329
Element render() {
34-
if (testTable == null) {
35-
return column(
36-
header.render(),
37-
text("No failing tests detected on pull request #" + controller.prResponse().getNumber()).fill()
38-
);
30+
var content = column(header.render(), testTable.render(), details.render(), footer.render());
31+
if (controller.hasTests()) {
32+
return content;
3933
}
40-
return column(header.render(), testTable.render(), requireNonNull(details).render(), footer.render());
34+
var message = "No failing tests detected on pull request #" + controller.prResponse().getNumber();
35+
return stack(
36+
content,
37+
dialog(text(message)).rounded().borderColor(YELLOW).width(message.length() + 4)
38+
);
4139
}
4240
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.