kkx/kkdisp/src/lib.rs

66 lines
1.5 KiB
Rust
Raw Normal View History

2023-01-19 23:15:50 +00:00
use crate::component::Cursed;
2023-01-20 14:51:36 +00:00
use component::{Plan, Section};
use event::Event;
2023-01-19 23:15:50 +00:00
use std::{
io::{Stdout, Write},
time::Duration,
};
2023-01-20 14:51:36 +00:00
use termion::{
clear,
input::{MouseTerminal, TermRead},
};
use termion::{
cursor,
raw::{IntoRawMode, RawTerminal},
screen::{AlternateScreen, IntoAlternateScreen},
};
2023-01-19 23:15:50 +00:00
use theme::{Color, ColorSet};
use token::Token;
2023-01-17 02:06:16 +00:00
extern crate termion;
mod component;
2023-01-17 11:26:45 +00:00
mod theme;
2023-01-17 02:06:16 +00:00
mod token;
2023-01-20 14:51:36 +00:00
mod widget;
2023-01-17 02:06:16 +00:00
pub struct Display {
// needs to hold the termion display
2023-01-20 14:51:36 +00:00
screen: MouseTerminal<RawTerminal<Stdout>>,
2023-01-17 02:06:16 +00:00
}
impl Display {
pub fn new() -> Result<Self, anyhow::Error> {
Ok(Self {
2023-01-20 14:51:36 +00:00
screen: MouseTerminal::from(
std::io::stdout().into_raw_mode()?,
),
2023-01-17 02:06:16 +00:00
})
}
2023-01-20 14:51:36 +00:00
pub fn testing_loop_show_input() -> ! {
let mut scr = MouseTerminal::from(
std::io::stdout()
.into_alternate_screen()
.unwrap()
.into_raw_mode()
.unwrap(),
);
write!(scr, "{}", clear::All).unwrap();
scr.flush().unwrap();
let inp = std::io::stdin();
let mut evs = inp.events();
loop {
let ev = evs.next().unwrap().unwrap();
write!(
scr,
"{clear}{oo}{:#?}",
ev,
oo = cursor::Goto(1, 1),
clear = clear::All
)
.unwrap();
scr.flush().unwrap();
}
}
2023-01-17 02:06:16 +00:00
}