Split WASM and native versions, and move iced support code to native
This commit is contained in:
36
src/debug.rs
36
src/debug.rs
@@ -2,6 +2,7 @@ use std::num::NonZeroUsize;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DebugLog {
|
||||
enabled: bool,
|
||||
current: String,
|
||||
history: Vec<String>,
|
||||
max_history: Option<NonZeroUsize>,
|
||||
@@ -11,6 +12,7 @@ pub struct DebugLog {
|
||||
impl DebugLog {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
enabled: false,
|
||||
current: String::new(),
|
||||
history: vec![],
|
||||
max_history: None,
|
||||
@@ -47,25 +49,41 @@ impl DebugLog {
|
||||
pub fn pop(&mut self) -> Option<String> {
|
||||
self.history.pop()
|
||||
}
|
||||
|
||||
pub fn enable(&mut self) {
|
||||
self.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Write for DebugLog {
|
||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||
let tmp = self.current.write_str(s);
|
||||
self.rotate();
|
||||
tmp
|
||||
if self.enabled {
|
||||
let tmp = self.current.write_str(s);
|
||||
self.rotate();
|
||||
tmp
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn write_char(&mut self, c: char) -> std::fmt::Result {
|
||||
let tmp = self.current.write_char(c);
|
||||
self.rotate();
|
||||
tmp
|
||||
if self.enabled {
|
||||
let tmp = self.current.write_char(c);
|
||||
self.rotate();
|
||||
tmp
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::fmt::Result {
|
||||
let tmp = self.current.write_fmt(args);
|
||||
self.rotate();
|
||||
tmp
|
||||
if self.enabled {
|
||||
let tmp = self.current.write_fmt(args);
|
||||
self.rotate();
|
||||
tmp
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user