Move examples to its own member

This commit is contained in:
Alexandre Bury 2020-04-23 17:13:50 -07:00
parent 4154f99b44
commit b7764541e5
41 changed files with 62 additions and 39 deletions

View File

@ -1,3 +1,3 @@
[workspace] [workspace]
members = ["cursive-core", "cursive"] members = ["cursive-core", "cursive", "examples"]

View File

@ -46,17 +46,17 @@ fn main() {
} }
``` ```
[![Cursive dialog example](https://raw.githubusercontent.com/gyscos/cursive/master/doc/cursive_example.png)](examples/dialog.rs) [![Cursive dialog example](https://raw.githubusercontent.com/gyscos/cursive/master/doc/cursive_example.png)](examples/src/bin/dialog.rs)
Check out the other [examples](https://github.com/gyscos/cursive/tree/master/examples) to get these results, and more: Check out the other [examples](https://github.com/gyscos/cursive/tree/master/examples) to get these results, and more:
<div> <div>
<a href="examples/edit.rs"><img src="https://imgur.com/CQgSwly.png" alt="edit.rs example", width="48%" /></a> <a href="examples/src/bin/edit.rs"><img src="https://imgur.com/CQgSwly.png" alt="edit.rs example", width="48%" /></a>
<a href="examples/lorem.rs"><img src="https://imgur.com/hW9M9MV.png" alt="lorem.rs example", width="48%" /></a> <a href="examples/src/bin/lorem.rs"><img src="https://imgur.com/hW9M9MV.png" alt="lorem.rs example", width="48%" /></a>
<a href="examples/menubar.rs"><img src="https://imgur.com/xx3lZPz.png" alt="menubar.rs example", width="48%" /></a> <a href="examples/src/bin/menubar.rs"><img src="https://imgur.com/xx3lZPz.png" alt="menubar.rs example", width="48%" /></a>
<a href="examples/select.rs"><img src="https://imgur.com/couty0n.png" alt="select.rs example", width="48%" /></a> <a href="examples/src/bin/select.rs"><img src="https://imgur.com/couty0n.png" alt="select.rs example", width="48%" /></a>
<a href="examples/mines/"><img src="https://imgur.com/vNteYyy.png" alt="mines example", width="48%" /></a> <a href="examples/src/bin/mines/"><img src="https://imgur.com/vNteYyy.png" alt="mines example", width="48%" /></a>
<a href="examples/theme.rs"><img src="https://i.imgur.com/3Yleozc.png" alt="theme.rs example", width="48%" /></a> <a href="examples/src/bin/theme.rs"><img src="https://i.imgur.com/3Yleozc.png" alt="theme.rs example", width="48%" /></a>
</div> </div>
_(Colors may depend on your terminal configuration.)_ _(Colors may depend on your terminal configuration.)_
@ -117,8 +117,7 @@ There is initial support for [wide characters](https://en.wikipedia.org/wiki/CJK
* Keep in mind that if the terminal has shortcuts registered, they probably won't be transmitted to the app. * Keep in mind that if the terminal has shortcuts registered, they probably won't be transmitted to the app.
* UTF-8 input should work fine in a unicode-enabled terminal emulator, but raw linux TTY may be more capricious. * UTF-8 input should work fine in a unicode-enabled terminal emulator, but raw linux TTY may be more capricious.
## [Contributing](CONTRIBUTING.md) ## [Contributing](CONTRIBUTING.md)
## Alternatives ## Alternatives
See also [tui-rs](https://github.com/fdehau/tui-rs) - and a small [comparison page](https://github.com/gyscos/cursive/wiki/Cursive-vs-tui%E2%80%90rs). See also [tui-rs](https://github.com/fdehau/tui-rs) - and a small [comparison page](https://github.com/gyscos/cursive/wiki/Cursive-vs-tui%E2%80%90rs).

View File

@ -3,7 +3,6 @@ authors = ["Alexandre Bury <alexandre.bury@gmail.com>"]
categories = ["command-line-interface", "gui"] categories = ["command-line-interface", "gui"]
description = "Core components for the Cursive TUI" description = "Core components for the Cursive TUI"
documentation = "https://docs.rs/cursive" documentation = "https://docs.rs/cursive"
exclude = ["doc/**", "assets/**", "examples/**"]
keywords = ["ncurses", "TUI", "UI"] keywords = ["ncurses", "TUI", "UI"]
license = "MIT" license = "MIT"
name = "cursive_core" name = "cursive_core"

View File

@ -644,8 +644,9 @@ impl View for StackView {
// We need to call `layout()` on the view before giving it focus // We need to call `layout()` on the view before giving it focus
// for the first time. Otherwise it will not be properly set up. // for the first time. Otherwise it will not be properly set up.
// Ex: examples/lorem.rs: the text view takes focus because it's // Ex: `examples/src/bin/lorem.rs`
// scrolling, but it only knows that after a call to `layout()`. // The text view takes focus because it's scrolling, but it only
// knows that after a call to `layout()`.
if layer.virgin { if layer.virgin {
layer.view.take_focus(Direction::none()); layer.view.take_focus(Direction::none());
layer.virgin = false; layer.virgin = false;

View File

@ -3,7 +3,6 @@ authors = ["Alexandre Bury <alexandre.bury@gmail.com>"]
categories = ["command-line-interface", "gui"] categories = ["command-line-interface", "gui"]
description = "A TUI (Text User Interface) library focused on ease-of-use." description = "A TUI (Text User Interface) library focused on ease-of-use."
documentation = "https://docs.rs/cursive" documentation = "https://docs.rs/cursive"
exclude = ["doc/**", "assets/**", "examples/**"]
keywords = ["ncurses", "TUI", "UI"] keywords = ["ncurses", "TUI", "UI"]
license = "MIT" license = "MIT"
name = "cursive" name = "cursive"

19
examples/Cargo.toml Normal file
View File

@ -0,0 +1,19 @@
[package]
authors = ["Alexandre Bury <alexandre.bury@gmail.com>"]
description = "Examples for the cursive TUI library."
documentation = "https://docs.rs/cursive"
edition = "2018"
license = "MIT"
name = "cursive-examples"
publish = false
readme = "Readme.md"
repository = "https://github.com/gyscos/cursive"
version = "0.1.0"
[dependencies]
atty = "0.2.14"
log = "0.4.8"
pretty-bytes = "0.2.2"
rand = "0.7.3"
cursive = { path = "../cursive" }

View File

@ -3,101 +3,107 @@
Here are example programs using Cursive to help you getting familiar with the Here are example programs using Cursive to help you getting familiar with the
various aspects of the library. various aspects of the library.
To run an example, use `cargo run --example EXAMPLE_NAME`. To run an example, use `cargo run --bin EXAMPLE_NAME`.
## [`hello_world`](hello_world.rs) To use a specific cursive backend, you can do, for example:
```
cargo run --bin EXAMPLE_NAME --features cursive/crossterm-backend
```
## [`hello_world`](src/bin/hello_world.rs)
Simplest example possible, it will show you the starting point of a basic Simplest example possible, it will show you the starting point of a basic
Cursive application. Cursive application.
## [`dialog`](dialog.rs) ## [`dialog`](src/bin/dialog.rs)
This example wraps the text in a `Dialog` view, showing the basic idea of view This example wraps the text in a `Dialog` view, showing the basic idea of view
composition. composition.
## [`lorem`](lorem.rs) ## [`lorem`](src/bin/lorem.rs)
This example loads a large text file to show scrolling behaviour. It also This example loads a large text file to show scrolling behaviour. It also
includes greek and japanese characters to show non-ascii support. includes greek and japanese characters to show non-ascii support.
## [`edit`](edit.rs) ## [`edit`](src/bin/edit.rs)
Here we have an `EditView` to get input from the user, and use that input in Here we have an `EditView` to get input from the user, and use that input in
the next view. It shows how to identify a view with an name and refer to it the next view. It shows how to identify a view with an name and refer to it
later. later.
## [`mutation`](mutation.rs) ## [`mutation`](src/bin/mutation.rs)
This example modifies the content of an existing view. This example modifies the content of an existing view.
## [`linear`](linear.rs) ## [`linear`](src/bin/linear.rs)
This example uses a `LinearView` to put multiple views side-by-side. This example uses a `LinearView` to put multiple views side-by-side.
## [`menubar`](menubar.rs) ## [`menubar`](src/bin/menubar.rs)
Here we learn how to create a menubar at the top of the screen, and populate Here we learn how to create a menubar at the top of the screen, and populate
it with static and dynamic entried. it with static and dynamic entried.
## [`logs`](logs.rs) ## [`logs`](src/bin/logs.rs)
This example defines a custom view to display asynchronous input from a This example defines a custom view to display asynchronous input from a
channel. channel.
## [`key_codes`](key_codes.rs) ## [`key_codes`](src/bin/key_codes.rs)
This example uses a custom view to print any input received. Can be used as a This example uses a custom view to print any input received. Can be used as a
debugging tool to see what input the application is receiving. debugging tool to see what input the application is receiving.
## [`select`](select.rs) ## [`select`](src/bin/select.rs)
This example uses a `SelectView` to have the user pick a city from a long list. This example uses a `SelectView` to have the user pick a city from a long list.
## [`list_view`](list_view.rs) ## [`list_view`](src/bin/list_view.rs)
This shows a use of a `ListView`, used to build simple forms. This shows a use of a `ListView`, used to build simple forms.
## [`text_area`](text_area.rs) ## [`text_area`](src/bin/text_area.rs)
This example uses a `TextArea`, where the user can input a block of text. This example uses a `TextArea`, where the user can input a block of text.
## [`markup`](markup.rs) ## [`markup`](src/bin/markup.rs)
This example prints a text with markup decorations. This example prints a text with markup decorations.
## [`theme`](theme.rs) ## [`theme`](src/bin/theme.rs)
This loads a theme file at runtime to change default colors. This loads a theme file at runtime to change default colors.
## [`theme_manual`](theme_manual.rs) ## [`theme_manual`](src/bin/theme_manual.rs)
Instead of loading a theme file, this manually sets various theme settings. Instead of loading a theme file, this manually sets various theme settings.
## [`terminal_default`](terminal_default.rs) ## [`terminal_default`](src/bin/terminal_default.rs)
This example shows the effect of the `Color::TerminalDefault` setting. This example shows the effect of the `Color::TerminalDefault` setting.
## [`colors`](colors.rs) ## [`colors`](src/bin/colors.rs)
This example draws a colorful square to show off true color support. This example draws a colorful square to show off true color support.
## [`refcell_view`](refcell_view.rs) ## [`refcell_view`](src/bin/refcell_view.rs)
Here we show how to access multiple views concurently through their name. Here we show how to access multiple views concurently through their name.
## [`progress`](progress.rs) ## [`progress`](src/bin/progress.rs)
This shows how to send information from an asynchronous task (like a download This shows how to send information from an asynchronous task (like a download
or slow computation) to update a progress bar. or slow computation) to update a progress bar.
## [`radio`](radio.rs) ## [`radio`](src/bin/radio.rs)
This shows how to use `RadioGroup` and `RadioButton`. This shows how to use `RadioGroup` and `RadioButton`.
## [`slider`](slider.rs) ## [`slider`](src/bin/slider.rs)
This is a demonstration of the `SliderView`. This is a demonstration of the `SliderView`.
## [`mines`](mines) (**Work in progress**) ## [`mines`](src/bin/mines) (**Work in progress**)
A larger example showing an implementation of minesweeper. A larger example showing an implementation of minesweeper.

View File

@ -4,7 +4,7 @@ use cursive::views::{Dialog, Panel, TextView};
fn main() { fn main() {
// Read some long text from a file. // Read some long text from a file.
let content = include_str!("../assets/lorem.txt"); let content = include_str!("../../assets/lorem.txt");
let mut siv = cursive::default(); let mut siv = cursive::default();

View File

@ -18,7 +18,7 @@ fn main() {
// Read the list of cities from separate file, and fill the view with it. // Read the list of cities from separate file, and fill the view with it.
// (We include the file at compile-time to avoid runtime read errors.) // (We include the file at compile-time to avoid runtime read errors.)
let content = include_str!("../assets/cities.txt"); let content = include_str!("../../assets/cities.txt");
select.add_all_str(content.lines()); select.add_all_str(content.lines());
// Sets the callback for when "Enter" is pressed. // Sets the callback for when "Enter" is pressed.