mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-09 10:50:40 +00:00
Add method to turn a CursiveRunnable into a CursiveRunner
This commit is contained in:
parent
58718824fa
commit
c0ddd5c302
12
CHANGELOG.md
12
CHANGELOG.md
@ -1,5 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## cursive-core 0.2.2, cursive 0.16.2
|
||||
|
||||
### API updates
|
||||
|
||||
- Add methods to turn a CursiveRunnable into a CursiveRunner.
|
||||
|
||||
## cursive 0.16.1
|
||||
|
||||
### Bugfixes
|
||||
|
||||
- Fix mouse input with crossterm backend.
|
||||
|
||||
## cursive-core 0.2.1
|
||||
|
||||
### Bugfixes
|
||||
|
@ -8,7 +8,7 @@ license = "MIT"
|
||||
name = "cursive_core"
|
||||
readme = "Readme.md"
|
||||
repository = "https://github.com/gyscos/cursive"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2-alpha"
|
||||
edition = "2018"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
|
@ -41,7 +41,8 @@ where
|
||||
}
|
||||
|
||||
impl<C> CursiveRunner<C> {
|
||||
pub(crate) fn new(siv: C, backend: Box<dyn backend::Backend>) -> Self {
|
||||
/// Creates a new cursive runner wrapper.
|
||||
pub fn new(siv: C, backend: Box<dyn backend::Backend>) -> Self {
|
||||
CursiveRunner {
|
||||
siv,
|
||||
backend,
|
||||
|
@ -8,14 +8,14 @@ license = "MIT"
|
||||
name = "cursive"
|
||||
readme = "../Readme.md"
|
||||
repository = "https://github.com/gyscos/cursive"
|
||||
version = "0.16.1"
|
||||
version = "0.16.2-alpha"
|
||||
edition = "2018"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["unstable_scroll", "markdown", "toml"]
|
||||
|
||||
[dependencies]
|
||||
cursive_core = { path = "../cursive-core", version= "0.2.1"}
|
||||
cursive_core = { path = "../cursive-core", version= "0.2.2-alpha"}
|
||||
crossbeam-channel = "0.5"
|
||||
cfg-if = "1"
|
||||
wasmer_enumset = "1"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{backend, backends, Cursive};
|
||||
use crate::{backend, backends, Cursive, CursiveRunner};
|
||||
|
||||
type Initializer =
|
||||
dyn FnMut()
|
||||
@ -63,6 +63,58 @@ impl CursiveRunnable {
|
||||
self.siv.try_run_with(&mut self.backend_init)
|
||||
}
|
||||
|
||||
/// Gets a runner with the registered backend.
|
||||
///
|
||||
/// Used to manually control the event loop. In most cases, running
|
||||
/// `run()` will be easier.
|
||||
///
|
||||
/// The runner will borrow `self`; when dropped, it will clear out the
|
||||
/// terminal, and the cursive instance will be ready for another run if
|
||||
/// needed.
|
||||
pub fn try_runner(
|
||||
&mut self,
|
||||
) -> Result<CursiveRunner<&mut Cursive>, Box<dyn std::error::Error>> {
|
||||
Ok(self.siv.runner((self.backend_init)()?))
|
||||
}
|
||||
|
||||
/// Gets a runner with the registered backend.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If the backend initialization fails.
|
||||
pub fn runner(&mut self) -> CursiveRunner<&mut Cursive> {
|
||||
self.try_runner().unwrap()
|
||||
}
|
||||
|
||||
/// Returns a new runner on the registered backend.
|
||||
///
|
||||
/// Used to manually control the event loop. In most cases, running
|
||||
/// `run()` will be easier.
|
||||
///
|
||||
/// The runner will embed `self`; when dropped, it will clear out the
|
||||
/// terminal, and the cursive instance will be dropped as well.
|
||||
pub fn try_into_runner(
|
||||
mut self,
|
||||
) -> Result<CursiveRunner<Self>, Box<dyn std::error::Error>> {
|
||||
let backend = (self.backend_init)()?;
|
||||
Ok(CursiveRunner::new(self, backend))
|
||||
}
|
||||
|
||||
/// Returns a new runner on the registered backend.
|
||||
///
|
||||
/// Used to manually control the event loop. In most cases, running
|
||||
/// `run()` will be easier.
|
||||
///
|
||||
/// The runner will embed `self`; when dropped, it will clear out the
|
||||
/// terminal, and the cursive instance will be dropped as well.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If the backend initialization fails.
|
||||
pub fn into_runner(self) -> CursiveRunner<Self> {
|
||||
self.try_into_runner().unwrap()
|
||||
}
|
||||
|
||||
/// Creates a new Cursive wrapper using the dummy backend.
|
||||
///
|
||||
/// Nothing will actually be output when calling `.run()`.
|
||||
|
Loading…
Reference in New Issue
Block a user