aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-05-04 01:13:16 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-05-04 20:48:17 +0530
commitd33106431dd22759b133a838337427a388f6008f (patch)
treea270cd5ea1d0cfb668706977057c5501e6b4043b /src/common
parentIntroduce IpcReceiverWIthContext and move ipc stuff to common/ipc.rs (diff)
downloadsl0ppij-d33106431dd22759b133a838337427a388f6008f.tar.gz
sl0ppij-d33106431dd22759b133a838337427a388f6008f.tar.xz
sl0ppij-d33106431dd22759b133a838337427a388f6008f.zip
Fix after rebase
Diffstat (limited to 'src/common')
-rw-r--r--src/common/input/handler.rs7
-rw-r--r--src/common/os_input_output.rs66
-rw-r--r--src/common/pty_bus.rs7
-rw-r--r--src/common/screen.rs5
-rw-r--r--src/common/utils/consts.rs11
-rw-r--r--src/common/wasm_vm.rs11
6 files changed, 77 insertions, 30 deletions
diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs
index 7a4a4e52..75f9f8b1 100644
--- a/src/common/input/handler.rs
+++ b/src/common/input/handler.rs
@@ -11,7 +11,7 @@ use crate::server::ServerInstruction;
use crate::CommandIsExecuting;
use termion::input::{TermRead, TermReadEventsAndRaw};
-use zellij_tile::data::{InputMode, Key, ModeInfo};
+use zellij_tile::data::{InputMode, Key, ModeInfo, Palette};
/// Handles the dispatching of [`Action`]s according to the current
/// [`InputMode`], and keep tracks of the current [`InputMode`].
@@ -48,7 +48,6 @@ impl InputHandler {
fn handle_input(&mut self) {
let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow());
err_ctx.add_call(ContextType::StdinHandler);
- let keybinds = self.config.keybinds.clone();
let alt_left_bracket = vec![27, 91];
loop {
if self.should_exit {
@@ -60,14 +59,14 @@ impl InputHandler {
Ok((event, raw_bytes)) => match event {
termion::event::Event::Key(key) => {
let key = cast_termion_key(key);
- self.handle_key(&key, raw_bytes, &keybinds);
+ self.handle_key(&key, raw_bytes);
}
termion::event::Event::Unsupported(unsupported_key) => {
// we have to do this because of a bug in termion
// this should be a key event and not an unsupported event
if unsupported_key == alt_left_bracket {
let key = Key::Alt('[');
- self.handle_key(&key, raw_bytes, &keybinds);
+ self.handle_key(&key, raw_bytes);
}
}
termion::event::Event::Mouse(_) => {
diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs
index a339b08d..7bf39757 100644
--- a/src/common/os_input_output.rs
+++ b/src/common/os_input_output.rs
@@ -1,3 +1,12 @@
+use crate::client::ClientInstruction;
+use crate::common::{
+ ipc::{IpcReceiverWithContext, IpcSenderWithContext},
+ utils::consts::ZELLIJ_IPC_PIPE,
+};
+use crate::errors::ErrorContext;
+use crate::panes::PositionAndSize;
+use crate::server::ServerInstruction;
+use crate::utils::shared::{default_palette, detect_theme, hex_to_rgb};
use interprocess::local_socket::LocalSocketStream;
use nix::fcntl::{fcntl, FcntlArg, OFlag};
use nix::pty::{forkpty, Winsize};
@@ -13,15 +22,8 @@ use std::os::unix::io::RawFd;
use std::path::PathBuf;
use std::process::{Child, Command};
use std::sync::{Arc, Mutex};
-
-use crate::client::ClientInstruction;
-use crate::common::{
- ipc::{IpcReceiverWithContext, IpcSenderWithContext},
- utils::consts::ZELLIJ_IPC_PIPE,
-};
-use crate::errors::ErrorContext;
-use crate::panes::PositionAndSize;
-use crate::server::ServerInstruction;
+use xrdb::Colors;
+use zellij_tile::data::{Palette, PaletteSource};
fn into_raw_mode(pid: RawFd) {
let mut tio = termios::tcgetattr(pid).expect("could not get terminal attribute");
@@ -194,6 +196,7 @@ pub trait ServerOsApi: Send + Sync {
fn add_client_sender(&mut self);
/// Update the receiver socket for the client
fn update_receiver(&mut self, stream: LocalSocketStream);
+ fn load_palette(&self) -> Palette;
}
impl ServerOsApi for ServerOsInputOutput {
@@ -258,6 +261,51 @@ impl ServerOsApi for ServerOsInputOutput {
self.receive_instructions_from_client =
Some(Arc::new(Mutex::new(IpcReceiverWithContext::new(stream))));
}
+ fn load_palette(&self) -> Palette {
+ let palette = match Colors::new("xresources") {
+ Some(palette) => {
+ let fg = if let Some(foreground) = palette.fg.as_deref().map(hex_to_rgb) {
+ foreground
+ } else {
+ return default_palette();
+ };
+
+ let bg = if let Some(background) = palette.bg.as_deref().map(hex_to_rgb) {
+ background
+ } else {
+ return default_palette();
+ };
+
+ // NOTE: `16` is the same as the length of `palette.colors`.
+ let mut colors: [(u8, u8, u8); 16] = [(0, 0, 0); 16];
+ for (idx, color) in palette.colors.iter().enumerate() {
+ if let Some(c) = color {
+ colors[idx] = hex_to_rgb(c);
+ } else {
+ return default_palette();
+ }
+ }
+ let theme = detect_theme(bg);
+ Palette {
+ source: PaletteSource::Xresources,
+ theme,
+ fg,
+ bg,
+ black: colors[0],
+ red: colors[1],
+ green: colors[2],
+ yellow: colors[3],
+ blue: colors[4],
+ magenta: colors[5],
+ cyan: colors[6],
+ white: colors[7],
+ orange: colors[9],
+ }
+ }
+ None => default_palette(),
+ };
+ palette
+ }
}
impl Clone for Box<dyn ServerOsApi> {
diff --git a/src/common/pty_bus.rs b/src/common/pty_bus.rs
index 10be6d52..31696186 100644
--- a/src/common/pty_bus.rs
+++ b/src/common/pty_bus.rs
@@ -165,9 +165,9 @@ fn stream_terminal_bytes(
impl PtyBus {
pub fn new(
receive_pty_instructions: Receiver<(PtyInstruction, ErrorContext)>,
- os_input: Box<dyn ServerOsApi>,
send_screen_instructions: SenderWithContext<ScreenInstruction>,
send_plugin_instructions: SenderWithContext<PluginInstruction>,
+ os_input: Box<dyn ServerOsApi>,
debug_to_file: bool,
) -> Self {
PtyBus {
@@ -193,8 +193,7 @@ impl PtyBus {
self.id_to_child_pid.insert(pid_primary, pid_secondary);
pid_primary
}
- pub fn spawn_terminals_for_layout(&mut self, layout_path: PathBuf) {
- let layout = Layout::new(layout_path.clone());
+ pub fn spawn_terminals_for_layout(&mut self, layout: Layout) {
let total_panes = layout.total_terminal_panes();
let mut new_pane_pids = vec![];
for _ in 0..total_panes {
@@ -204,7 +203,7 @@ impl PtyBus {
}
self.send_screen_instructions
.send(ScreenInstruction::ApplyLayout(
- layout_path,
+ layout,
new_pane_pids.clone(),
))
.unwrap();
diff --git a/src/common/screen.rs b/src/common/screen.rs
index c30cf251..c5e4f9a5 100644
--- a/src/common/screen.rs
+++ b/src/common/screen.rs
@@ -2,7 +2,6 @@
use std::collections::BTreeMap;
use std::os::unix::io::RawFd;
-use std::path::PathBuf;
use std::str;
use std::sync::mpsc::Receiver;
@@ -49,7 +48,7 @@ pub enum ScreenInstruction {
SetMaxHeight(PaneId, usize),
SetInvisibleBorders(PaneId, bool),
ClosePane(PaneId),
- ApplyLayout(PathBuf, Vec<RawFd>),
+ ApplyLayout(Layout, Vec<RawFd>),
NewTab(RawFd),
SwitchTabNext,
SwitchTabPrev,
@@ -83,6 +82,8 @@ pub struct Screen {
/// The [`ClientOsApi`] this [`Screen`] uses.
os_api: Box<dyn ServerOsApi>,
mode_info: ModeInfo,
+ input_mode: InputMode,
+ colors: Palette,
}
impl Screen {
diff --git a/src/common/utils/consts.rs b/src/common/utils/consts.rs
index c21e3029..3a783914 100644
--- a/src/common/utils/consts.rs
+++ b/src/common/utils/consts.rs
@@ -9,12 +9,19 @@ pub const ZELLIJ_TMP_DIR: &str = "/tmp/zellij";
pub const ZELLIJ_TMP_LOG_DIR: &str = "/tmp/zellij/zellij-log";
pub const ZELLIJ_TMP_LOG_FILE: &str = "/tmp/zellij/zellij-log/log.txt";
+pub const ZELLIJ_CONFIG_FILE_ENV: &str = "ZELLIJ_CONFIG_FILE";
+pub const ZELLIJ_CONFIG_DIR_ENV: &str = "ZELLIJ_CONFIG_DIR";
+
+// TODO: ${PREFIX} argument in makefile
+pub const SYSTEM_DEFAULT_CONFIG_DIR: &str = "/etc/zellij";
+
lazy_static! {
static ref UID: Uid = Uid::current();
pub static ref SESSION_NAME: String = names::Generator::default().next().unwrap();
+ pub static ref ZELLIJ_PROJ_DIR: ProjectDirs =
+ ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
pub static ref ZELLIJ_IPC_PIPE: PathBuf = {
- let project_dir = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
- let mut ipc_dir = project_dir
+ let mut ipc_dir = ZELLIJ_PROJ_DIR
.runtime_dir()
.map(|p| p.to_owned())
.unwrap_or_else(|| PathBuf::from("/tmp/zellij-".to_string() + &format!("{}", *UID)));
diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs
index 5c234403..db52c2bb 100644
--- a/src/common/wasm_vm.rs
+++ b/src/common/wasm_vm.rs
@@ -27,7 +27,8 @@ pub struct PluginEnv {
pub plugin_id: u32,
// FIXME: This should be a big bundle of all of the channels
pub send_screen_instructions: SenderWithContext<ScreenInstruction>,
- pub send_pty_instructions: SenderWithContext<PtyInstruction>, // FIXME: This should be a big bundle of all of the channels
+ pub send_pty_instructions: SenderWithContext<PtyInstruction>,
+ pub send_plugin_instructions: SenderWithContext<PluginInstruction>,
pub wasi_env: WasiEnv,
pub subscriptions: Arc<Mutex<HashSet<EventType>>>,
}
@@ -70,14 +71,6 @@ fn host_unsubscribe(plugin_env: &PluginEnv) {
subscriptions.retain(|k| !old.contains(k));
}
-fn host_open_file(plugin_env: &PluginEnv) {
- let path = PathBuf::from(wasi_stdout(&plugin_env.wasi_env).lines().next().unwrap());
- plugin_env
- .send_pty_instructions
- .send(PtyInstruction::SpawnTerminal(Some(path)))
- .unwrap();
-}
-
fn host_set_selectable(plugin_env: &PluginEnv, selectable: i32) {
let selectable = selectable != 0;
plugin_env