1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! Module for things related to displaying a Klondike game in the terminal.

use std::{fmt, io};
use termion::terminal_size;

pub mod blank;
pub mod card;
pub mod frame;
pub mod game;
pub mod geometry;
pub mod help;
pub mod selector;
pub mod stack;
pub mod win;

#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum DisplayState {
    Playing,
    HelpMessageOpen,
    Quitting,
    WinMessageOpen,
}

pub trait Widget: fmt::Display {
    fn bounds(&self) -> geometry::Rect<u16>;
}

pub fn terminal_bounds() -> io::Result<geometry::Size2D<u16>> {
    let (cols, rows) = terminal_size()?;
    Ok(geometry::size2(cols, rows))
}