Compare commits
2 Commits
f1882310c9
...
47cd7bcd2c
Author | SHA1 | Date |
---|---|---|
pointer-to-bios | 47cd7bcd2c | |
pointer-to-bios | 12a489039e |
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
*~
|
||||||
|
|
|
@ -186,6 +186,7 @@ name = "muxde"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossterm",
|
"crossterm",
|
||||||
|
"once_cell",
|
||||||
"serde",
|
"serde",
|
||||||
"tokio",
|
"tokio",
|
||||||
"toml",
|
"toml",
|
||||||
|
@ -201,6 +202,12 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.19.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.12.3"
|
version = "0.12.3"
|
||||||
|
|
|
@ -5,6 +5,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crossterm = "0.28.1"
|
crossterm = "0.28.1"
|
||||||
|
once_cell = "1.19.0"
|
||||||
serde = { version = "1.0.210", features = ["derive", "serde_derive"] }
|
serde = { version = "1.0.210", features = ["derive", "serde_derive"] }
|
||||||
tokio = { version = "1.40.0", features = ["full"] }
|
tokio = { version = "1.40.0", features = ["full"] }
|
||||||
toml = "0.8.19"
|
toml = "0.8.19"
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
[colortheme]
|
[colortheme]
|
||||||
background = [0x26, 0x26, 0x28]
|
background = [0x26, 0x26, 0x28]
|
||||||
|
|
||||||
command-bar = [0x20, 0x28, 0x20]
|
command-bar = [0x20, 0x28, 0x20]
|
||||||
cmdbar-prompt = [0x60, 0x60, 0x60]
|
cmdbar-prompt = [0x60, 0x60, 0x60]
|
||||||
cmdbar-cmdexist = [0x40, 0xff, 0x40]
|
cmdbar-cmdexist = [0x40, 0xff, 0x40]
|
||||||
cmdbar-cmdunexist = [0xff, 0x40, 0x40]
|
cmdbar-cmdunexist = [0xff, 0x40, 0x40]
|
||||||
|
|
||||||
|
editor-title = [0x30, 0x30, 0x42]
|
||||||
|
|
||||||
[command]
|
[command]
|
||||||
new-window = "n"
|
new-window = "n"
|
||||||
quit = "q"
|
quit = "q"
|
||||||
abcdefg = "abcd"
|
|
||||||
fdsafdsa = "fdsa"
|
|
||||||
|
|
11
src/api.rs
11
src/api.rs
|
@ -1,5 +1,10 @@
|
||||||
use crate::window::Window;
|
use once_cell::sync::OnceCell;
|
||||||
|
|
||||||
pub fn new_window() -> Box<dyn Window> {
|
use crate::{window::Window, window::editor::Editor};
|
||||||
todo!()
|
|
||||||
|
pub fn new_window(screen_size: (u16, u16)) -> Box<dyn Window> {
|
||||||
|
static mut ID_COUNT: OnceCell<usize> = OnceCell::new();
|
||||||
|
let tmp = unsafe { *ID_COUNT.get_or_init(|| 0) };
|
||||||
|
let _ = unsafe { ID_COUNT.set(tmp + 1) };
|
||||||
|
Box::new(Editor::new(tmp, screen_size))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
use std::collection::HashMap;
|
|
||||||
|
|
||||||
use crate::window::Window;
|
|
||||||
|
|
||||||
pub fn new_window() -> Box<dyn Window> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
|
@ -79,18 +79,19 @@ impl Application {
|
||||||
fn command_process(&mut self) -> bool {
|
fn command_process(&mut self) -> bool {
|
||||||
if let toml::Value::Table(map) = &self.config.get("command").unwrap() {
|
if let toml::Value::Table(map) = &self.config.get("command").unwrap() {
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
if self.cmdprocessor.process(map, tx) {
|
let res = if self.cmdprocessor.process(map, self.size, tx) {
|
||||||
while let Ok(pipeobj) = rx.recv() {
|
|
||||||
match pipeobj {
|
|
||||||
PipeObj::NewWindow(win) => {
|
|
||||||
self.windows.insert(win.get_id(), win);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
};
|
||||||
|
while let Ok(pipeobj) = rx.recv() {
|
||||||
|
match pipeobj {
|
||||||
|
PipeObj::NewWindow(win) => {
|
||||||
|
self.windows.insert(win.get_id(), win);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
res
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -138,6 +139,13 @@ impl Application {
|
||||||
style::Print(" ".repeat((self.size.0 - x) as usize)),
|
style::Print(" ".repeat((self.size.0 - x) as usize)),
|
||||||
cursor::RestorePosition,
|
cursor::RestorePosition,
|
||||||
)?;
|
)?;
|
||||||
|
for (_, win) in self.windows.iter_mut() {
|
||||||
|
win.render(
|
||||||
|
&mut self.stdout,
|
||||||
|
(self.size.0, self.size.1 - 1),
|
||||||
|
&self.colortheme,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
self.stdout.flush()?;
|
self.stdout.flush()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ pub struct ColorTheme {
|
||||||
pub cmdbar_prompt: Color,
|
pub cmdbar_prompt: Color,
|
||||||
pub cmdbar_cmdexist: Color,
|
pub cmdbar_cmdexist: Color,
|
||||||
pub cmdbar_cmdunexist: Color,
|
pub cmdbar_cmdunexist: Color,
|
||||||
|
pub editor_title: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Table> for ColorTheme {
|
impl From<&Table> for ColorTheme {
|
||||||
|
@ -27,12 +28,14 @@ impl From<&Table> for ColorTheme {
|
||||||
let cmdbar_prompt = f("cmdbar-prompt");
|
let cmdbar_prompt = f("cmdbar-prompt");
|
||||||
let cmdbar_cmdexist = f("cmdbar-cmdexist");
|
let cmdbar_cmdexist = f("cmdbar-cmdexist");
|
||||||
let cmdbar_cmdunexist = f("cmdbar-cmdunexist");
|
let cmdbar_cmdunexist = f("cmdbar-cmdunexist");
|
||||||
|
let editor_title = f("editor-title");
|
||||||
Self {
|
Self {
|
||||||
background,
|
background,
|
||||||
command_bar,
|
command_bar,
|
||||||
cmdbar_prompt,
|
cmdbar_prompt,
|
||||||
cmdbar_cmdexist,
|
cmdbar_cmdexist,
|
||||||
cmdbar_cmdunexist,
|
cmdbar_cmdunexist,
|
||||||
|
editor_title,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,12 @@ impl CommandProcessor {
|
||||||
self.command_mode
|
self.command_mode
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process(&mut self, map: &Config, sender: Sender<PipeObj>) -> bool {
|
pub fn process(
|
||||||
|
&mut self,
|
||||||
|
map: &Config,
|
||||||
|
screen_size: (u16, u16),
|
||||||
|
sender: Sender<PipeObj>,
|
||||||
|
) -> bool {
|
||||||
if let Some((name, cmd, full)) = iterate_config(map, &self.command) {
|
if let Some((name, cmd, full)) = iterate_config(map, &self.command) {
|
||||||
self.cmdbar_prompt = format!("{}", name);
|
self.cmdbar_prompt = format!("{}", name);
|
||||||
if !full {
|
if !full {
|
||||||
|
@ -68,7 +73,7 @@ impl CommandProcessor {
|
||||||
match name.as_str() {
|
match name.as_str() {
|
||||||
"quit" => return true,
|
"quit" => return true,
|
||||||
"new-window" => {
|
"new-window" => {
|
||||||
let win = api::new_window();
|
let win = api::new_window(screen_size);
|
||||||
sender.send(PipeObj::NewWindow(win)).unwrap();
|
sender.send(PipeObj::NewWindow(win)).unwrap();
|
||||||
}
|
}
|
||||||
"abcd" => (),
|
"abcd" => (),
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
pub enum PipeObj {
|
|
||||||
NewWindow(Box<dyn Window>),
|
|
||||||
}
|
|
|
@ -4,7 +4,6 @@ pub mod colortheme;
|
||||||
pub mod command;
|
pub mod command;
|
||||||
pub mod innerpipe;
|
pub mod innerpipe;
|
||||||
pub mod window;
|
pub mod window;
|
||||||
pub mod windows;
|
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
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, stdout: &mut Stdout, screen_size: (u16, u16)) -> io::Result<()>;
|
|
||||||
}
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
use std::io::{self, Stdout};
|
||||||
|
|
||||||
|
use crossterm::{cursor, queue, style};
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
|
use crate::{colortheme::ColorTheme, window::Window};
|
||||||
|
|
||||||
|
pub struct Editor {
|
||||||
|
id: usize,
|
||||||
|
name: String,
|
||||||
|
pos: (u16, u16),
|
||||||
|
size: (u16, u16),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Editor {
|
||||||
|
pub fn new(id: usize, screen_size: (u16, u16)) -> Self {
|
||||||
|
Editor {
|
||||||
|
id,
|
||||||
|
name: String::new(),
|
||||||
|
pos: (0, 0),
|
||||||
|
size: screen_size,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
self.id
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(
|
||||||
|
&mut self,
|
||||||
|
stdout: &mut Stdout,
|
||||||
|
screen_size: (u16, u16),
|
||||||
|
colortheme: &ColorTheme,
|
||||||
|
) -> io::Result<()> {
|
||||||
|
let x = UnicodeWidthStr::width(self.name.as_str()) as u16;
|
||||||
|
queue!(
|
||||||
|
stdout,
|
||||||
|
cursor::SavePosition,
|
||||||
|
style::SetBackgroundColor(colortheme.editor_title),
|
||||||
|
cursor::MoveTo(self.pos.0, self.pos.1),
|
||||||
|
style::Print(self.name.clone()),
|
||||||
|
style::Print(" ".repeat((screen_size.0 - x) as usize) + "\n\r"),
|
||||||
|
style::SetBackgroundColor(colortheme.background),
|
||||||
|
cursor::RestorePosition,
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
pub mod editor;
|
||||||
|
|
||||||
|
use std::io::{self, Stdout};
|
||||||
|
|
||||||
|
use crate::colortheme::ColorTheme;
|
||||||
|
|
||||||
|
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,
|
||||||
|
stdout: &mut Stdout,
|
||||||
|
screen_size: (u16, u16),
|
||||||
|
colortheme: &ColorTheme,
|
||||||
|
) -> io::Result<()>;
|
||||||
|
}
|
|
@ -1,48 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
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 +0,0 @@
|
||||||
pub mod editor;
|
|
Loading…
Reference in New Issue