add window

This commit is contained in:
pointer-to-bios 2024-09-26 04:11:39 +00:00
parent 934452beda
commit f1882310c9
7 changed files with 125 additions and 25 deletions

View File

@ -55,6 +55,7 @@ impl CommandProcessor {
}
if self.command.is_empty() {
self.cmdbar_suggestion.clear();
self.cmdbar_prompt.clear();
} else {
self.cmdbar_suggestion = s;
}

View File

@ -4,6 +4,7 @@ pub mod colortheme;
pub mod command;
pub mod innerpipe;
pub mod window;
pub mod windows;
use std::io;

View File

@ -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<()>;
}

48
src/windows/editor.rs Normal file
View File

@ -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)
}
}

48
src/windows/editor.rs~ Normal file
View File

@ -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)
}
}

1
src/windows/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod editor;