bracket_terminal/hal/
mod.rs

1// Enable modules based on target architecture
2#[cfg(feature = "opengl")]
3mod gl_common;
4
5#[cfg(feature = "opengl")]
6pub use gl_common::*;
7
8#[cfg(all(feature = "opengl", not(target_arch = "wasm32")))]
9mod native;
10
11#[cfg(all(feature = "opengl", not(target_arch = "wasm32")))]
12pub use native::*;
13
14#[cfg(all(feature = "opengl", target_arch = "wasm32"))]
15mod wasm;
16
17#[cfg(all(feature = "opengl", target_arch = "wasm32"))]
18pub use wasm::*;
19
20#[cfg(all(not(feature = "opengl"), feature = "webgpu"))]
21mod webgpu;
22
23#[cfg(all(not(feature = "opengl"), feature = "webgpu"))]
24pub use webgpu::*;
25
26#[cfg(not(feature = "opengl"))]
27#[cfg(all(not(feature = "opengl"), feature = "curses"))]
28mod curses;
29
30#[cfg(all(not(feature = "opengl"), feature = "curses"))]
31pub use curses::*;
32
33#[cfg(not(feature = "opengl"))]
34#[cfg(all(not(feature = "opengl"), feature = "cross_term"))]
35mod crossterm_be;
36
37#[cfg(all(not(feature = "opengl"), feature = "cross_term"))]
38pub use crossterm_be::*;
39
40#[cfg(all(
41    not(feature = "opengl"),
42    not(feature = "curses"),
43    not(feature = "webgpu"),
44    not(feature = "crossterm")
45))]
46mod dummy;
47
48#[cfg(all(
49    not(feature = "opengl"),
50    not(feature = "curses"),
51    not(feature = "webgpu"),
52    not(feature = "crossterm")
53))]
54pub use dummy::*;
55
56#[cfg(any(feature = "opengl", feature = "webgpu"))]
57mod scaler;
58
59/// Provides a base abstract platform for BTerm to run on, with specialized content.
60pub struct BTermPlatform {
61    pub platform: PlatformGL,
62}
63
64#[allow(dead_code)]
65fn convert_fps_to_wait(frame_sleep_time: Option<f32>) -> Option<u64> {
66    frame_sleep_time.map(|f| (f * 1000.0) as u64)
67}
68
69#[allow(dead_code)]
70fn fps_sleep(frame_sleep_time: Option<u64>, now: &std::time::Instant, prev_ms: u128) {
71    if let Some(wait_time) = frame_sleep_time {
72        let execute_ms = now.elapsed().as_millis() as u64 - prev_ms as u64;
73        if execute_ms < wait_time {
74            std::thread::sleep(std::time::Duration::from_millis(wait_time - execute_ms));
75        }
76    }
77}