Skip to content

Commit

Permalink
Merge branch 'boardwidget'
Browse files Browse the repository at this point in the history
  • Loading branch information
jfredett committed Oct 5, 2024
2 parents 8779a04 + 1dfd778 commit 705a4c4
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 181 deletions.
73 changes: 73 additions & 0 deletions LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,76 @@ Did I accidentally re-invent React? I don't know, just seems logical to me, I'm
For the moment I'm just going to eat crow and thread everything through, it's ugly but it will work.


# 4-OCT-2024

## 2339

While working on the UI yesterday and a bit today, I thought I was going to have the opportunity to do some extremely
cursed things with unicode variables and stuff, but alas it was not to be. I did, however, make this at one point:


```rust

let table = Table::new([
Row::new(vec!["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]),
Row::new(vec!["", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", ""]),
Row::new(vec!["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]),
Row::new(vec!["", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", ""]),
Row::new(vec!["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]),
Row::new(vec!["", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", ""]),
Row::new(vec!["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]),
Row::new(vec!["", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", ""]),
Row::new(vec!["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]),
Row::new(vec!["", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", ""]),
Row::new(vec!["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]),
Row::new(vec!["", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", "", " ", " ", " ", ""]),
Row::new(vec!["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]),
Row::new(vec!["", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", ""]),
Row::new(vec!["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]),
Row::new(vec!["", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", "", " ", ""]),
Row::new(vec!["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]),


], Constraint::from_maxes(vec![1].repeat(33)))
.column_spacing(0)
.style(
Style::default().bg(Color::White).fg(Color::Black)
);
```

Which is beautiful in both rendering and absolute piss-elegance. I did not want it to go to waste in /dev/null, so I
have recorded it here.


# 5-OCT-2024

## 0015

These too:

```rust

const EMPTY : &'static str = " ";

const HORIZONTAL : &'static str = "";
const TOP_LEFT_CORNER : &'static str = "";
const TOP_RIGHT_CORNER : &'static str = "";
const BOTTOM_LEFT_CORNER : &'static str = "";
const BOTTOM_RIGHT_CORNER : &'static str = "";
const VERTICAL : &'static str = "";
const CROSS : &'static str = "";
const TEE_RIGHT : &'static str = "";
const TEE_LEFT : &'static str = "";
const TEE_DOWN : &'static str = "";
const TEE_UP : &'static str = "";

const TRANSPARENT_ROOK : &'static str = "";
const TRANSPARENT_KNIGHT : &'static str = "";
const TRANSPARENT_BISHOP : &'static str = "";
const TRANSPARENT_QUEEN : &'static str = "";
const TRANSPARENT_KING : &'static str = "";
const TRANSPARENT_PAWN : &'static str = "";

```

They may be useful again someday.
60 changes: 32 additions & 28 deletions src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use tracing::{debug, instrument};
use crate::uci::UCIMessage;
use crate::ui::model::entry::{Entry, stockfish};
use crate::engine::Engine;
use crate::ui::model::pieceboard::PieceBoard;

use super::widgets::tile::Tile;

Expand Down Expand Up @@ -50,10 +51,11 @@ impl Hazel {
s.entry.exec(UCIMessage::UCI);
s.entry.exec(UCIMessage::IsReady);
debug!("setting startpos");
s.entry.exec(UCIMessage::Position("startpos".to_string(), vec![]));
s.entry.exec(UCIMessage::Position("startpos moves d2d4".to_string(), vec![]));
debug!("setting startpos done");

s.entry.boardstate.set_startpos();
// s.entry.boardstate.set_startpos();
s.entry.boardstate = PieceBoard::from_fen("rnbqkbnr/pppppppp/8/8/3P4/8/PPP1PPPP/RNBQKBNR");

return s;
}
Expand Down Expand Up @@ -131,8 +133,8 @@ impl Hazel {

#[instrument]
pub fn render(&mut self, frame: &mut Frame) {
let tile = &self.tile;
frame.render_stateful_widget(tile, Rect::new(0,0,64,32), &mut ());
self.tile.set_state(self.entry.boardstate.clone());
frame.render_widget(&self.tile, Rect::new(0,0,64,32));
}
}

Expand All @@ -154,23 +156,25 @@ mod tests {
});

