() {
html_element.set_scroll_top(html_element.scroll_height());
}
}
}
/// ログメッセージを出力
pub fn log(&self, message: &str) {
self.append_console_line(message, "log");
}
/// 警告メッセージを出力
pub fn warn(&self, message: &str) {
self.append_console_line(message, "warn");
}
/// エラーメッセージを出力
pub fn error(&self, message: &str) {
self.append_console_line(message, "error");
}
/// 情報メッセージを出力
pub fn info(&self, message: &str) {
self.append_console_line(message, "info");
}
/// デバッグメッセージを出力
pub fn debug(&self, message: &str) {
self.append_console_line(message, "debug");
}
/// コンソールをクリア
pub fn clear(&self) {
if let Some(element) = self.get_target_element() {
element.set_inner_html("");
}
}
/// 区切り線を追加
pub fn separator(&self) {
if let Some(element) = self.get_target_element() {
let current_content = element.inner_html();
let separator_line = "
";
let new_content = format!("{}{}", current_content, separator_line);
element.set_inner_html(&new_content);
}
}
/// グループ開始(見出し付き)
pub fn group(&self, title: &str) {
if let Some(element) = self.get_target_element() {
let current_content = element.inner_html();
let group_header = format!(
"📂 {}
",
title
);
let new_content = format!("{}{}", current_content, group_header);
element.set_inner_html(&new_content);
}
}
/// グループ終了
pub fn group_end(&self) {
if let Some(element) = self.get_target_element() {
let current_content = element.inner_html();
let group_footer = "
";
let new_content = format!("{}{}", current_content, group_footer);
element.set_inner_html(&new_content);
}
}
}
#[cfg(target_arch = "wasm32")]
impl BoxCore for WebConsoleBox {
fn box_id(&self) -> u64 {
self.base.id
}
fn parent_type_id(&self) -> Option {
self.base.parent_type_id
}
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "WebConsoleBox({})", self.target_element_id)
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
#[cfg(target_arch = "wasm32")]
impl NyashBox for WebConsoleBox {
fn clone_box(&self) -> Box {
Box::new(self.clone())
}
/// 仮実装: clone_boxと同じ(後で修正)
fn share_box(&self) -> Box {
self.clone_box()
}
fn to_string_box(&self) -> StringBox {
StringBox::new(format!("WebConsoleBox({})", self.target_element_id))
}
fn type_name(&self) -> &'static str {
"WebConsoleBox"
}
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
if let Some(other_console) = other.as_any().downcast_ref::() {
BoolBox::new(self.base.id == other_console.base.id)
} else {
BoolBox::new(false)
}
}
}
#[cfg(target_arch = "wasm32")]
impl std::fmt::Display for WebConsoleBox {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.fmt_box(f)
}
}