few changes
This commit is contained in:
+27
-13
@@ -1,3 +1,4 @@
|
||||
pub mod console;
|
||||
pub mod utils;
|
||||
pub mod widgets;
|
||||
|
||||
@@ -62,8 +63,8 @@ impl Frame {
|
||||
|
||||
println!(
|
||||
"\x1b[{};{}H{}",
|
||||
props.x + (i as u16) + 1,
|
||||
props.y + 1,
|
||||
props.y + (i as u16) + 1,
|
||||
props.x + 1,
|
||||
line.chars().take(props.width as usize).collect::<String>()
|
||||
);
|
||||
}
|
||||
@@ -71,7 +72,7 @@ impl Frame {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new(width: u16, height: u16) -> Self {
|
||||
pub fn new((width, height): (u16, u16)) -> Self {
|
||||
let mut f = Self::default();
|
||||
f.area.width(width);
|
||||
f.area.height(height);
|
||||
@@ -84,20 +85,23 @@ impl Area {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn center_x(&mut self) -> Self {
|
||||
self.center_x = true;
|
||||
*self
|
||||
pub fn center_x() -> Self {
|
||||
let mut s = Self::default();
|
||||
s.center_x = true;
|
||||
s
|
||||
}
|
||||
|
||||
pub fn center_y(&mut self) -> Self {
|
||||
self.center_y = true;
|
||||
*self
|
||||
pub fn center_y() -> Self {
|
||||
let mut s = Self::default();
|
||||
s.center_y = true;
|
||||
s
|
||||
}
|
||||
|
||||
pub fn center(&mut self) -> Self {
|
||||
self.center_x = true;
|
||||
self.center_y = true;
|
||||
*self
|
||||
pub fn center() -> Self {
|
||||
let mut s = Self::default();
|
||||
s.center_x = true;
|
||||
s.center_y = true;
|
||||
s
|
||||
}
|
||||
|
||||
pub fn width(&mut self, w: u16) -> Self {
|
||||
@@ -111,6 +115,16 @@ impl Area {
|
||||
self.height_auto = false;
|
||||
*self
|
||||
}
|
||||
|
||||
pub fn x(&mut self, x: u16) -> Self {
|
||||
self.x = x;
|
||||
*self
|
||||
}
|
||||
|
||||
pub fn y(&mut self, y: u16) -> Self {
|
||||
self.y = y;
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Area {
|
||||
|
||||
+10
-9
@@ -1,15 +1,16 @@
|
||||
use osui::*;
|
||||
|
||||
fn main() -> osui::Result<()> {
|
||||
utils::init()?;
|
||||
let con = console::init()?;
|
||||
|
||||
let (width, height) = crossterm::terminal::size()?;
|
||||
loop {
|
||||
con.draw(|frame| -> Result<()> {
|
||||
frame.draw(&"testing", Area::center())?;
|
||||
frame.draw(&"\x1b[32mX\x1b[0m", Area::center_x())?;
|
||||
frame.draw(&"\x1b[31mY\x1b[0m", Area::center_y())?;
|
||||
Ok(())
|
||||
})?;
|
||||
}
|
||||
|
||||
let frame = Frame::new(width, height);
|
||||
|
||||
frame.draw(&"Hello?", Area::new())?;
|
||||
|
||||
utils::read()?;
|
||||
|
||||
utils::end()
|
||||
console::end()
|
||||
}
|
||||
|
||||
@@ -19,18 +19,6 @@ pub fn flush() -> crate::Result<()> {
|
||||
std::io::stdout().flush()
|
||||
}
|
||||
|
||||
pub fn init() -> crate::Result<()> {
|
||||
crossterm::terminal::enable_raw_mode()?;
|
||||
clear()?;
|
||||
hide_cursor()
|
||||
}
|
||||
|
||||
pub fn end() -> crate::Result<()> {
|
||||
crossterm::terminal::disable_raw_mode()?;
|
||||
clear()?;
|
||||
show_cursor()
|
||||
}
|
||||
|
||||
pub fn str_size(s: &str) -> (u16, u16) {
|
||||
let mut height = 1;
|
||||
let mut max_width = 0;
|
||||
@@ -50,25 +38,3 @@ pub fn str_size(s: &str) -> (u16, u16) {
|
||||
|
||||
(max_width, height)
|
||||
}
|
||||
|
||||
pub enum Event {
|
||||
Key(crossterm::event::KeyEvent),
|
||||
Resize(u16, u16),
|
||||
Mouse(crossterm::event::MouseEvent),
|
||||
Paste(String),
|
||||
FocusGained,
|
||||
FocusLost,
|
||||
}
|
||||
|
||||
pub fn read() -> crate::Result<Event> {
|
||||
let event = crossterm::event::read()?;
|
||||
|
||||
Ok(match event {
|
||||
crossterm::event::Event::Key(k) => Event::Key(k),
|
||||
crossterm::event::Event::Resize(w, h) => Event::Resize(w, h),
|
||||
crossterm::event::Event::FocusGained => Event::FocusGained,
|
||||
crossterm::event::Event::FocusLost => Event::FocusLost,
|
||||
crossterm::event::Event::Mouse(m) => Event::Mouse(m),
|
||||
crossterm::event::Event::Paste(p) => Event::Paste(p),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,3 +5,9 @@ impl Widget for &str {
|
||||
self.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for String {
|
||||
fn render(&self) -> String {
|
||||
self.clone()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user