let mut expected = Buffer::with_lines(vec![
" Placeholder ┌─────────────────────────────┐",
" Placeholder │ Placeholder │",
" Placeholder │ Placeholder │",
"┌───────────────┐┌──────────────┐│ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder ││ Placeholder │",
"│ Placeholder ││ Placeholder │└─────────────────────────────┘",
"└───────────────┘└──────────────┘ Placeholder ",
" Placeholder R N B Q K B N R ",
" Placeholder a8 b8 c8 d8 e8 f8 g8 h8 ",
" Placeholder P P P P P P P P ",
"┌──────────────────┐┌──────────────────┐a7 b7 c7 d7 e7 f7 g7 h7 ",
"│ Placeholder ││ Placeholder │ ",
"│ Placeholder ││ Placeholder │a6 b6 c6 d6 e6 f6 g6 h6 ",
"│ Placeholder ││ Placeholder │ ",
"│ Placeholder ││ Placeholder │a5 b5 c5 d5 e5 f5 g5 h5 ",
"│ Placeholder ││ Placeholder │ P ",
"│ Placeholder ││ Placeholder │a4 b4 c4 d4 e4 f4 g4 h4 ",
"│ Placeholder ││ Placeholder │ ",
"│ Placeholder ││ Placeholder │a3 b3 c3 d3 e3 f3 g3 h3 ",
"│ Placeholder ││ Placeholder │ P P P P P P P ",
"│ Placeholder ││ Placeholder │a2 b2 c2 d2 e2 f2 g2 h2 ",
"│ Placeholder ││ Placeholder │ R N B Q K B N R ",
"│ Placeholder ││ Placeholder │a1 b1 c1 d1 e1 f1 g1 h1 ",
"│ Placeholder ││ Placeholder │ Placeholder ",
"│ Placeholder ││ Placeholder │ Placeholder ",
"└──────────────────┘└──────────────────┘ Placeholder ",
"│ Placeholder │",
"┌──────────────────────────────────────────────────────────────┐",
"│ │",
Expand All @@ -182,17 +186,17 @@ mod tests {
"│ │",
"│ │",
"│ │",
"│ │",
"│ │",
"└──────────────────────────────────────────────────────────────┘",
"$> ",
]);

// Ignore style differences for now
let mut actual = t.backend().buffer().clone();
actual.set_style(Rect::new(0, 0, 64, 32), Style::default().fg(Color::White).bg(Color::Black));
expected.set_style(Rect::new(0, 0, 64, 32), Style::default().fg(Color::White).bg(Color::Black));
let actual = t.backend().buffer().clone();

// Ignore style differences for now, by... turning everything into a big list of chars
// wrapped in &strs wrapped in my pain and suffering.
let expected_content : Vec<String> = expected.content().iter().map(|x| x.symbol().to_string()).collect();
let actual_content : Vec<String> = actual.content().iter().map(|x| x.symbol().to_string()).collect();

assert_eq!(actual, expected);
assert_eq!(actual_content, expected_content);
}
}
23 changes: 11 additions & 12 deletions src/ui/widgets/engine_io_section/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ impl Default for EngineIOSection {
}
}

impl StatefulWidget for &EngineIOSection {
type State = ();
fn render(self, area: Rect, buf: &mut Buffer, _state: &mut Self::State) {
impl Widget for &EngineIOSection {
fn render(self, area: Rect, buf: &mut Buffer) {
let chunks = LAYOUT.split(area);

// NOTE: I don't fully understand why the buffer is passed like this, since it's already
Expand All @@ -74,7 +73,7 @@ mod tests {
let mut buffer = Buffer::empty(rect);
buffer.set_style(rect, Style::default().fg(Color::White).bg(Color::Black));

let engine_io_section = &mut EngineIOSection::default();
let mut engine_io_section = EngineIOSection::default();

// Mock out the output from the 'engine'
engine_io_section.push("Stockfish 16.1 by the Stockfish developers (see AUTHORS file)".to_string());
Expand All @@ -87,7 +86,7 @@ mod tests {
engine_io_section.push("info depth 1 seldepth 2 multipv 1 score cp 0 nodes 20 nps 1000 hashfull 0 tbhits 0 time 20 pv d2d4".to_string());
engine_io_section.push("bestmove d2d4".to_string());

engine_io_section.render(rect, &mut buffer, &mut ());
engine_io_section.render(rect, &mut buffer);

let mut expected = Buffer::with_lines(vec![
"┌──────────────────────────────────────────────────────────────┐",
Expand Down Expand Up @@ -119,12 +118,12 @@ mod tests {
let mut buffer = Buffer::empty(rect);
buffer.set_style(rect, Style::default().fg(Color::White).bg(Color::Black));

let engine_io_section = &mut EngineIOSection::default();
let mut engine_io_section = EngineIOSection::default();


engine_io_section.push("A line exceeding, the buffers shortened width, should be wrapped around.".to_string());

engine_io_section.render(rect, &mut buffer, &mut ());
engine_io_section.render(rect, &mut buffer);

let mut expected = Buffer::with_lines(vec![
"┌─────────────────────────┐",
Expand All @@ -145,7 +144,7 @@ mod tests {
let mut buffer = Buffer::empty(rect);
buffer.set_style(rect, Style::default().fg(Color::White).bg(Color::Black));

let engine_io_section = &mut EngineIOSection::default();
let mut engine_io_section = EngineIOSection::default();

engine_io_section.handle_input('a');
engine_io_section.handle_input('b');
Expand All @@ -155,7 +154,7 @@ mod tests {
engine_io_section.handle_input('f');
engine_io_section.handle_input('g');

engine_io_section.render(rect, &mut buffer, &mut ());
engine_io_section.render(rect, &mut buffer);

let mut expected = Buffer::with_lines(vec![
"┌──────────────────────────────────────────────────────────────┐",
Expand Down Expand Up @@ -202,7 +201,7 @@ mod tests {

engine_io_section.handle_backspace();

engine_io_section.render(rect, &mut buffer, &mut ());
engine_io_section.render(rect, &mut buffer);

let mut expected = Buffer::with_lines(vec![
"┌──────────────────────────────────────────────────────────────┐",
Expand Down Expand Up @@ -237,7 +236,7 @@ mod tests {
let mut buffer = Buffer::empty(rect);
buffer.set_style(rect, Style::default().fg(Color::White).bg(Color::Black));

let engine_io_section = &mut EngineIOSection::default();
let mut engine_io_section = EngineIOSection::default();

engine_io_section.handle_input('a');
engine_io_section.handle_input('b');
Expand All @@ -249,7 +248,7 @@ mod tests {

engine_io_section.handle_enter();

engine_io_section.render(rect, &mut buffer, &mut ());
engine_io_section.render(rect, &mut buffer);

let mut expected = Buffer::with_lines(vec![
"┌──────────────────────────────────────────────────────────────┐",
Expand Down
Loading

0 comments on commit 705a4c4

Please sign in to comment.