diff --git a/Cargo.lock b/Cargo.lock index f1fdba7f..b5e22f24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,6 +154,18 @@ dependencies = [ "serde", ] +[[package]] +name = "async-example" +version = "0.1.0" +dependencies = [ + "color-eyre", + "crossterm", + "octocrab 0.42.0", + "ratatui", + "tokio", + "tokio-stream", +] + [[package]] name = "async-trait" version = "0.1.83" @@ -367,8 +379,10 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", "serde", + "wasm-bindgen", "windows-targets", ] @@ -1598,6 +1612,46 @@ dependencies = [ "url", ] +[[package]] +name = "octocrab" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5235d5839910001bef2c3df99a88688c7c781e5b1fd5fe40c5d8fa8bd786ac5a" +dependencies = [ + "arc-swap", + "async-trait", + "base64 0.22.1", + "bytes", + "cfg-if", + "chrono", + "either", + "futures", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-timeout", + "hyper-util", + "jsonwebtoken", + "once_cell", + "percent-encoding", + "pin-project", + "secrecy", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "snafu", + "tokio", + "tower", + "tower-http", + "tracing", + "url", + "web-time", +] + [[package]] name = "once_cell" version = "1.20.2" @@ -2099,7 +2153,7 @@ dependencies = [ "indoc", "instability", "itertools 0.13.0", - "octocrab", + "octocrab 0.41.2", "palette", "pretty_assertions", "rand 0.8.5", @@ -2978,6 +3032,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.12" @@ -3356,6 +3421,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "wezterm-bidi" version = "0.2.3" diff --git a/Cargo.toml b/Cargo.toml index 22f85c4f..ab54d8cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,12 @@ [workspace] resolver = "2" -members = ["ratatui", "ratatui-core", "ratatui-widgets", "xtask"] +members = [ + "examples/*/*", + "ratatui", + "ratatui-core", + "ratatui-widgets", + "xtask", +] default-members = ["ratatui", "ratatui-core", "ratatui-widgets"] [workspace.package] @@ -25,6 +31,7 @@ rust-version = "1.74.0" [workspace.dependencies] bitflags = "2.6.0" +crossterm = { version = "0.28.1", features = ["event-stream"] } indoc = "2.0.5" instability = "0.3.1" itertools = "0.13.0" diff --git a/examples/apps/async/Cargo.toml b/examples/apps/async/Cargo.toml new file mode 100644 index 00000000..0249b7ff --- /dev/null +++ b/examples/apps/async/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "async-example" +version = "0.1.0" +authors.workspace = true +documentation.workspace = true +repository.workspace = true +homepage.workspace = true +keywords.workspace = true +categories.workspace = true +readme.workspace = true +license.workspace = true +exclude.workspace = true +edition.workspace = true +rust-version.workspace = true + +[dependencies] +color-eyre = "0.6.3" +crossterm = { workspace = true, features = ["event-stream"] } +octocrab = "0.42.0" +ratatui.workspace = true +tokio = { version = "1.41.1", features = ["rt-multi-thread", "macros"] } +tokio-stream = "0.1.16" diff --git a/ratatui/examples/async.rs b/examples/apps/async/src/main.rs similarity index 91% rename from ratatui/examples/async.rs rename to examples/apps/async/src/main.rs index c01761f5..ba453399 100644 --- a/ratatui/examples/async.rs +++ b/examples/apps/async/src/main.rs @@ -1,9 +1,7 @@ //! # [Ratatui] Async example //! //! This example demonstrates how to use Ratatui with widgets that fetch data asynchronously. It -//! uses the `octocrab` crate to fetch a list of pull requests from the GitHub API. You will need an -//! environment variable named `GITHUB_TOKEN` with a valid GitHub personal access token. The token -//! does not need any special permissions. +//! uses the `octocrab` crate to fetch a list of pull requests from the GitHub API. //! //! //! to create a new token (select classic, and no scopes) @@ -34,11 +32,10 @@ use std::{ time::Duration, }; -use color_eyre::{eyre::Context, Result, Section}; -use futures::StreamExt; +use color_eyre::Result; use octocrab::{ params::{pulls::Sort, Direction}, - OctocrabBuilder, Page, + Page, }; use ratatui::{ buffer::Buffer, @@ -49,29 +46,17 @@ use ratatui::{ widgets::{Block, HighlightSpacing, Row, StatefulWidget, Table, TableState, Widget}, DefaultTerminal, Frame, }; +use tokio_stream::StreamExt; #[tokio::main] async fn main() -> Result<()> { color_eyre::install()?; - init_octocrab()?; let terminal = ratatui::init(); let app_result = App::default().run(terminal).await; ratatui::restore(); app_result } -fn init_octocrab() -> Result<()> { - let token = std::env::var("GITHUB_TOKEN") - .wrap_err("The GITHUB_TOKEN environment variable was not found") - .suggestion( - "Go to https://github.com/settings/tokens/new to create a token, and re-run: - GITHUB_TOKEN=ghp_... cargo run --example async --features crossterm", - )?; - let crab = OctocrabBuilder::new().personal_token(token).build()?; - octocrab::initialise(crab); - Ok(()) -} - #[derive(Debug, Default)] struct App { should_quit: bool, diff --git a/ratatui/Cargo.toml b/ratatui/Cargo.toml index 4b9e1e74..cc6a9c61 100644 --- a/ratatui/Cargo.toml +++ b/ratatui/Cargo.toml @@ -15,7 +15,7 @@ edition.workspace = true rust-version.workspace = true [dependencies] -crossterm = { version = "0.28.1", optional = true } +crossterm = { workspace = true, optional = true } document-features = { version = "0.2.7", optional = true } indoc = "2" instability.workspace = true @@ -38,7 +38,7 @@ termion = { version = "4.0.0", optional = true } argh = "0.1.12" color-eyre = "0.6.2" criterion = { version = "0.5.1", features = ["html_reports"] } -crossterm = { version = "0.28.1", features = ["event-stream"] } +crossterm = { workspace = true, features = ["event-stream"] } fakeit = "1.1" font8x8 = "0.3.1" futures = "0.3.30" @@ -181,11 +181,6 @@ bench = false name = "main" harness = false -[[example]] -name = "async" -required-features = ["crossterm"] -doc-scrape-examples = true - [[example]] name = "barchart" required-features = ["crossterm"]