use std::fmt;
use std::mem::zeroed;
use winapi::um::wincon::CONSOLE_SCREEN_BUFFER_INFO;
use super::{Coord, Size, WindowPositions};
#[derive(Clone)]
pub struct ScreenBufferInfo(pub CONSOLE_SCREEN_BUFFER_INFO);
impl fmt::Debug for ScreenBufferInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ScreenBufferInfo")
.field("dwSize", &self.buffer_size())
.field("dwCursorPosition", &self.cursor_pos())
.field("wAttributes", &self.attributes()) .field("srWindow", &self.terminal_window())
.field(
"dwMaximumWindowSize",
&Size::from(self.0.dwMaximumWindowSize),
)
.finish()
}
}
impl ScreenBufferInfo {
pub fn new() -> ScreenBufferInfo {
ScreenBufferInfo(unsafe { zeroed() })
}
pub fn buffer_size(&self) -> Size {
Size::from(self.0.dwSize)
}
pub fn terminal_size(&self) -> Size {
Size::new(
self.0.srWindow.Right - self.0.srWindow.Left,
self.0.srWindow.Bottom - self.0.srWindow.Top,
)
}
pub fn terminal_window(&self) -> WindowPositions {
WindowPositions::from(self.0)
}
pub fn attributes(&self) -> u16 {
self.0.wAttributes
}
pub fn cursor_pos(&self) -> Coord {
Coord::from(self.0.dwCursorPosition)
}
}
impl From<CONSOLE_SCREEN_BUFFER_INFO> for ScreenBufferInfo {
fn from(csbi: CONSOLE_SCREEN_BUFFER_INFO) -> Self {
ScreenBufferInfo(csbi)
}
}