From b7764541e50739bbfa4edc9774a4856e8ec6647b Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 23 Apr 2020 17:13:50 -0700 Subject: [PATCH] Move examples to its own member --- Cargo.toml | 2 +- Readme.md | 17 +++--- cursive-core/Cargo.toml | 1 - cursive-core/src/views/stack_view.rs | 5 +- cursive/Cargo.toml | 1 - examples/Cargo.toml | 19 +++++++ {cursive/examples => examples}/Readme.md | 52 +++++++++++-------- {cursive => examples}/assets/cities.txt | 0 {cursive => examples}/assets/lorem.txt | 0 {cursive => examples}/assets/style.toml | 0 .../examples => examples/src/bin}/colors.rs | 0 .../src/bin}/debug_console.rs | 0 .../examples => examples/src/bin}/dialog.rs | 0 .../examples => examples/src/bin}/edit.rs | 0 .../src/bin}/hello_world.rs | 0 .../src/bin}/key_codes.rs | 0 .../examples => examples/src/bin}/linear.rs | 0 .../src/bin}/list_view.rs | 0 .../examples => examples/src/bin}/logs.rs | 0 .../examples => examples/src/bin}/lorem.rs | 2 +- .../examples => examples/src/bin}/markup.rs | 0 .../examples => examples/src/bin}/menubar.rs | 0 .../src/bin}/mines/Readme.md | 0 .../src/bin}/mines/game.rs | 0 .../src/bin}/mines/main.rs | 0 .../examples => examples/src/bin}/mutation.rs | 0 .../examples => examples/src/bin}/position.rs | 0 .../examples => examples/src/bin}/progress.rs | 0 .../examples => examples/src/bin}/radio.rs | 0 .../src/bin}/refcell_view.rs | 0 .../examples => examples/src/bin}/scroll.rs | 0 .../examples => examples/src/bin}/select.rs | 2 +- .../src/bin}/select_test.rs | 0 .../examples => examples/src/bin}/slider.rs | 0 .../src/bin}/tcp_server.rs | 0 .../src/bin}/terminal_default.rs | 0 .../src/bin}/text_area.rs | 0 .../examples => examples/src/bin}/theme.rs | 0 .../src/bin}/theme_manual.rs | 0 .../src/bin}/user_data.rs | 0 {cursive/examples => examples/src/bin}/vpv.rs | 0 41 files changed, 62 insertions(+), 39 deletions(-) create mode 100644 examples/Cargo.toml rename {cursive/examples => examples}/Readme.md (66%) rename {cursive => examples}/assets/cities.txt (100%) rename {cursive => examples}/assets/lorem.txt (100%) rename {cursive => examples}/assets/style.toml (100%) rename {cursive/examples => examples/src/bin}/colors.rs (100%) rename {cursive/examples => examples/src/bin}/debug_console.rs (100%) rename {cursive/examples => examples/src/bin}/dialog.rs (100%) rename {cursive/examples => examples/src/bin}/edit.rs (100%) rename {cursive/examples => examples/src/bin}/hello_world.rs (100%) rename {cursive/examples => examples/src/bin}/key_codes.rs (100%) rename {cursive/examples => examples/src/bin}/linear.rs (100%) rename {cursive/examples => examples/src/bin}/list_view.rs (100%) rename {cursive/examples => examples/src/bin}/logs.rs (100%) rename {cursive/examples => examples/src/bin}/lorem.rs (93%) rename {cursive/examples => examples/src/bin}/markup.rs (100%) rename {cursive/examples => examples/src/bin}/menubar.rs (100%) rename {cursive/examples => examples/src/bin}/mines/Readme.md (100%) rename {cursive/examples => examples/src/bin}/mines/game.rs (100%) rename {cursive/examples => examples/src/bin}/mines/main.rs (100%) rename {cursive/examples => examples/src/bin}/mutation.rs (100%) rename {cursive/examples => examples/src/bin}/position.rs (100%) rename {cursive/examples => examples/src/bin}/progress.rs (100%) rename {cursive/examples => examples/src/bin}/radio.rs (100%) rename {cursive/examples => examples/src/bin}/refcell_view.rs (100%) rename {cursive/examples => examples/src/bin}/scroll.rs (100%) rename {cursive/examples => examples/src/bin}/select.rs (96%) rename {cursive/examples => examples/src/bin}/select_test.rs (100%) rename {cursive/examples => examples/src/bin}/slider.rs (100%) rename {cursive/examples => examples/src/bin}/tcp_server.rs (100%) rename {cursive/examples => examples/src/bin}/terminal_default.rs (100%) rename {cursive/examples => examples/src/bin}/text_area.rs (100%) rename {cursive/examples => examples/src/bin}/theme.rs (100%) rename {cursive/examples => examples/src/bin}/theme_manual.rs (100%) rename {cursive/examples => examples/src/bin}/user_data.rs (100%) rename {cursive/examples => examples/src/bin}/vpv.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index a83a315..dac69e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["cursive-core", "cursive"] +members = ["cursive-core", "cursive", "examples"] diff --git a/Readme.md b/Readme.md index 936d698..a9bc335 100644 --- a/Readme.md +++ b/Readme.md @@ -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:
-edit.rs example -lorem.rs example -menubar.rs example -select.rs example -mines example -theme.rs example +edit.rs example +lorem.rs example +menubar.rs example +select.rs example +mines example +theme.rs example
_(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. * 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 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). diff --git a/cursive-core/Cargo.toml b/cursive-core/Cargo.toml index 6d651d1..bf889c7 100644 --- a/cursive-core/Cargo.toml +++ b/cursive-core/Cargo.toml @@ -3,7 +3,6 @@ authors = ["Alexandre Bury "] categories = ["command-line-interface", "gui"] description = "Core components for the Cursive TUI" documentation = "https://docs.rs/cursive" -exclude = ["doc/**", "assets/**", "examples/**"] keywords = ["ncurses", "TUI", "UI"] license = "MIT" name = "cursive_core" diff --git a/cursive-core/src/views/stack_view.rs b/cursive-core/src/views/stack_view.rs index 1974adb..cb99c29 100644 --- a/cursive-core/src/views/stack_view.rs +++ b/cursive-core/src/views/stack_view.rs @@ -644,8 +644,9 @@ impl View for StackView { // We need to call `layout()` on the view before giving it focus // for the first time. Otherwise it will not be properly set up. - // Ex: examples/lorem.rs: the text view takes focus because it's - // scrolling, but it only knows that after a call to `layout()`. + // Ex: `examples/src/bin/lorem.rs` + // The text view takes focus because it's scrolling, but it only + // knows that after a call to `layout()`. if layer.virgin { layer.view.take_focus(Direction::none()); layer.virgin = false; diff --git a/cursive/Cargo.toml b/cursive/Cargo.toml index f746114..720b250 100644 --- a/cursive/Cargo.toml +++ b/cursive/Cargo.toml @@ -3,7 +3,6 @@ authors = ["Alexandre Bury "] categories = ["command-line-interface", "gui"] description = "A TUI (Text User Interface) library focused on ease-of-use." documentation = "https://docs.rs/cursive" -exclude = ["doc/**", "assets/**", "examples/**"] keywords = ["ncurses", "TUI", "UI"] license = "MIT" name = "cursive" diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100644 index 0000000..8f758a6 --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,19 @@ +[package] +authors = ["Alexandre Bury "] +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" } + diff --git a/cursive/examples/Readme.md b/examples/Readme.md similarity index 66% rename from cursive/examples/Readme.md rename to examples/Readme.md index dfb6c9c..85c5614 100644 --- a/cursive/examples/Readme.md +++ b/examples/Readme.md @@ -3,101 +3,107 @@ Here are example programs using Cursive to help you getting familiar with the 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 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 composition. -## [`lorem`](lorem.rs) +## [`lorem`](src/bin/lorem.rs) This example loads a large text file to show scrolling behaviour. It also 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 the next view. It shows how to identify a view with an name and refer to it later. -## [`mutation`](mutation.rs) +## [`mutation`](src/bin/mutation.rs) 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. -## [`menubar`](menubar.rs) +## [`menubar`](src/bin/menubar.rs) Here we learn how to create a menubar at the top of the screen, and populate 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 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 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. -## [`list_view`](list_view.rs) +## [`list_view`](src/bin/list_view.rs) 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. -## [`markup`](markup.rs) +## [`markup`](src/bin/markup.rs) 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. -## [`theme_manual`](theme_manual.rs) +## [`theme_manual`](src/bin/theme_manual.rs) 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. -## [`colors`](colors.rs) +## [`colors`](src/bin/colors.rs) 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. -## [`progress`](progress.rs) +## [`progress`](src/bin/progress.rs) This shows how to send information from an asynchronous task (like a download or slow computation) to update a progress bar. -## [`radio`](radio.rs) +## [`radio`](src/bin/radio.rs) This shows how to use `RadioGroup` and `RadioButton`. -## [`slider`](slider.rs) +## [`slider`](src/bin/slider.rs) 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. diff --git a/cursive/assets/cities.txt b/examples/assets/cities.txt similarity index 100% rename from cursive/assets/cities.txt rename to examples/assets/cities.txt diff --git a/cursive/assets/lorem.txt b/examples/assets/lorem.txt similarity index 100% rename from cursive/assets/lorem.txt rename to examples/assets/lorem.txt diff --git a/cursive/assets/style.toml b/examples/assets/style.toml similarity index 100% rename from cursive/assets/style.toml rename to examples/assets/style.toml diff --git a/cursive/examples/colors.rs b/examples/src/bin/colors.rs similarity index 100% rename from cursive/examples/colors.rs rename to examples/src/bin/colors.rs diff --git a/cursive/examples/debug_console.rs b/examples/src/bin/debug_console.rs similarity index 100% rename from cursive/examples/debug_console.rs rename to examples/src/bin/debug_console.rs diff --git a/cursive/examples/dialog.rs b/examples/src/bin/dialog.rs similarity index 100% rename from cursive/examples/dialog.rs rename to examples/src/bin/dialog.rs diff --git a/cursive/examples/edit.rs b/examples/src/bin/edit.rs similarity index 100% rename from cursive/examples/edit.rs rename to examples/src/bin/edit.rs diff --git a/cursive/examples/hello_world.rs b/examples/src/bin/hello_world.rs similarity index 100% rename from cursive/examples/hello_world.rs rename to examples/src/bin/hello_world.rs diff --git a/cursive/examples/key_codes.rs b/examples/src/bin/key_codes.rs similarity index 100% rename from cursive/examples/key_codes.rs rename to examples/src/bin/key_codes.rs diff --git a/cursive/examples/linear.rs b/examples/src/bin/linear.rs similarity index 100% rename from cursive/examples/linear.rs rename to examples/src/bin/linear.rs diff --git a/cursive/examples/list_view.rs b/examples/src/bin/list_view.rs similarity index 100% rename from cursive/examples/list_view.rs rename to examples/src/bin/list_view.rs diff --git a/cursive/examples/logs.rs b/examples/src/bin/logs.rs similarity index 100% rename from cursive/examples/logs.rs rename to examples/src/bin/logs.rs diff --git a/cursive/examples/lorem.rs b/examples/src/bin/lorem.rs similarity index 93% rename from cursive/examples/lorem.rs rename to examples/src/bin/lorem.rs index 6973e9a..bcfa554 100644 --- a/cursive/examples/lorem.rs +++ b/examples/src/bin/lorem.rs @@ -4,7 +4,7 @@ use cursive::views::{Dialog, Panel, TextView}; fn main() { // 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(); diff --git a/cursive/examples/markup.rs b/examples/src/bin/markup.rs similarity index 100% rename from cursive/examples/markup.rs rename to examples/src/bin/markup.rs diff --git a/cursive/examples/menubar.rs b/examples/src/bin/menubar.rs similarity index 100% rename from cursive/examples/menubar.rs rename to examples/src/bin/menubar.rs diff --git a/cursive/examples/mines/Readme.md b/examples/src/bin/mines/Readme.md similarity index 100% rename from cursive/examples/mines/Readme.md rename to examples/src/bin/mines/Readme.md diff --git a/cursive/examples/mines/game.rs b/examples/src/bin/mines/game.rs similarity index 100% rename from cursive/examples/mines/game.rs rename to examples/src/bin/mines/game.rs diff --git a/cursive/examples/mines/main.rs b/examples/src/bin/mines/main.rs similarity index 100% rename from cursive/examples/mines/main.rs rename to examples/src/bin/mines/main.rs diff --git a/cursive/examples/mutation.rs b/examples/src/bin/mutation.rs similarity index 100% rename from cursive/examples/mutation.rs rename to examples/src/bin/mutation.rs diff --git a/cursive/examples/position.rs b/examples/src/bin/position.rs similarity index 100% rename from cursive/examples/position.rs rename to examples/src/bin/position.rs diff --git a/cursive/examples/progress.rs b/examples/src/bin/progress.rs similarity index 100% rename from cursive/examples/progress.rs rename to examples/src/bin/progress.rs diff --git a/cursive/examples/radio.rs b/examples/src/bin/radio.rs similarity index 100% rename from cursive/examples/radio.rs rename to examples/src/bin/radio.rs diff --git a/cursive/examples/refcell_view.rs b/examples/src/bin/refcell_view.rs similarity index 100% rename from cursive/examples/refcell_view.rs rename to examples/src/bin/refcell_view.rs diff --git a/cursive/examples/scroll.rs b/examples/src/bin/scroll.rs similarity index 100% rename from cursive/examples/scroll.rs rename to examples/src/bin/scroll.rs diff --git a/cursive/examples/select.rs b/examples/src/bin/select.rs similarity index 96% rename from cursive/examples/select.rs rename to examples/src/bin/select.rs index 13b046a..4099dde 100644 --- a/cursive/examples/select.rs +++ b/examples/src/bin/select.rs @@ -18,7 +18,7 @@ fn main() { // 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.) - let content = include_str!("../assets/cities.txt"); + let content = include_str!("../../assets/cities.txt"); select.add_all_str(content.lines()); // Sets the callback for when "Enter" is pressed. diff --git a/cursive/examples/select_test.rs b/examples/src/bin/select_test.rs similarity index 100% rename from cursive/examples/select_test.rs rename to examples/src/bin/select_test.rs diff --git a/cursive/examples/slider.rs b/examples/src/bin/slider.rs similarity index 100% rename from cursive/examples/slider.rs rename to examples/src/bin/slider.rs diff --git a/cursive/examples/tcp_server.rs b/examples/src/bin/tcp_server.rs similarity index 100% rename from cursive/examples/tcp_server.rs rename to examples/src/bin/tcp_server.rs diff --git a/cursive/examples/terminal_default.rs b/examples/src/bin/terminal_default.rs similarity index 100% rename from cursive/examples/terminal_default.rs rename to examples/src/bin/terminal_default.rs diff --git a/cursive/examples/text_area.rs b/examples/src/bin/text_area.rs similarity index 100% rename from cursive/examples/text_area.rs rename to examples/src/bin/text_area.rs diff --git a/cursive/examples/theme.rs b/examples/src/bin/theme.rs similarity index 100% rename from cursive/examples/theme.rs rename to examples/src/bin/theme.rs diff --git a/cursive/examples/theme_manual.rs b/examples/src/bin/theme_manual.rs similarity index 100% rename from cursive/examples/theme_manual.rs rename to examples/src/bin/theme_manual.rs diff --git a/cursive/examples/user_data.rs b/examples/src/bin/user_data.rs similarity index 100% rename from cursive/examples/user_data.rs rename to examples/src/bin/user_data.rs diff --git a/cursive/examples/vpv.rs b/examples/src/bin/vpv.rs similarity index 100% rename from cursive/examples/vpv.rs rename to examples/src/bin/vpv.rs