more scripting
This commit is contained in:
+12
-6
@@ -21,13 +21,13 @@ use ratatui::crossterm::event::{
|
||||
use ratatui::crossterm::execute;
|
||||
use ratatui::layout::{Constraint, Layout, Spacing};
|
||||
use ratatui::style::{Color, Style};
|
||||
use ratatui::symbols::merge::MergeStrategy;
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Paragraph, Wrap};
|
||||
use render::{BoardWidget, logline_to_line};
|
||||
use std::io;
|
||||
use std::process::ExitCode;
|
||||
use std::time::{Duration, Instant};
|
||||
use ratatui::symbols::merge::MergeStrategy;
|
||||
use term::TerminalCaps;
|
||||
|
||||
/// View-only UI state for the log panel. This is presentation state, so it lives
|
||||
@@ -197,7 +197,9 @@ fn scroll_log(ui: &mut Ui, game: &GameState, delta: i32) {
|
||||
/// panel across the bottom. When the panel is closed the latest log message is
|
||||
/// previewed in the board's bottom-left border after a `[l]og:` label.
|
||||
fn draw(frame: &mut Frame, game: &GameState, ui: &Ui) {
|
||||
let board = &game.board;
|
||||
// Borrow the board for the duration of the frame (no script runs during draw).
|
||||
let board = game.board();
|
||||
let board = &*board;
|
||||
|
||||
if ui.log_open {
|
||||
// Split the screen: board on top, log panel of `log_height` at the bottom.
|
||||
@@ -206,14 +208,19 @@ fn draw(frame: &mut Frame, game: &GameState, ui: &Ui) {
|
||||
.spacing(Spacing::Overlap(1))
|
||||
.areas(frame.area());
|
||||
|
||||
let block = Block::bordered().title(format!(" {} ", board.name)).merge_borders(MergeStrategy::Exact);
|
||||
let block = Block::bordered()
|
||||
.title(format!(" {} ", board.name))
|
||||
.merge_borders(MergeStrategy::Exact);
|
||||
let inner = block.inner(board_area);
|
||||
frame.render_widget(block, board_area);
|
||||
frame.render_widget(BoardWidget::new(board), inner);
|
||||
|
||||
// Newest message on top: reverse the log into ratatui lines.
|
||||
let log_block = Block::bordered()
|
||||
.title(Span::styled(" [l]og: ", Style::default().fg(Color::DarkGray)))
|
||||
.title(Span::styled(
|
||||
" [l]og: ",
|
||||
Style::default().fg(Color::DarkGray),
|
||||
))
|
||||
.merge_borders(MergeStrategy::Exact);
|
||||
let lines: Vec<Line> = game.log.iter().rev().map(logline_to_line).collect();
|
||||
let paragraph = Paragraph::new(lines)
|
||||
@@ -223,8 +230,7 @@ fn draw(frame: &mut Frame, game: &GameState, ui: &Ui) {
|
||||
frame.render_widget(paragraph, log_area);
|
||||
} else {
|
||||
// Panel closed: board fills the screen, latest message in the border.
|
||||
let mut block =
|
||||
Block::bordered().title(format!(" {} ", board.name));
|
||||
let mut block = Block::bordered().title(format!(" {} ", board.name));
|
||||
block = block.title_bottom(log_preview(game).left_aligned());
|
||||
let inner = block.inner(frame.area());
|
||||
frame.render_widget(block, frame.area());
|
||||
|
||||
Reference in New Issue
Block a user