Skip to content
This repository was archived by the owner on Aug 6, 2023. It is now read-only.

Commit c8c0329

Browse files
committed
chore: self contained examples
1 parent e00df22 commit c8c0329

16 files changed

+421
-281
lines changed

.github/workflows/ci.yml

+5-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
name: CI
1010

1111
env:
12-
CI_CARGO_MAKE_VERSION: 0.32.9
12+
CI_CARGO_MAKE_VERSION: 0.35.6
1313

1414
jobs:
1515
linux:
@@ -38,16 +38,10 @@ jobs:
3838
- name: "Install cargo-make"
3939
if: steps.cache-cargo-make.outputs.cache-hit != 'true'
4040
run: cargo install cargo-make --version ${{ env.CI_CARGO_MAKE_VERSION }}
41-
- name: "Format"
42-
run: cargo make fmt
43-
- name: "Check"
44-
run: cargo make check
45-
- name: "Test"
46-
run: cargo make test
41+
- name: "Format / Build / Test"
42+
run: cargo make ci
4743
env:
4844
RUST_BACKTRACE: full
49-
- name: "Clippy"
50-
run: cargo make clippy
5145
windows:
5246
name: Windows
5347
runs-on: windows-latest
@@ -73,13 +67,7 @@ jobs:
7367
- name: "Install cargo-make"
7468
if: steps.cache-cargo-make.outputs.cache-hit != 'true'
7569
run: cargo install cargo-make --version ${{ env.CI_CARGO_MAKE_VERSION }}
76-
- name: "Format"
77-
run: cargo make fmt
78-
- name: "Check"
79-
run: cargo make check
80-
- name: "Test"
81-
run: cargo make test
70+
- name: "Format / Build / Test"
71+
run: cargo make ci
8272
env:
8373
RUST_BACKTRACE: full
84-
- name: "Clippy"
85-
run: cargo make clippy

Cargo.toml

+54-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,57 @@ rand = "0.8"
3333
argh = "0.1"
3434

3535
[[example]]
36-
name = "termion_demo"
37-
path = "examples/termion_demo.rs"
38-
required-features = ["termion"]
36+
name = "barchart"
37+
required-features = ["crossterm"]
38+
39+
[[example]]
40+
name = "block"
41+
required-features = ["crossterm"]
42+
43+
[[example]]
44+
name = "canvas"
45+
required-features = ["crossterm"]
46+
47+
[[example]]
48+
name = "chart"
49+
required-features = ["crossterm"]
50+
51+
[[example]]
52+
name = "custom_widget"
53+
required-features = ["crossterm"]
54+
55+
[[example]]
56+
name = "gauge"
57+
required-features = ["crossterm"]
58+
59+
[[example]]
60+
name = "layout"
61+
required-features = ["crossterm"]
62+
63+
[[example]]
64+
name = "list"
65+
required-features = ["crossterm"]
66+
67+
[[example]]
68+
name = "paragraph"
69+
required-features = ["crossterm"]
70+
71+
[[example]]
72+
name = "popup"
73+
required-features = ["crossterm"]
74+
75+
[[example]]
76+
name = "sparkline"
77+
required-features = ["crossterm"]
78+
79+
[[example]]
80+
name = "table"
81+
required-features = ["crossterm"]
82+
83+
[[example]]
84+
name = "tabs"
85+
required-features = ["crossterm"]
86+
87+
[[example]]
88+
name = "user_input"
89+
required-features = ["crossterm"]

Makefile.toml

+71-36
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
[config]
22
skip_core_tasks = true
33

4-
[env.TUI_FEATURES]
5-
source = "${CARGO_MAKE_RUST_TARGET_OS}"
6-
default_value = "unknown"
7-
8-
[env.TUI_FEATURES.mapping]
9-
linux = "serde,crossterm,termion"
10-
macos = "serde,crossterm,termion"
11-
windows = "serde,crossterm"
4+
[tasks.ci]
5+
run_task = [
6+
{ name = "ci-unix", condition = { platforms = ["linux", "mac"] } },
7+
{ name = "ci-windows", condition = { platforms = ["windows"] } },
8+
]
129

