Compare commits

..

No commits in common. "47cd7bcd2c221e9c534614def3e92ad27dc79f21" and "f1882310c92cab7af2a2a69051e01c873a910ffa" have entirely different histories.

17 changed files with 133 additions and 127 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
/target
*~

7
Cargo.lock generated
View File

@ -186,7 +186,6 @@ name = "muxde"
version = "0.1.0"
dependencies = [
"crossterm",
"once_cell",
"serde",
"tokio",
"toml",
@ -202,12 +201,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "parking_lot"
version = "0.12.3"

View File

@ -5,7 +5,6 @@ edition = "2021"
[dependencies]
crossterm = "0.28.1"
once_cell = "1.19.0"
serde = { version = "1.0.210", features = ["derive", "serde_derive"] }
tokio = { version = "1.40.0", features = ["full"] }
toml = "0.8.19"

View File

@ -1,13 +1,12 @@
[colortheme]
background = [0x26, 0x26, 0x28]
command-bar = [0x20, 0x28, 0x20]
cmdbar-prompt = [0x60, 0x60, 0x60]
cmdbar-cmdexist = [0x40, 0xff, 0x40]
cmdbar-cmdunexist = [0xff, 0x40, 0x40]
editor-title = [0x30, 0x30, 0x42]
[command]
new-window = "n"
quit = "q"
abcdefg = "abcd"
fdsafdsa = "fdsa"

View File

@ -1,10 +1,5 @@
use once_cell::sync::OnceCell;
use crate::window::Window;
use crate::{window::Window, window::editor::Editor};
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))
pub fn new_window() -> Box<dyn Window> {
todo!()
}

7
src/api.rs~ Normal file
View File

@ -0,0 +1,7 @@
use std::collection::HashMap;
use crate::window::Window;
pub fn new_window() -> Box<dyn Window> {
todo!()
}

View File

@ -79,19 +79,18 @@ impl Application {
fn command_process(&mut self) -> bool {
if let toml::Value::Table(map) = &self.config.get("command").unwrap() {
let (tx, rx) = mpsc::channel();
let res = if self.cmdprocessor.process(map, self.size, tx) {
if self.cmdprocessor.process(map, tx) {
while let Ok(pipeobj) = rx.recv() {
match pipeobj {
PipeObj::NewWindow(win) => {
self.windows.insert(win.get_id(), win);
}
}
}
true
} else {
false
};
while let Ok(pipeobj) = rx.recv() {
match pipeobj {
PipeObj::NewWindow(win) => {
self.windows.insert(win.get_id(), win);
}
}
}
res
} else {
false
}
@ -139,13 +138,6 @@ impl Application {
style::Print(" ".repeat((self.size.0 - x) as usize)),
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()?;
Ok(())
}

View File

@ -7,7 +7,6 @@ pub struct ColorTheme {
pub cmdbar_prompt: Color,
pub cmdbar_cmdexist: Color,
pub cmdbar_cmdunexist: Color,
pub editor_title: Color,
}
impl From<&Table> for ColorTheme {
@ -28,14 +27,12 @@ impl From<&Table> for ColorTheme {
let cmdbar_prompt = f("cmdbar-prompt");
let cmdbar_cmdexist = f("cmdbar-cmdexist");
let cmdbar_cmdunexist = f("cmdbar-cmdunexist");
let editor_title = f("editor-title");
Self {
background,
command_bar,
cmdbar_prompt,
cmdbar_cmdexist,
cmdbar_cmdunexist,
editor_title,
}
}
}

View File

@ -45,12 +45,7 @@ impl CommandProcessor {
self.command_mode
}
pub fn process(
&mut self,
map: &Config,
screen_size: (u16, u16),
sender: Sender<PipeObj>,
) -> bool {
pub fn process(&mut self, map: &Config, sender: Sender<PipeObj>) -> bool {
if let Some((name, cmd, full)) = iterate_config(map, &self.command) {
self.cmdbar_prompt = format!("{}", name);
if !full {
@ -73,7 +68,7 @@ impl CommandProcessor {
match name.as_str() {
"quit" => return true,
"new-window" => {
let win = api::new_window(screen_size);
let win = api::new_window();
sender.send(PipeObj::NewWindow(win)).unwrap();
}
"abcd" => (),

3
src/innerpipe.rs~ Normal file
View File

@ -0,0 +1,3 @@
pub enum PipeObj {
NewWindow(Box<dyn Window>),
}

View File

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

10
src/window.rs Normal file
View File

@ -0,0 +1,10 @@
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<()>;
}

View File

@ -1,62 +0,0 @@
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(())
}
}

View File

@ -1,19 +0,0 @@
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<()>;
}

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;