#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![warn(missing_docs, clippy::unwrap_used, clippy::expect_used)]
#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used))]
#![cfg_attr(not(any(feature = "terminal", feature = "window")), allow(dead_code))]
mod app;
mod args;
#[cfg(feature = "clipboard")]
pub mod clipboard;
pub mod config;
#[cfg(feature = "toml")]
mod config_file;
pub mod gesture;
pub mod gpu;
mod help;
#[cfg(feature = "terminal")]
pub mod terminal;
mod waker;
#[cfg(feature = "window")]
pub mod window;
#[cfg(any(feature = "terminal", feature = "window"))]
use app::End;
pub use app::{App, Flow, ViewSlot};
pub use config::{Backend, Config, Mode, Palette, Protocol};
pub use gesture::{DragAction, Gesture, GestureKind, GestureType, Input, ScrollAction};
pub use gpu::{render_to_rgba, share, Gpu, GpuView, PixelRect, SharedView, Target, Views};
pub use help::Help;
pub use waker::Waker;
pub use crossterm;
pub use ratatui;
pub use wgpu;
pub fn run(app: &mut dyn App, views: Views, config: &Config) -> Result<(), String> {
#[cfg(not(any(feature = "terminal", feature = "window")))]
return {
let _ = (app, views);
Err(format!(
"{:?} mode is not compiled in; enable the scopekit feature",
config.mode
))
};
#[cfg(any(feature = "terminal", feature = "window"))]
{
let started = config.mode;
let mut mode = started;
loop {
let end = match mode {
#[cfg(feature = "terminal")]
Mode::Terminal => terminal::session(app, views.clone(), config)?,
#[cfg(feature = "window")]
Mode::Window => window::session(app, views.clone(), config, mode != started)?,
#[allow(unreachable_patterns)]
other => {
return Err(format!(
"{other:?} mode is not compiled in; enable the scopekit feature"
))
}
};
if end == End::Quit {
return Ok(());
}
mode = match mode {
Mode::Terminal => Mode::Window,
Mode::Window => Mode::Terminal,
};
if mode == Mode::Window {
if let Some(k) = config.switch_key {
eprintln!(
"{} runs in its window; press {k} there to come back.",
config.title
);
}
}
app.mode_changed(mode);
}
}
}
#[cfg(doctest)]
#[doc = include_str!("../HOWTO.md")]
struct HowtoDoctests;