Skip to content

Commit

Permalink
refactor(crates): move shared contents from zellij tile to zellij uti…
Browse files Browse the repository at this point in the history
…ls (#1541)

* zellij-tile: Move `data` to zellij-utils

The rationale behind this is that all components of zellij access the
data structures defined in this module, as they define some of the most
basic types in the application. However, so far zellij-tile is treated
like a separate crate from the rest of the program in that it is the
only one that doesn't have access to `zellij-utils`, which contains a
lot of other data structures used throughout zellij.

This poses issues as discussed in
#1242 and is one of the reasons
why the keybindings in the status bar default plugin can't be updated
dynamically. It is also the main reason for why the keybindings are
currently passed to the plugin as strings: The plugins only have access
to `zellij-tile`, but since this is a dependency of `zellij-utils`, it
can't import `zellij-utils` to access the keybindings.
Other weird side-effect are that in some places `server` and `client`
have to access the `zellij-tile` contents "through" `zellij-utils`, as
in `use zellij_utils::zellij_tile::prelude::*`.

By moving these central data structures to one common shared crate
(`zellij-utils`), `zellij-tile` will be enabled to import `zellij-utils`
like `screen` and `client` already do. This will, next to other things,
allow dropping a lot of `std::fmt::Fmt` impls needed to convert core
data structures into strings and as a consequence, a lot of string
parsing in the first place.

* utils: Integrate new `data` module, bump rust ver

Integrates the `data` module that was previously part of `zellij-tile`
to allow sharing the contained data structures between all components of
zellij.

This allows `zellij-tile` to use `utils` as a dependency. However, since
`tile` is build against the wasm target, it cannot include all of
`zellij-utils`, since a lot of dependencies there cannot compile with
`wasm` as target (Examples include: termwiz, log4rs, async-std). Thus we
make all the dependencies that cannot compile against `wasm` optional
and introduce a new feature `full` that will compile the crate with all
dependencies. Along with this, modify `lib.rs` to include most of the
data structures only when compiling against the `full` feature.

This makes the compiles of `zellij-tile` lighter, as it doesn't include
all of `utils`. As a side effect, due to the dependency notation for the
optional dependencies (See
https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies),
we bump the rust toolchain version to 1.60.0.

* tile: Import `data` from zellij-utils

Add `zellij-utils` as a dependency to `zellij-tile` and allow us access
to the `data` module defined there. Update the re-export in the
`prelude` such that from all of the plugins points of view *absolutely
nothing changes*.

* utils: Fix `data` module dependency

Since the `data` module has been migrated from `zellij-tile` to
`zellij-utils`, we import it from `zellij-utils` directly now.
Also unify the imports for the `data` module members: We import all of
the through `data::` now, not through a mixture of `data::` and
`prelude::`.

* client: Fix `data` module dependency

Since the `data` module has been migrated from `zellij-tile` to
`zellij-utils`, we import it from `zellij-utils` directly now.
Also unify the imports for the `data` module members: We import all of
the through `data::` now, not through a mixture of `data::` and
`prelude::`.
Add the "full" feature flag to the `zellij-utils` dependency so it
includes all the components we need.

* server: Fix `data` module dependency

Since the `data` module has been migrated from `zellij-tile` to
`zellij-utils`, we import it from `zellij-utils` directly now.
Also unify the imports for the `data` module members: We import all of
the through `data::` now, not through a mixture of `data::` and
`prelude::`.
Add the "full" feature flag to the `zellij-utils` dependency so it
includes all the components we need.

* tests: Fix `data` module dependency

Since the `data` module has been migrated from `zellij-tile` to
`zellij-utils`, we import it from `zellij-utils` directly now.

* utils: Remove "full" feature

in favor of conditional compilation using `target_family`. Replace the
rust 1.60 method of specifying optional dependencies based on features
and optionally include the dependencies only when not building for wasm
instead. (I.e. `cfg(not(target_family = "wasm"))`)

* cargo: Update module dependencies

since `client`, `server` and `tile` now all depend on `utils` only.
  • Loading branch information
har7an authored Jul 6, 2022
1 parent 5a40f42 commit c26a6bc
Show file tree
Hide file tree
Showing 48 changed files with 108 additions and 132 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/tests/e2e/remote_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};

use zellij_server::panes::{LinkHandler, TerminalPane};
use zellij_utils::data::{Palette, Style};
use zellij_utils::pane_size::{Dimension, PaneGeom, Size};
use zellij_utils::vte;
use zellij_utils::zellij_tile::data::Palette;
use zellij_utils::zellij_tile::prelude::Style;

