forked from spring-projects/spring-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make StatusBarView work with hotkeys
- StatusItem can now define a hotkey which is then bound to its action. - In catalog app replace use of raw key event to item's hotkey for status bar visibility. - Various doc updates. - Relates spring-projects#826
- Loading branch information
Showing
9 changed files
with
227 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
= AppView | ||
:page-section-summary-toc: 1 | ||
|
||
ifndef::snippets[:snippets: ../../../../../src/test/java/org/springframework/shell/docs] | ||
|
||
_AppView_ is a base implementation providing functionality to draw opinionated _application view_. | ||
Inherits xref:tui/views/box.adoc[]. | ||
|
||
Generic idea is to have menu and status views which typically are xref:tui/views/menubar.adoc[] and | ||
xref:tui/views/statusbar.adoc[] respectively. Main content view is then whatever user want to show | ||
in it. | ||
|
||
[source, text] | ||
---- | ||
┌──────────────────────────┐ | ||
│ Menu │ | ||
├──────────────────────────┤ | ||
│ │ | ||
│ Main │ | ||
│ │ | ||
├──────────────────────────┤ | ||
│ Status │ | ||
└──────────────────────────┘ | ||
---- | ||
|
||
== Key Handling | ||
If menu has a focus key handling is processed there, then main is consulted for handling. | ||
Lastly cursor left/right are processed to dispatch _AppViewEvent_. | ||
|
||
== HotKey Handling | ||
Hotkeys are processed in order of _main_, _menu_ and _status_. | ||
|
||
== Events | ||
.AppView Events | ||
|=== | ||
|Event |Description | ||
|
||
|AppViewEvent | ||
|Direction for a next selection. | ||
|
||
|=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
spring-shell-docs/modules/ROOT/pages/tui/views/statusbar.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
= StatusBarView | ||
:page-section-summary-toc: 1 | ||
|
||
ifndef::snippets[:snippets: ../../../../../src/test/java/org/springframework/shell/docs] | ||
|
||
_StatusBarView_ is a base implementation providing functionality to draw a status bar. | ||
Inherits xref:tui/views/box.adoc[]. | ||
|
||
[source, text] | ||
---- | ||
┌─────────────────────────────┐ | ||
│ Item1 | Item2 | Item3 │ | ||
└─────────────────────────────┘ | ||
---- | ||
|
||
You can create a simple status bar with an item: | ||
|
||
[source, java, indent=0] | ||
---- | ||
include::{snippets}/StatusBarViewSnippets.java[tag=simple] | ||
---- | ||
|
||
Constructor can take array form which allows to lay out simple | ||
item definitions in a _dsl_ style. | ||
|
||
[source, java, indent=0] | ||
---- | ||
include::{snippets}/StatusBarViewSnippets.java[tag=viaarray] | ||
---- | ||
|
||
Items support runnable actions which generally as executed when | ||
item is selected. It can also get attached to a hot key. | ||
|
||
[source, java, indent=0] | ||
---- | ||
include::{snippets}/StatusBarViewSnippets.java[tag=items] | ||
---- | ||
|
||
|
||
== Events | ||
.StatusBarView Events | ||
|=== | ||
|Event |Description | ||
|
||
|StatusBarViewOpenSelectedItemEvent | ||
|StatusItem is selected. | ||
|
||
|=== |
63 changes: 63 additions & 0 deletions
63
spring-shell-docs/src/test/java/org/springframework/shell/docs/StatusBarViewSnippets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.shell.docs; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.shell.component.view.control.StatusBarView; | ||
import org.springframework.shell.component.view.control.StatusBarView.StatusItem; | ||
import org.springframework.shell.component.view.event.KeyEvent; | ||
import org.springframework.shell.component.view.event.KeyEvent.Key; | ||
|
||
class StatusBarViewSnippets { | ||
|
||
@SuppressWarnings("unused") | ||
void simple() { | ||
// tag::simple[] | ||
StatusItem item1 = new StatusBarView.StatusItem("Item1"); | ||
StatusBarView statusBar = new StatusBarView(List.of(item1)); | ||
// end::simple[] | ||
} | ||
|
||
void items() { | ||
// tag::items[] | ||
StatusItem item1 = StatusBarView.StatusItem.of("Item1"); | ||
|
||
Runnable action1 = () -> {}; | ||
StatusItem item2 = StatusBarView.StatusItem.of("Item2", action1); | ||
|
||
Runnable action2 = () -> {}; | ||
StatusItem item3 = StatusBarView.StatusItem.of("Item3", action2, KeyEvent.Key.f10); | ||
|
||
StatusBarView statusBar = new StatusBarView(); | ||
statusBar.setItems(List.of(item1, item2, item3)); | ||
// end::items[] | ||
} | ||
|
||
void viaArray() { | ||
// tag::viaarray[] | ||
new StatusBarView(new StatusItem[] { | ||
StatusItem.of("Item1"), | ||
StatusItem.of("Item2") | ||
.setAction(() -> {}), | ||
StatusItem.of("Item3") | ||
.setAction(() -> {}) | ||
.setHotKey(Key.f10) | ||
}); | ||
// end::viaarray[] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters