Initial terminal ui implementation

- This commit adds proof of concept work for terminal ui as is.
- Some things work, some don't but we need to start from somewhere.
  Further development continues in a main.
- Essentially we are starting to have enough so that it merits to
  move all this work into a main repo.
- Everything new is kept under org.springframework.shell.component.view
  and will get revisiter later to find correct locations for some classes.
- Catalog sample has been modified to provide "showcase" app for
  terminal ui features. This is a start while it already contains
  some usefull scenarios.
- Relates #800
- Relates #801
- Relates #802
- Relates #803
- Relates #804
- Relates #805
- Relates #806
- Relates #807
- Relates #808
- Relates #809
- Relates #810
- Relates #811
This commit is contained in:
Janne Valkealahti
2023-07-15 16:42:39 +01:00
parent da04202822
commit a0bdbfc033
94 changed files with 9990 additions and 8 deletions

View File

@@ -0,0 +1,12 @@
[#appendix-tui-catalog]
=== Catalog App
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
Catalog application is showing various ways how Terminal UI Framework can be used.
In this section we discuss how this application works. It can be considered to be
a reference application as it's using most of the features available and tries
to follow best practices.
==== Create Scenario
Every `Scenario` essentially is a sample code of a `View` as that's what catalog
app demonstrates.

View File

@@ -0,0 +1,5 @@
[#appendix-tui-control]
=== Control
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
_Control_ draws something into a screen with a given bounds.

View File

@@ -0,0 +1,5 @@
[#appendix-tui-eventloop]
=== EventLoop
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
_EventLoop_ is a central system handling eventing in a framework.

View File

@@ -0,0 +1,5 @@
[#appendix-tui-keyhandling]
=== Key Handling
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
Handles incoming key events.

View File

@@ -0,0 +1,5 @@
[#appendix-tui-mousehandling]
=== Mouse Handling
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
Handles incoming mouse events.

View File

@@ -0,0 +1,6 @@
[#appendix-tui-screen]
=== Screen
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
_Screen_ is an abstraction providing higher level concept to draw something
into a terminal.

View File

@@ -0,0 +1,5 @@
[#appendix-tui-view]
=== View
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
_View_ extends _Control_ providing integration into event loop.

View File

@@ -0,0 +1,22 @@
[appendix]
[#appendix-tech-intro-tui]
== Terminal UI
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
This is a technical introduction to _UI Framework_.
_UI Framework_ is a toolkit to build rich console apps.
include::appendices-tui-control.adoc[]
include::appendices-tui-view.adoc[]
include::appendices-tui-eventloop.adoc[]
include::appendices-tui-screen.adoc[]
include::appendices-tui-keyhandling.adoc[]
include::appendices-tui-mousehandling.adoc[]
include::appendices-tui-catalog.adoc[]

View File

@@ -1,3 +1,5 @@
include::appendices-techical-intro.adoc[]
include::appendices-debugging.adoc[]
include::appendices-tui.adoc[]

View File

@@ -0,0 +1,14 @@
[[using-shell-tui-intro]]
=== Introduction
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
Lets start with a simple app which prints "hello world" in a view.
====
[source, java, indent=0]
----
include::{snippets}/TerminalUiSnippets.java[tag=snippet1]
----
====
There is not much to see here other than `TerminalUI` is a class handling
all logic aroung views and uses `View` as it's root view.

View File

@@ -0,0 +1,6 @@
[[using-shell-tui-views-box]]
==== BoxView
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
_BoxView_ is a base implementation providing functionality to draw into a
bounded _Rectancle_.

View File

@@ -0,0 +1,5 @@
[[using-shell-tui-views-list]]
==== ListView
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
_ListView_ is a base implementation providing functionality to draw list of items.

View File

@@ -0,0 +1,11 @@
[[using-shell-tui-views]]
=== Views
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
Framework provides a build-in views which are documented below.
TIP: To learn more about views, see <<appendix-tui-view>>.
include::using-shell-tui-views-box.adoc[]
include::using-shell-tui-views-list.adoc[]

View File

@@ -0,0 +1,16 @@
[[using-shell-tui]]
== Terminal UI
NOTE: Feature is experimental and subject to breaking changes until foundation
and related concepts around framework are getting more stable.
_Terminal UI Framework_ is a toolkit to build rich console apps. This section is
for those using existing features as is. If you're planning to go deeper possibly
creating your own components <<appendix-tech-intro-tui>> provides more detailed
documentation.
TIP: Catalog sample is a good place to study a real application <<appendix-tui-catalog>>.
include::using-shell-tui-intro.adoc[]
include::using-shell-tui-views.adoc[]

View File

@@ -10,6 +10,8 @@ include::using-shell-building.adoc[]
include::using-shell-components.adoc[]
include::using-shell-tui.adoc[]
include::using-shell-customization.adoc[]
include::using-shell-execution.adoc[]

View File

@@ -0,0 +1,49 @@
/*
* 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 org.jline.terminal.Terminal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.shell.component.view.TerminalUI;
import org.springframework.shell.component.view.control.BoxView;
import org.springframework.shell.component.view.geom.HorizontalAlign;
import org.springframework.shell.component.view.geom.VerticalAlign;
class TerminalUiSnippets {
class Sample {
// tag::snippet1[]
@Autowired
Terminal terminal;
void build() {
TerminalUI ui = new TerminalUI(terminal);
BoxView view = new BoxView();
view.setDrawFunction((screen, rect) -> {
screen.writerBuilder()
.build()
.text("Hello World", rect, HorizontalAlign.CENTER, VerticalAlign.CENTER);
return rect;
});
ui.setRoot(view, true);
ui.run();
}
// end::snippet1[]
}
}