chessfriend/core/src/pieces/display.rs
Eryn Wells 9010f1e9c2 [explorer, moves, core] Improve error handling in explorer
Implement thiserror::Error for a bunch of error types, and remove string errors
from the implementation of the command handler in explorer.

Clean up parsing of basic types all over the place.

Update Cargo files to include thiserror and anyhow.
2025-05-19 14:18:31 -07:00

28 lines
725 B
Rust

// Eryn Wells <eryn@erynwells.me>
use super::Piece;
#[derive(Default)]
pub enum PieceDisplayStyle {
#[default]
Unicode,
ASCII,
LongForm,
}
pub struct PieceDisplay {
pub(super) piece: Piece,
pub(super) style: PieceDisplayStyle,
}
impl std::fmt::Display for PieceDisplay {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.style {
PieceDisplayStyle::Unicode => write!(f, "{}", self.piece.to_unicode()),
PieceDisplayStyle::ASCII => write!(f, "{}", self.piece.to_ascii()),
PieceDisplayStyle::LongForm => {
write!(f, "{} {}", self.piece.color.name(), self.piece.shape.name())
}
}
}
}