13-
[tasks.default]
10+
[tasks.ci-unix]
11+
private = true
1412
dependencies = [
15-
"check",
13+
"fmt",
14+
"check-crossterm",
15+
"check-termion",
16+
"test-crossterm",
17+
"test-termion",
18+
"clippy-crossterm",
19+
"clippy-termion",
20+
"test-doc",
1621
]
1722

18-
[tasks.ci]
23+
[tasks.ci-windows]
24+
private = true
1925
dependencies = [
20-
"fmt",
21-
"check",
22-
"test",
23-
"clippy",
26+
"fmt",
27+
"check-crossterm",
28+
"test-crossterm",
29+
"clippy-crossterm",
30+
"test-doc",
2431
]
2532

26-
2733
[tasks.fmt]
2834
command = "cargo"
2935
args = [
@@ -33,8 +39,17 @@ args = [
3339
"--check",
3440
]
3541

42+
[tasks.check-crossterm]
43+
env = { TUI_FEATURES = "serde,crossterm" }
44+
run_task = "check"
45+
46+
[tasks.check-termion]
47+
env = { TUI_FEATURES = "serde,termion" }
48+
run_task = "check"
49+
3650
[tasks.check]
3751
command = "cargo"
52+
condition = { env_set = ["TUI_FEATURES"] }
3853
args = [
3954
"check",
4055
"--no-default-features",
@@ -43,8 +58,17 @@ args = [
4358
"--all-targets",
4459
]
4560

61+
[tasks.build-crossterm]
62+
env = { TUI_FEATURES = "serde,crossterm" }
63+
run_task = "build"
64+
65+
[tasks.build-termion]
66+
env = { TUI_FEATURES = "serde,termion" }
67+
run_task = "build"
68+
4669
[tasks.build]
4770
command = "cargo"
71+
condition = { env_set = ["TUI_FEATURES"] }
4872
args = [
4973
"build",
5074
"--no-default-features",
@@ -53,8 +77,17 @@ args = [
5377
"--all-targets",
5478
]
5579

80+
[tasks.clippy-crossterm]
81+
env = { TUI_FEATURES = "serde,crossterm" }
82+
run_task = "clippy"
83+
84+
[tasks.clippy-termion]
85+
env = { TUI_FEATURES = "serde,termion" }
86+
run_task = "clippy"
87+
5688
[tasks.clippy]
5789
command = "cargo"
90+
condition = { env_set = ["TUI_FEATURES"] }
5891
args = [
5992
"clippy",
6093
"--no-default-features",
@@ -65,48 +98,50 @@ args = [
6598
"warnings",
6699
]
67100

101+
[tasks.test-crossterm]
102+
env = { TUI_FEATURES = "serde,crossterm" }
103+
run_task = "test"
104+
105+
[tasks.test-termion]
106+
env = { TUI_FEATURES = "serde,termion" }
107+
run_task = "test"
108+
68109
[tasks.test]
69110
command = "cargo"
111+
condition = { env_set = ["TUI_FEATURES"] }
70112
args = [
71113
"test",
72114
"--no-default-features",
73115
"--features",
74-
"${TUI_FEATURES}"
116+
"${TUI_FEATURES}",
117+
"--lib",
118+
"--tests",
119+
"--examples",
120+
]
121+
122+
[tasks.test-doc]
123+
command = "cargo"
124+
args = [
125+
"test",
126+
"--doc",
75127
]
76128

77129
[tasks.run-example]
78130
private = true
79-
condition = { env_set = ["TUI_EXAMPLE_NAME", "TUI_FEATURES"] }
131+
condition = { env_set = ["TUI_EXAMPLE_NAME"] }
80132
command = "cargo"
81133
args = [
82134
"run",
83-
"--features",
84-
"${TUI_FEATURES}",
85135
"--release",
86136
"--example",
87137
"${TUI_EXAMPLE_NAME}"
88138
]
89139

90-
[tasks.run-example-windows]
91-
private = true
92-
condition = { env = {"TUI_EXAMPLE_NAME" = "crossterm_demo"} }
93-
run_task = "run-example"
94-
95-
[tasks.run-example-router]
96-
private = true
97-
run_task = [
98-
{ name = "run-example-windows", condition = { platforms = ["window"] } },
99-
{ name = "run-example" }
100-
]
101-
102140
[tasks.build-examples]
103-
condition = { env_set = ["TUI_FEATURES"] }
104141
command = "cargo"
105142
args = [
106143
"build",
107144
"--examples",
108-
"--features",
109-
"${TUI_FEATURES}",
110145
"--release"
111146
]
112147

@@ -119,6 +154,6 @@ for file in ${files}
119154
name = basename ${file}
120155
name = substring ${name} -3
121156
set_env TUI_EXAMPLE_NAME ${name}
122-
cm_run_task run-example-router
157+
cm_run_task run-example
123158
end
124159
'''

README.md

+12-23
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@ user interfaces and dashboards. It is heavily inspired by the `Javascript`
1111
library [blessed-contrib](https://github.com/yaronn/blessed-contrib) and the
1212
`Go` library [termui](https://github.com/gizak/termui).
1313

14-
The library itself supports four different backends to draw to the terminal. You
15-
can either choose from:
16-
14+
The library supports multiple backends:
15+
- [crossterm](https://github.com/crossterm-rs/crossterm) [default]
1716
- [termion](https://github.com/ticki/termion)
18-
- [rustbox](https://github.com/gchp/rustbox)
19-
- [crossterm](https://github.com/crossterm-rs/crossterm)
20-
- [pancurses](https://github.com/ihalila/pancurses)
21-
22-
However, some features may only be available in one of the four.
2317

2418
The library is based on the principle of immediate rendering with intermediate
2519
buffers. This means that at each new frame you should build all widgets that are
@@ -34,37 +28,31 @@ you may rely on the previously cited libraries to achieve such features.
3428

3529
### Rust version requirements
3630

37-
Since version 0.10.0, `tui` requires **rustc version 1.44.0 or greater**.
31+
Since version 0.17.0, `tui` requires **rustc version 1.52.1 or greater**.
3832

3933
### [Documentation](https://docs.rs/tui)
4034

4135
### Demo
4236

43-
The demo shown in the gif can be run with all available backends
44-
(`examples/*_demo.rs` files). For example to see the `termion` version one could
45-
run:
37+
The demo shown in the gif can be run with all available backends.
4638

4739
```
48-
cargo run --example termion_demo --release -- --tick-rate 200
40+
# crossterm
41+
cargo run --example demo --release -- --tick-rate 200
42+
# termion
43+
cargo run --example demo --no-default-features --features=termion --release -- --tick-rate 200
4944
```
5045

5146
where `tick-rate` is the UI refresh rate in ms.
5247

5348
The UI code is in [examples/demo/ui.rs](https://github.com/fdehau/tui-rs/blob/v0.16.0/examples/demo/ui.rs) while the
5449
application state is in [examples/demo/app.rs](https://github.com/fdehau/tui-rs/blob/v0.16.0/examples/demo/app.rs).
5550

56-
Beware that the `termion_demo` only works on Unix platforms. If you are a Windows user,
57-
you can see the same demo using the `crossterm` backend with the following command:
58-
59-
```
60-
cargo run --example crossterm_demo --no-default-features --features="crossterm" --release -- --tick-rate 200
61-
```
62-
6351
If the user interface contains glyphs that are not displayed correctly by your terminal, you may want to run
6452
the demo without those symbols:
6553

6654
```
67-
cargo run --example crossterm_demo --no-default-features --features="crossterm" --release -- --tick-rate 200 --enhanced-graphics false
55+
cargo run --example demo --release -- --tick-rate 200 --enhanced-graphics false
6856
```
6957

7058
### Widgets
@@ -83,9 +71,10 @@ The library comes with the following list of widgets:
8371
* [Tabs](https://github.com/fdehau/tui-rs/blob/v0.16.0/examples/tabs.rs)
8472

8573
Click on each item to see the source of the example. Run the examples with with
86-
cargo (e.g. to run the demo `cargo run --example demo`), and quit by pressing `q`.
74+
cargo (e.g. to run the gauge example `cargo run --example gauge`), and quit by pressing `q`.
8775

88-
You can run all examples by running `make run-examples`.
76+
You can run all examples by running `cargo make run-examples` (require
77+
`cargo-make` that can be installed with `cargo install cargo-make`).
8978

9079
### Third-party widgets
9180

0 commit comments

Comments
 (0)