-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add modules `ui::service::{self, crossterm, miniquad}`. - add items: `CrosstermService`, `MiniquadService`, `MiniquadWindow`, `MiniquadEventHandlerExt`. - re-export a few `miniquad` items. - enable `ui··` flag via ui-related dependencies. - make ui dependencies version-specific. - misc. refactors. - update docs.
- Loading branch information
Showing
9 changed files
with
240 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// devela::ui::service::crossterm | ||
// | ||
//! `crossterm` Ui service. | ||
// | ||
|
||
mod service; | ||
// mod events; | ||
|
||
crate::items! { // structural access: _mods, _all | ||
#[allow(unused)] | ||
pub use _mods::*; | ||
|
||
mod _mods { | ||
pub use super::service::*; | ||
} | ||
pub(super) mod _all { #![allow(unused)] | ||
#[doc(inline)] | ||
pub use super::_mods::*; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// devela::ui::service::crossterm::service | ||
// | ||
//! Defines [`CrosstermService`]. | ||
// | ||
// ISSUES | ||
// - WAIT: [add Event::Terminate](https://github.com/crossterm-rs/crossterm/issues/554) | ||
// - WAIT: [support ctrl+z + fg](https://github.com/crossterm-rs/crossterm/issues/494) | ||
// | ||
// TODO | ||
// - window refresh, render | ||
|
||
use ::crossterm::{event, execute, terminal}; | ||
|
||
// use core::time::Duration; | ||
use std::io; | ||
|
||
use crate::{ | ||
IoError, UiCap, UiCapImage, /* Event, EventSource, */ UiCapInput, | ||
/* Window, */ UiCapWindow, UiService, | ||
}; | ||
|
||
/// `crossterm`'s UI service. | ||
// | ||
// https://docs.rs/crossterm/latest/crossterm/terminal/index.html | ||
pub struct CrosstermService; | ||
// { raw_mode: bool, } | ||
|
||
// TODO | ||
// impl Drop for CrosstermService { | ||
// fn drop(&mut self) { | ||
// if self.raw_mode { | ||
// self.set_raw_mode(false); | ||
// } | ||
// } | ||
// } | ||
|
||
impl CrosstermService { | ||
/// Creates a new `CrosstermService`. | ||
pub fn new() -> Result<Self, IoError> { | ||
Ok(Self { /* raw_mode: false */ }) | ||
} | ||
|
||
/// Tells whether the raw mode is enabled. | ||
// | ||
// https://docs.rs/crossterm/latest/crossterm/terminal/fn.is_raw_mode_enabled.html | ||
#[inline] | ||
pub fn is_raw_mode(&self) -> Result<bool, IoError> { | ||
terminal::is_raw_mode_enabled() | ||
} | ||
|
||
/// Enables the raw mode. | ||
// | ||
// https://docs.rs/crossterm/latest/crossterm/terminal/fn.enable_raw_mode.html | ||
#[inline] | ||
pub fn enable_raw_mode(&self) -> Result<(), IoError> { | ||
terminal::enable_raw_mode() | ||
} | ||
|
||
/// Disables the raw mode. | ||
// | ||
// https://docs.rs/crossterm/latest/crossterm/terminal/fn.disable_raw_mode.html | ||
#[inline] | ||
pub fn disable_raw_mode(&self) -> Result<(), IoError> { | ||
terminal::disable_raw_mode() | ||
} | ||
|
||
/// Switches to the alternate screen. | ||
// | ||
// https://docs.rs/crossterm/latest/crossterm/terminal/struct.EnterAlternateScreen.html | ||
pub fn enter_alternate_screen(&self) -> Result<(), IoError> { | ||
Ok(execute!(io::stdout(), terminal::EnterAlternateScreen)?) | ||
} | ||
|
||
/// Switches back to the main screen. | ||
// | ||
// https://docs.rs/crossterm/latest/crossterm/terminal/struct.LeaveAlternateScreen.html | ||
pub fn leave_alternate_screen(&self) -> Result<(), IoError> { | ||
Ok(execute!(io::stdout(), terminal::EnterAlternateScreen)?) | ||
} | ||
|
||
/// Enables receiving mouse events. | ||
// | ||
// https://docs.rs/crossterm/latest/crossterm/event/struct.EnableMouseCapture.html | ||
pub fn enable_mouse(&mut self) -> Result<(), IoError> { | ||
Ok(execute!(io::stdout(), event::EnableMouseCapture)?) | ||
} | ||
/// Disables receiving mouse events. | ||
// | ||
// https://docs.rs/crossterm/latest/crossterm/event/struct.DisableMouseCapture.html | ||
pub fn disable_mouse(&mut self) -> Result<(), IoError> { | ||
Ok(execute!(io::stdout(), event::DisableMouseCapture)?) | ||
} | ||
|
||
// TODO | ||
// /// Enables bracketed paste mode. | ||
// // | ||
// // https://docs.rs/crossterm/latest/crossterm/event/struct.EnableBracketedPaste.html | ||
// pub fn enable_bracketed_paste(&self) -> Result<(), IoError> { | ||
// Ok(execute!(io::stdout(), event::EnableBracketedPaste)?) | ||
// } | ||
// | ||
// /// Disables bracketed paste mode. | ||
// // | ||
// // https://docs.rs/crossterm/latest/crossterm/event/struct.DisableBracketedPaste.html | ||
// pub fn disable_bracketed_paste(&self) -> Result<(), IoError> { | ||
// Ok(execute!(io::stdout(), event::DisableBracketedPaste)?) | ||
// } | ||
|
||
/// Enables focus change mode. | ||
// | ||
// https://docs.rs/crossterm/latest/crossterm/event/struct.EnableFocusChange.html | ||
pub fn enable_focus_change(&self) -> Result<(), IoError> { | ||
Ok(execute!(io::stdout(), event::EnableFocusChange)?) | ||
} | ||
|
||
/// Disables focus change mode. | ||
// | ||
// https://docs.rs/crossterm/latest/crossterm/event/struct.DisableFocusChange.html | ||
pub fn disable_focus_change(&self) -> Result<(), IoError> { | ||
Ok(execute!(io::stdout(), event::DisableFocusChange)?) | ||
} | ||
} | ||
|
||
impl UiService for CrosstermService { | ||
fn capabilities(&self) -> UiCap { | ||
let image = Some(UiCapImage { | ||
rgb: true, | ||
// palette_change: false, | ||
// palette_size: ::crossterm::style::available_color_count(), | ||
..Default::default() | ||
}); | ||
|
||
let input = Some(UiCapInput { keyboard: true, mouse: true, ..Default::default() }); | ||
|
||
// let text_grid = Some(UiCapTextGridCap { | ||
// // we don't unknown | ||
// cell_size: None, | ||
// // https://github.com/crossterm-rs/crossterm/issues/166 | ||
// // custom_cell_size: false, | ||
// // // https://github.com/crossterm-rs/crossterm/issues/677 | ||
// // unicode: true, | ||
// // ..Default::default() | ||
// }); | ||
|
||
let window = Some(UiCapWindow { multi: false }); | ||
|
||
UiCap { | ||
image, | ||
input, | ||
// text_grid, | ||
window, | ||
..Default::default() | ||
} | ||
} | ||
|
||
fn version(&self) -> (u32, u32, u32) { | ||
(0, 28, 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// devela::ui::service::miniquad::reexports | ||
// | ||
//! | ||
// | ||
|
||
use crate::reexport; | ||
|
||
/* structs */ | ||
|
||
reexport! { "dep_miniquad", "miniquad", miniquad::conf, | ||
doc: "Describes a hardware and platform-specific setup.", | ||
@Conf as MiniquadConf | ||
} | ||
reexport! { "dep_miniquad", "miniquad", miniquad::conf, | ||
doc: "Platform-specific settings.", | ||
@Platform as MiniquadPlatform | ||
} | ||
|
||
/* traits */ | ||
|
||
reexport! { "dep_miniquad", "miniquad", miniquad, | ||
doc: "Defines how an application responds to events in miniquad.", | ||
@EventHandler as MiniquadEventHandler | ||
} | ||
reexport! { "dep_miniquad", "miniquad", miniquad::graphics, | ||
doc: "Low-level interface for rendering operations in miniquad.", | ||
@RenderingBackend as MiniquadRenderingBackend | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters