add window
This commit is contained in:
parent
934452beda
commit
f1882310c9
|
@ -55,6 +55,7 @@ impl CommandProcessor {
|
|||
}
|
||||
if self.command.is_empty() {
|
||||
self.cmdbar_suggestion.clear();
|
||||
self.cmdbar_prompt.clear();
|
||||
} else {
|
||||
self.cmdbar_suggestion = s;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ pub mod colortheme;
|
|||
pub mod command;
|
||||
pub mod innerpipe;
|
||||
pub mod window;
|
||||
pub mod windows;
|
||||
|
||||
use std::io;
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::io;
|
||||
use std::io::{self, Stdout};
|
||||
|
||||
pub trait Window {
|
||||
fn get_pos(&self) -> (u16, u16);
|
||||
fn get_size(&self) -> (u16, u16);
|
||||
fn get_name(&self) -> &str;
|
||||
fn get_id(&self) -> usize;
|
||||
|
||||
fn render(&mut self, screen_size: (u16, u16)) -> io::Result<()>;
|
||||
fn render(&mut self, stdout: &mut Stdout, screen_size: (u16, u16)) -> io::Result<()>;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
use std::{
|
||||
hash::{DefaultHasher, Hash, Hasher},
|
||||
io::{self, Stdout},
|
||||
};
|
||||
|
||||
use crossterm::{cursor, queue};
|
||||
|
||||
use crate::window::Window;
|
||||
|
||||
pub struct Editor {
|
||||
name: String,
|
||||
pos: (u16, u16),
|
||||
size: (u16, u16),
|
||||
}
|
||||
|
||||
impl Window for Editor {
|
||||
fn get_pos(&self) -> (u16, u16) {
|
||||
self.pos
|
||||
}
|
||||
|
||||
fn get_size(&self) -> (u16, u16) {
|
||||
self.size
|
||||
}
|
||||
|
||||
fn get_name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
fn get_id(&self) -> usize {
|
||||
let mut state = DefaultHasher::new();
|
||||
self.name.hash(&mut state);
|
||||
state.finish() as usize
|
||||
}
|
||||
|
||||
fn render(&mut self, stdout: &mut Stdout, screen_size: (u16, u16)) -> io::Result<()> {
|
||||
queue!(stdout, cursor::SavePosition, cursor::RestorePosition)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Editor {
|
||||
fn hash<H>(&self, state: &mut H)
|
||||
where
|
||||
H: Hasher,
|
||||
{
|
||||
self.name.hash(state)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
use std::{
|
||||
hash::{DefaultHasher, Hash, Hasher},
|
||||
io::{self, Stdout},
|
||||
};
|
||||
|
||||
use crossterm::{cursor, queue};
|
||||
|
||||
use crate::window::Window;
|
||||
|
||||
pub struct Editor {
|
||||
name: String,
|
||||
pos: (u16, u16),
|
||||
size: (u16, u16),
|
||||
}
|
||||
|
||||
impl Window for Editor {
|
||||
fn get_pos(&self) -> (u16, u16) {
|
||||
self.pos
|
||||
}
|
||||
|
||||
fn get_size(&self) -> (u16, u16) {
|
||||
self.size
|
||||
}
|
||||
|
||||
fn get_name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
fn get_id(&self) -> usize {
|
||||
let mut state = DefaultHasher::new();
|
||||
self.name.hash(&mut state);
|
||||
state.finish() as usize
|
||||
}
|
||||
|
||||
fn render(&mut self, stdout: &mut Stdout, screen_size: (u16, u16)) -> io::Result<()> {
|
||||
queue!(stdout, cursor::SavePosition, cursor::StorePosition)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Editor {
|
||||
fn hash<H>(&self, state: &mut H)
|
||||
where
|
||||
H: Hasher,
|
||||
{
|
||||
self.name.hash(state)
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
pub mod editor;
|
Loading…
Reference in New Issue