chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt
This commit is contained in:
@ -1,35 +1,35 @@
|
||||
/*! 📟 ConsoleBox - コンソール出力Box
|
||||
*
|
||||
*
|
||||
* ## 📝 概要
|
||||
* Webブラウザのコンソール機能を統合したBox。
|
||||
* WASM環境ではブラウザコンソール、ネイティブ環境では標準出力。
|
||||
*
|
||||
*
|
||||
* ## 🛠️ 利用可能メソッド
|
||||
* - `log(message)` - 通常のメッセージ出力
|
||||
* - `warn(message)` - 警告メッセージ出力
|
||||
* - `error(message)` - エラーメッセージ出力
|
||||
* - `clear()` - コンソール画面クリア
|
||||
*
|
||||
*
|
||||
* ## 💡 使用例
|
||||
* ```nyash
|
||||
* local console
|
||||
* console = new ConsoleBox()
|
||||
*
|
||||
*
|
||||
* console.log("Hello, Nyash!") // 通常ログ
|
||||
* console.warn("This is a warning") // 警告
|
||||
* console.error("Something went wrong") // エラー
|
||||
* console.clear() // クリア
|
||||
*
|
||||
*
|
||||
* // デバッグ用途
|
||||
* local value
|
||||
* value = 42
|
||||
* console.log("Debug: value = " + value.toString())
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* ## 🌐 環境別動作
|
||||
* - **WASM環境**: ブラウザの開発者ツールコンソールに出力
|
||||
* - **ネイティブ環境**: ターミナル標準出力にプレフィックス付きで出力
|
||||
*
|
||||
*
|
||||
* ## 🔍 デバッグ活用
|
||||
* ```nyash
|
||||
* // エラーハンドリング
|
||||
@ -37,7 +37,7 @@
|
||||
* console.error("Critical error occurred!")
|
||||
* return null
|
||||
* }
|
||||
*
|
||||
*
|
||||
* // 実行トレース
|
||||
* console.log("Function start")
|
||||
* // 処理...
|
||||
@ -45,7 +45,7 @@
|
||||
* ```
|
||||
*/
|
||||
|
||||
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
|
||||
use crate::box_trait::{BoolBox, BoxBase, BoxCore, NyashBox, StringBox};
|
||||
use std::any::Any;
|
||||
use std::fmt::Display;
|
||||
|
||||
@ -59,24 +59,26 @@ pub struct ConsoleBox {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
impl ConsoleBox {
|
||||
pub fn new() -> Self {
|
||||
Self { base: BoxBase::new() }
|
||||
Self {
|
||||
base: BoxBase::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Log messages to browser console
|
||||
pub fn log(&self, message: &str) {
|
||||
web_sys::console::log_1(&message.into());
|
||||
}
|
||||
|
||||
|
||||
/// Log warning to browser console
|
||||
pub fn warn(&self, message: &str) {
|
||||
web_sys::console::warn_1(&message.into());
|
||||
}
|
||||
|
||||
|
||||
/// Log error to browser console
|
||||
pub fn error(&self, message: &str) {
|
||||
web_sys::console::error_1(&message.into());
|
||||
}
|
||||
|
||||
|
||||
/// Clear browser console
|
||||
pub fn clear(&self) {
|
||||
web_sys::console::clear();
|
||||
@ -88,19 +90,19 @@ impl BoxCore for ConsoleBox {
|
||||
fn box_id(&self) -> u64 {
|
||||
self.base.id
|
||||
}
|
||||
|
||||
|
||||
fn parent_type_id(&self) -> Option<std::any::TypeId> {
|
||||
self.base.parent_type_id
|
||||
}
|
||||
|
||||
|
||||
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "[ConsoleBox - Browser Console Interface]")
|
||||
}
|
||||
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
@ -111,27 +113,26 @@ impl NyashBox for ConsoleBox {
|
||||
fn to_string_box(&self) -> StringBox {
|
||||
StringBox::new("[ConsoleBox - Browser Console Interface]")
|
||||
}
|
||||
|
||||
|
||||
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
|
||||
BoolBox::new(other.as_any().is::<ConsoleBox>())
|
||||
}
|
||||
|
||||
|
||||
fn type_name(&self) -> &'static str {
|
||||
"ConsoleBox"
|
||||
}
|
||||
|
||||
|
||||
fn clone_box(&self) -> Box<dyn NyashBox> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
|
||||
|
||||
/// 仮実装: clone_boxと同じ(後で修正)
|
||||
fn share_box(&self) -> Box<dyn NyashBox> {
|
||||
self.clone_box()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Non-WASM版 - モックアップ実装
|
||||
// Non-WASM版 - モックアップ実装
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ConsoleBox {
|
||||
@ -141,22 +142,24 @@ pub struct ConsoleBox {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl ConsoleBox {
|
||||
pub fn new() -> Self {
|
||||
Self { base: BoxBase::new() }
|
||||
Self {
|
||||
base: BoxBase::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Mock log method for non-WASM environments
|
||||
pub fn log(&self, message: &str) {
|
||||
println!("[Console LOG] {}", message);
|
||||
}
|
||||
|
||||
|
||||
pub fn warn(&self, message: &str) {
|
||||
println!("[Console WARN] {}", message);
|
||||
}
|
||||
|
||||
|
||||
pub fn error(&self, message: &str) {
|
||||
println!("[Console ERROR] {}", message);
|
||||
}
|
||||
|
||||
|
||||
pub fn clear(&self) {
|
||||
println!("[Console CLEAR]");
|
||||
}
|
||||
@ -167,19 +170,19 @@ impl BoxCore for ConsoleBox {
|
||||
fn box_id(&self) -> u64 {
|
||||
self.base.id
|
||||
}
|
||||
|
||||
|
||||
fn parent_type_id(&self) -> Option<std::any::TypeId> {
|
||||
self.base.parent_type_id
|
||||
}
|
||||
|
||||
|
||||
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "[ConsoleBox - Mock Implementation]")
|
||||
}
|
||||
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
@ -190,27 +193,25 @@ impl NyashBox for ConsoleBox {
|
||||
fn to_string_box(&self) -> StringBox {
|
||||
StringBox::new("[ConsoleBox - Mock Implementation]")
|
||||
}
|
||||
|
||||
|
||||
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
|
||||
BoolBox::new(other.as_any().is::<ConsoleBox>())
|
||||
}
|
||||
|
||||
|
||||
fn type_name(&self) -> &'static str {
|
||||
"ConsoleBox"
|
||||
}
|
||||
|
||||
|
||||
fn clone_box(&self) -> Box<dyn NyashBox> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
|
||||
|
||||
/// 仮実装: clone_boxと同じ(後で修正)
|
||||
fn share_box(&self) -> Box<dyn NyashBox> {
|
||||
self.clone_box()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Display implementations for both WASM and non-WASM versions
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
impl Display for ConsoleBox {
|
||||
|
||||
Reference in New Issue
Block a user