diff --git a/board/src/display.rs b/board/src/display.rs index 73c59a9..b7eb86f 100644 --- a/board/src/display.rs +++ b/board/src/display.rs @@ -5,9 +5,17 @@ use chessfriend_bitboard::BitBoard; use chessfriend_core::{File, Rank, Square}; use std::fmt; +#[derive(Default)] +pub enum PieceDisplayStyle { + #[default] + Unicode, + ASCII, +} + #[must_use] pub struct DiagramFormatter<'a> { board: &'a Board, + piece_style: PieceDisplayStyle, marked_squares: BitBoard, highlighted_squares: BitBoard, } @@ -16,6 +24,7 @@ impl<'a> DiagramFormatter<'a> { pub fn new(board: &'a Board) -> Self { Self { board, + piece_style: PieceDisplayStyle::default(), marked_squares: BitBoard::default(), highlighted_squares: BitBoard::default(), } @@ -48,7 +57,11 @@ impl fmt::Display for DiagramFormatter<'_> { } if let Some(piece) = self.board.get_piece(square) { - write!(f, "{piece}")?; + let ch = match self.piece_style { + PieceDisplayStyle::Unicode => piece.to_unicode(), + PieceDisplayStyle::ASCII => piece.to_ascii(), + }; + write!(f, "{ch}")?; } else { let ch = if self.marked_squares.contains(square) { '*' diff --git a/core/src/pieces.rs b/core/src/pieces.rs index a580967..a335aa9 100644 --- a/core/src/pieces.rs +++ b/core/src/pieces.rs @@ -63,7 +63,7 @@ impl Piece { } #[must_use] - fn to_unicode(self) -> char { + pub fn to_unicode(self) -> char { match (self.color, self.shape) { (Color::Black, Shape::Pawn) => '♟', (Color::Black, Shape::Knight) => '♞',