use ssh2::Session;
use std::io::prelude::*;
Expand Down
1 change: 0 additions & 1 deletion zellij-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ license = "MIT"
[dependencies]
mio = { version = "0.7.11", features = ['os-ext'] }
zellij-utils = { path = "../zellij-utils/", version = "0.31.0" }
zellij-tile = { path = "../zellij-tile/", version = "0.31.0" }
log = "0.4.17"

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions zellij-client/src/fake_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//! Multiple actions at the same time can be dispatched.
use log::debug;
use std::{fs, path::PathBuf, thread};
use zellij_tile::prelude::{ClientId, Style};
use zellij_utils::errors::ContextType;

use crate::{
command_is_executing::CommandIsExecuting, input_handler::input_actions,
Expand All @@ -14,6 +12,8 @@ use crate::{
use zellij_utils::{
channels::{self, ChannelWithContext, SenderWithContext},
cli::CliArgs,
data::{ClientId, Style},
errors::ContextType,
input::{actions::Action, config::Config, layout::LayoutFromYaml, options::Options},
ipc::{ClientAttributes, ClientToServerMsg, ServerToClientMsg},
};
Expand Down
22 changes: 10 additions & 12 deletions zellij-client/src/input_handler.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
//! Main input logic.
use zellij_utils::{
input::{
mouse::{MouseButton, MouseEvent},
options::Options,
},
termwiz::input::InputEvent,
zellij_tile,
};

use crate::{
os_input_output::ClientOsApi,
stdin_ansi_parser::{AnsiStdinInstructionOrKeys, StdinAnsiParser},
ClientId, ClientInstruction, CommandIsExecuting, InputInstruction,
};
use zellij_utils::{
channels::{Receiver, SenderWithContext, OPENCALLS},
data::{InputMode, Key},
errors::{ContextType, ErrorContext},
input::{actions::Action, cast_termwiz_key, config::Config, keybinds::Keybinds},
input::{
actions::Action,
cast_termwiz_key,
config::Config,
keybinds::Keybinds,
mouse::{MouseButton, MouseEvent},
options::Options,
},
ipc::{ClientToServerMsg, ExitReason},
termwiz::input::InputEvent,
};

use zellij_tile::data::{InputMode, Key};

/// Handles the dispatching of [`Action`]s according to the current
/// [`InputMode`], and keep tracks of the current [`InputMode`].
struct InputHandler {
Expand Down
3 changes: 1 addition & 2 deletions zellij-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ use std::io::{self, Write};
use std::path::Path;
use std::process::Command;
use std::thread;
use zellij_tile::prelude::{ClientId, Style};

use crate::{
command_is_executing::CommandIsExecuting, input_handler::input_loop,
os_input_output::ClientOsApi, stdin_handler::stdin_loop,
};
use zellij_tile::data::InputMode;
use zellij_utils::{
channels::{self, ChannelWithContext, SenderWithContext},
consts::ZELLIJ_IPC_PIPE,
data::{ClientId, InputMode, Style},
envs,
errors::{ClientContext, ContextType, ErrorInstruction},
input::{actions::Action, config::Config, options::Options},
Expand Down
4 changes: 2 additions & 2 deletions zellij-client/src/os_input_output.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use zellij_utils::pane_size::Size;
use zellij_utils::{interprocess, libc, nix, signal_hook, zellij_tile};
use zellij_utils::{interprocess, libc, nix, signal_hook};

use interprocess::local_socket::LocalSocketStream;
use mio::{unix::SourceFd, Events, Interest, Poll, Token};
Expand All @@ -11,8 +11,8 @@ use std::os::unix::io::RawFd;
use std::path::Path;
use std::sync::{Arc, Mutex};
use std::{io, thread, time};
use zellij_tile::data::Palette;
use zellij_utils::{
data::Palette,
errors::ErrorContext,
ipc::{ClientToServerMsg, IpcReceiverWithContext, IpcSenderWithContext, ServerToClientMsg},
shared::default_palette,
Expand Down
12 changes: 7 additions & 5 deletions zellij-client/src/stdin_ansi_parser.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use zellij_utils::pane_size::SizeInPixels;

use zellij_utils::{ipc::PixelDimensions, lazy_static::lazy_static, regex::Regex};

use zellij_tile::data::{CharOrArrow, Key};
use zellij_utils::{
data::{CharOrArrow, Key},
ipc::PixelDimensions,
lazy_static::lazy_static,
pane_size::SizeInPixels,
regex::Regex,
};

pub struct StdinAnsiParser {
expected_ansi_instructions: usize,
Expand Down
5 changes: 1 addition & 4 deletions zellij-client/src/unit/input_handler_tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::input_loop;
use zellij_utils::data::{InputMode, Palette};
use zellij_utils::input::actions::{Action, Direction};
use zellij_utils::input::config::Config;
use zellij_utils::input::options::Options;
use zellij_utils::nix;
use zellij_utils::pane_size::{Size, SizeInPixels};
use zellij_utils::termwiz::input::{InputEvent, KeyCode, KeyEvent, Modifiers};
use zellij_utils::zellij_tile::data::Palette;

use crate::InputInstruction;
use crate::{
Expand All @@ -15,12 +15,9 @@ use crate::{

use std::path::Path;

use zellij_utils::zellij_tile;

use std::io;
use std::os::unix::io::RawFd;
use std::sync::{Arc, Mutex};
use zellij_tile::data::InputMode;
use zellij_utils::{
errors::ErrorContext,
ipc::{ClientToServerMsg, PixelDimensions, ServerToClientMsg},
Expand Down
1 change: 0 additions & 1 deletion zellij-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ wasmer = "1.0.0"
wasmer-wasi = "1.0.0"
cassowary = "0.3.0"
zellij-utils = { path = "../zellij-utils/", version = "0.31.0" }
zellij-tile = { path = "../zellij-tile/", version = "0.31.0" }
log = "0.4.17"
typetag = "0.1.7"
chrono = "0.4.19"
Expand Down
4 changes: 1 addition & 3 deletions zellij-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ use std::{
sync::{Arc, Mutex, RwLock},
thread,
};
use zellij_tile::prelude::Style;
use zellij_utils::envs;
use zellij_utils::nix::sys::stat::{umask, Mode};
use zellij_utils::pane_size::Size;
use zellij_utils::zellij_tile;

use wasmer::Store;
use zellij_tile::data::{Event, PluginCapabilities};

use crate::{
os_input_output::ServerOsApi,
Expand All @@ -41,6 +38,7 @@ use zellij_utils::{
channels::{self, ChannelWithContext, SenderWithContext},
cli::CliArgs,
consts::{DEFAULT_SCROLL_BUFFER_SIZE, SCROLL_BUFFER_SIZE},
data::{Event, PluginCapabilities, Style},
errors::{ContextType, ErrorInstruction, ServerContext},
input::{
command::{RunCommand, TerminalAction},
Expand Down
4 changes: 2 additions & 2 deletions zellij-server/src/os_input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::PathBuf;
use std::process::{Child, Command};
use std::sync::{Arc, Mutex};

use zellij_utils::{async_std, interprocess, libc, nix, signal_hook, zellij_tile};
use zellij_utils::{async_std, interprocess, libc, nix, signal_hook};

use async_std::fs::File as AsyncFile;
use async_std::os::unix::io::FromRawFd;
Expand All @@ -25,8 +25,8 @@ use nix::sys::termios;

use nix::unistd;
use signal_hook::consts::*;
use zellij_tile::data::Palette;
use zellij_utils::{
data::Palette,
input::command::{RunCommand, TerminalAction},
ipc::{ClientToServerMsg, IpcReceiverWithContext, IpcSenderWithContext, ServerToClientMsg},
shared::default_palette,
Expand Down
9 changes: 5 additions & 4 deletions zellij-server/src/panes/floating_panes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use zellij_tile::prelude::Style;
mod floating_pane_grid;
use zellij_utils::{position::Position, zellij_tile};
use zellij_utils::position::Position;

use crate::tab::Pane;
use floating_pane_grid::FloatingPaneGrid;
Expand All @@ -16,8 +15,10 @@ use std::cell::RefCell;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::rc::Rc;
use std::time::Instant;
use zellij_tile::data::ModeInfo;
use zellij_utils::pane_size::{Offset, PaneGeom, Size, Viewport};
use zellij_utils::{
data::{ModeInfo, Style},
pane_size::{Offset, PaneGeom, Size, Viewport},
};

macro_rules! resize_pty {
($pane:expr, $os_input:expr) => {
Expand Down
4 changes: 2 additions & 2 deletions zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ use std::{

use zellij_utils::{
consts::{DEFAULT_SCROLL_BUFFER_SIZE, SCROLL_BUFFER_SIZE},
data::{Palette, PaletteColor},
pane_size::SizeInPixels,
position::Position,
vte, zellij_tile,
vte,
};

const TABSTOP_WIDTH: usize = 8; // TODO: is this always right?
pub const MAX_TITLE_STACK_SIZE: usize = 1000;

use vte::{Params, Perform};
use zellij_tile::data::{Palette, PaletteColor};
use zellij_utils::{consts::VERSION, shared::version_number};

use crate::output::{CharacterChunk, OutputBuffer};
Expand Down
2 changes: 1 addition & 1 deletion zellij-server/src/panes/plugin_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::ClientId;
use zellij_utils::pane_size::Offset;
use zellij_utils::position::Position;
use zellij_utils::shared::ansi_len;
use zellij_utils::zellij_tile::prelude::{Event, InputMode, Mouse, PaletteColor};
use zellij_utils::{
channels::SenderWithContext,
data::{Event, InputMode, Mouse, PaletteColor},
pane_size::{Dimension, PaneGeom},
shared::make_terminal_title,
};
Expand Down
3 changes: 1 addition & 2 deletions zellij-server/src/panes/terminal_character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use std::fmt::{self, Debug, Display, Formatter};
use std::ops::{Index, IndexMut};
use unicode_width::UnicodeWidthChar;

use zellij_utils::vte::ParamsIter;
use zellij_utils::{data::PaletteColor, vte::ParamsIter};

use crate::panes::alacritty_functions::parse_sgr_color;
use zellij_tile::data::PaletteColor;

pub const EMPTY_TERMINAL_CHARACTER: TerminalCharacter = TerminalCharacter {
character: ' ',
Expand Down
3 changes: 1 addition & 2 deletions zellij-server/src/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ use std::fmt::Debug;
use std::os::unix::io::RawFd;
use std::rc::Rc;
use std::time::{self, Instant};
use zellij_tile::prelude::Style;
use zellij_utils::pane_size::Offset;
use zellij_utils::{
data::{InputMode, Palette, PaletteColor, Style},
pane_size::SizeInPixels,
pane_size::{Dimension, PaneGeom},
position::Position,
shared::make_terminal_title,
vte,
zellij_tile::data::{InputMode, Palette, PaletteColor},
};

pub const SELECTION_SCROLL_INTERVAL_MS: u64 = 10;
Expand Down
5 changes: 1 addition & 4 deletions zellij-server/src/panes/tiled_panes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
mod pane_resizer;
mod tiled_pane_grid;

use zellij_tile::prelude::Style;
use zellij_utils::zellij_tile;

use crate::tab::{Pane, MIN_TERMINAL_HEIGHT, MIN_TERMINAL_WIDTH};
use tiled_pane_grid::{split, TiledPaneGrid};

Expand All @@ -15,8 +12,8 @@ use std::cell::RefCell;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::rc::Rc;
use std::time::Instant;
use zellij_tile::data::ModeInfo;
use zellij_utils::{
data::{ModeInfo, Style},
input::layout::Direction,
pane_size::{Offset, PaneGeom, Size, SizeInPixels, Viewport},
};
Expand Down
2 changes: 1 addition & 1 deletion zellij-server/src/panes/unit/grid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::panes::link_handler::LinkHandler;
use ::insta::assert_snapshot;
use std::cell::RefCell;
use std::rc::Rc;
use zellij_utils::{pane_size::SizeInPixels, position::Position, vte, zellij_tile::data::Palette};
use zellij_utils::{data::Palette, pane_size::SizeInPixels, position::Position, vte};

fn read_fixture(fixture_name: &str) -> Vec<u8> {
let mut path_to_file = std::path::PathBuf::new();
Expand Down
7 changes: 4 additions & 3 deletions zellij-server/src/panes/unit/terminal_pane_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use crate::tab::Pane;
use ::insta::assert_snapshot;
use std::cell::RefCell;
use std::rc::Rc;
use zellij_tile::data::Palette;
use zellij_tile::prelude::Style;
use zellij_utils::pane_size::PaneGeom;
use zellij_utils::{
data::{Palette, Style},
pane_size::PaneGeom,
};

use std::fmt::Write;

Expand Down
3 changes: 1 addition & 2 deletions zellij-server/src/route.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::sync::{Arc, RwLock};

use zellij_utils::zellij_tile::data::Event;

use crate::{
os_input_output::ServerOsApi,
pty::{ClientOrTabIndex, PtyInstruction},
Expand All @@ -11,6 +9,7 @@ use crate::{
};
use zellij_utils::{
channels::SenderWithContext,
data::Event,
input::{
actions::{Action, Direction, ResizeDirection},
command::TerminalAction,
Expand Down
Loading

0 comments on commit c26a6bc

Please sign in to comment.