Skip to content

Commit

Permalink
feat(sessions): session resurrection (#2801)
Browse files Browse the repository at this point in the history
* add necessary actions in server and utils

* update

* move all logic relevant to local default config directories to utils::home

* add debug statements for pane geom

* add tests; print resulting kdl

* fix dumping custom layouts from setup; start fixing algorithm for simplest layout possible

* fix: fixed persistence code and tests to support flexible layouts

* fix(tab-bar,compact-bar): tab switching with mouse sometimes not working (#2587)

* tab-bar: fix clicks sometimes not registering

Caching the click position wasn't working across multiple plugin
instances.

Also a couple of refactors:
  - move the code with the tab switching logic inside update
  - avoid rendering when calling switch_tab_to, since it will happen
    anyway afterwards

* same fix for compact-bar

* docs(changelog): plugins tab switching with mouse fix

* feat(ui): new status bar mode (#2619)

* supermode prototype

* fix integration tests

* fix tests

* style(fmt): rustfmt

* docs(changelog): status-bar supermode

* fix(rendering): occasional glitches while resizing (#2621)

* docs(changelog): resize glitches fix

* chore(version): bump development version

* Fix colored pane frames in mirrored sessions (#2625)

* server/panes/tiled: Fix colored frames

in mirrored sessions. Colored frames were previously ignored because
they were treated like floating panes when rendering tiled panes.

* CHANGELOG: Add PR #2625

* server/tab/unit: Fix unit tests for server.

* fix(sessions): use custom lists of adjectives and nouns for generating session names (#2122)

* Create custom lists of adjectives and nouns for generating session names

* move word lists to const slices

* add logic to retry name generation

* refactor

 - reuse the name generator
 - iterator instead of for loop

---------

Co-authored-by: Thomas Linford <[email protected]>

* docs(changelog): generate session names with custom words list

* feat(plugins): make plugins configurable (#2646)

* work

* make every plugin entry point configurable

* make integration tests pass

* make e2e tests pass

* add test for plugin configuration

* add test snapshot

* add plugin config parsing test

* cleanups

* style(fmt): rustfmt

* style(comment): remove commented code

* docs(changelog): configurable plugins

* fix(terminal): properly handle resizes in alternate screen (#2654)

* docs(changelog): focus glitches

* feat(plugins): utility functions to find active pane and tab (#2652)

* docs(changelog): plugin api utility functions

* feat(ui): break pane to new tab and move panes between tabs (#2664)

* prototype

* some tests

* break out floating pane

* break out plugin panes

* add keybind and fix some minor issues

* remove cli

* move pane to left/right tab

* update ui

* adjust ui

* style(fmt): rustfmt

* style(comment): remove commented code

* update snapshots

* docs(changelog): break pane to new tab

* fix(performance): plug memory leak (#2675)

* docs(changelog): plug memory leak

* feat(plugins): use protocol buffers for serializing across the wasm boundary (#2686)

* work

* almost done with command protobuffers

* done translating command data structures

* mid transferring of every command to protobuff command

* transferred plugin_command.rs, now moving on to shim.rs

* plugin command working with protobufs

* protobuffers in update

* protobuf event tests

* various TODOs and comments

* fix zellij-tile

* clean up prost deps

* remove version mismatch error

* fix panic

* some cleanups

* clean up event protobuffers

* clean up command protobuffers

* clean up various protobufs

* refactor protobufs

* update comments

* some transformation fixes

* use protobufs for workers

* style(fmt): rustfmt

* style(fmt): rustfmt

* chore(build): add protoc

* chore(build): authenticate protoc

* docs(changelog): protobuffers

* feat: add plugin permission system (#2624)

* WIP: add exaple of permission ui

* feat: add request permission ui

* feat: add caching permission in memory

* feat: add permission check

* feat: add file caching

* fix: changes request

* feat(ui): new status bar mode (#2619)

* supermode prototype

* fix integration tests

* fix tests

* style(fmt): rustfmt

* docs(changelog): status-bar supermode

* fix(rendering): occasional glitches while resizing (#2621)

* docs(changelog): resize glitches fix

* chore(version): bump development version

* Fix colored pane frames in mirrored sessions (#2625)

* server/panes/tiled: Fix colored frames

in mirrored sessions. Colored frames were previously ignored because
they were treated like floating panes when rendering tiled panes.

* CHANGELOG: Add PR #2625

* server/tab/unit: Fix unit tests for server.

* fix(sessions): use custom lists of adjectives and nouns for generating session names (#2122)

* Create custom lists of adjectives and nouns for generating session names

* move word lists to const slices

* add logic to retry name generation

* refactor

 - reuse the name generator
 - iterator instead of for loop

---------

Co-authored-by: Thomas Linford <[email protected]>

* docs(changelog): generate session names with custom words list

* feat(plugins): make plugins configurable (#2646)

* work

* make every plugin entry point configurable

* make integration tests pass

* make e2e tests pass

* add test for plugin configuration

* add test snapshot

* add plugin config parsing test

* cleanups

* style(fmt): rustfmt

* style(comment): remove commented code

* docs(changelog): configurable plugins

* style(fmt): rustfmt

* touch up ui

* fix: don't save permission data in memory

* feat: load cached permission

* test: add example test (WIP)

* fix: issue event are always denied

* test: update snapshot

* apply formatting

* refactor: update default cache function

* test: add more new test

* apply formatting

* Revert "apply formatting"

This reverts commit a4e9370.

* apply format

* fix: update cache path

* apply format

* fix: cache path

* fix: update log level

* test for github workflow

* Revert "test for github workflow"

This reverts commit 01eff3b.

* refactor: permission cache

* fix(test): permission grant/deny race condition

* style(fmt): rustfmt

* style(fmt): rustfmt

* configure permissions

* permission denied test

* snapshot

* add ui for small plugins

* style(fmt): rustfmt

* some cleanups

---------

Co-authored-by: Aram Drevekenin <[email protected]>
Co-authored-by: har7an <[email protected]>
Co-authored-by: Kyle Sutherland-Cash <[email protected]>
Co-authored-by: Thomas Linford <[email protected]>
Co-authored-by: Thomas Linford <[email protected]>

* docs(changelog): permission system

* feat(sessions): add a session manager to switch between sessions, tabs and panes and create new ones (#2721)

* write/read session metadata to disk for all sessions

* switch session client side

* fix tests

* various adjustments

* fix full screen focus bug in tiled panes

* fix tests

* fix permission sorting issue

* cleanups

* add session manager

* fix tests

* various cleanups

* style(fmt): rustfmt

* clear screen before switching sessions

* I hate you clippy

* truncate controls line to width

* version session cache

* attempt to fix plugin tests

* style(fmt): rustfmt

* another attempt to fix the tests in the ci

* docs(changelog): session manager

* fix(ux): various ui/ux fixes (#2722)

* force plugin render on permission request response

* clear warnings

* Revert "feat(ui): new status bar mode (#2619)"

This reverts commit 27763d2.

* adjust status bar help

* fix colors in session manager and shortcut in status-bar

* adjust keybindings

* docs(changelog): update ux fixes

* feat(plugins): optionally move plugin to focused tab (#2725)

* feat(plugins): move_to_focused_tab attribute for LaunchOrFocusPlugin

* style(fmt): rustfmt

* docs(changelog): move plugin to focused tab

* fix(keybinds): add 'floating' and 'name' to the Run command keybinding (#2726)

* fix(keybinds): add 'floating' and 'name' to the Run command keybinding

* style(fmt): rustfmt

* docs(changelog): keybind run floating pane

* fix(plugins): make sure configuration is also part of the plugin keys (#2727)

* fix(plugins): make sure configuration is also part of the plugin keys

* no thanks clippy

* docs(changelog): fix plugin configuration uniqueness

* fix(plugins): remove protobuf duplications (#2729)

* fix(plugins): remove protobuf duplications

* style(fmt): rustfmt

* Update CHANGELOG.md

* fix(plugins): various ui fixes (#2731)

* Update CHANGELOG.md

* fix(panes): refocus pane properly on tab change (#2734)

* fix(panes): stacked panes focus bug

* style(fmt): rustfmt

* docs(changelog): stacked pane focus glitch

* xtask/pipeline: Fix publish task (#2711)

* xtask/pipeline: Fix publish task

which was previously stuck in an infinite loop after successfully
publishing a crate. The error originated in the code only checking for
error conditions but not breaking out of the inner infinite loop in case
of success.

* xtask: Improve publish failure UX

by offering the user more actions to choose from when an error occured.

* utils/assets: Add generated prost files to assets

to make sure they're available at build time and are picked up by all
components. It seems we hit some strange bug with the build script
where, when running `cargo publish --dry-run` the build script **is
not** run before regularly compiling zellij-utils. This shouldn't happen
according to the docs, but I cannot explain what's causing it. So we're
using this as a workaround for now to make a smooth release.

* xtask: Prevent accidental git commit deletion

when dry-running a publish.

* utils: Add comments to protobuf-related code

to explain why these changes were performed. The comments all include a
link to an issue comment explaining the situation in greater detail.

* xtask: Build protobuf definitions

when building any part of the project, similar to how we build the
plugins when required. This should ensure that all crates built through
`cargo xtask` (which is the officially supported build method) will
receive up-to-date protobuf definitions.

* chore(release): v0.38.0

* chore(version): bump development version

* refactor(server): remove unnecessary mut (#2735)

* docs(changelog): refactor server

* chore(repo): update build instructions

* fix(status-bar): add break tab hints (#2748)

* fix(status-bar): add break tab hints

* fix(tests): update snapshot to new hints

* Update CHANGELOG.md

* fix(reconnect): do not clear terminal state when entering alternate screen (#2750)

* debug

* refactor(reconnect): articular reconnection logic

* docs(changelog): fix glitches on windows terminal

* fix(grid): memory leak with unfocused tabs (#2745)

* use hashset instead of vec for changed lines

avoid output buffer growring indefinitely if tab does not get rendered

* tidy up

- improve hashset -> vec conversion
- remove now unnecessary dedup

* use copied instead of cloned on iter

* docs(changelog): grid memory leak fix

* fix(input): block input thread for newtiledpane and newfloatingpane as well (#2757)

* docs(changelog): input action new pane fix

* chore(version): adjust version for release

* chore(release): v0.38.1

* chore(version): bump development version

* fix(terminal): wrap lines when adding characters in alternate screen (#2789)

* docs(changelog): line wrap bug

* chore(version): bump version for patch release

* chore(release): v0.38.2

* chore(version): bump development version

* fix(utils): validate session name (#2607)

* fix(utils): validate session name

* cargo fmt

* refactor: assign constant values to variables

* refactor: move operations unrealted to the condition

---------

Co-authored-by: Jae-Heon Ji <[email protected]>

* docs(changelog): fix validate session name

* merge conflict fix

* feat(panes): in place run (#2795)

* prototype

* fix tests

* add to all the things except plugins

* add in-place to plugin commands

* fix launch-or-focus should_float and in place behavior

* various cleanups

* style(fmt): rustfmt

* docs

* bring in commands to dumped layout

* tidy up data structures

* bring in plugins to dumped layout

* fix tests

* style(fmt): rustfmt

* chore: rename file (#2803)

Signed-off-by: AlixBernard <[email protected]>

* bring in floating panes

* bring in stacked panes

* style(fmt): rustfmt

* bring in new_tab_template

* bring in swap layouts

* bring in edit panes, command panes and cwds

* consolidate CWD common prefixes when possible

* filter out default shell

* style(fmt): rustfmt

* handle scrollback editor panes properly

* handle in place panes properly

* bring in pane names

* style(fmt): rustfmt

* style(fmt): rustfmt

* dump layout action to terminal

* log session layout to HD periodically

* resurrect dead sessions by attaching to them

* delete dead sessions

* style(fmt): rustfmt

* start command panes as suspended by default

* style(fmt): rustfmt

* respect tab/pane focus

* improve dump performance

* hide_floating_panes in layout and resurrection

* show resurrectable sessions in zellij ls and include timestamps

* style(fmt): rustfmt

* allow disabling session serialization in config

* style(fmt): rustfmt

* fix e2e tests

* add e2e test

* style(fmt): rustfmt

* style(fmt): rustfmt

* serialize and restore pane viewport

* fix e2e tests and add new one

* style(fmt): rustfmt

* cleanups

* cleanups

* more cleanups

* refactor: move stuff around

* fix e2e tests

* style(fmt): rustfmt

* style(fmt): handle compilation warnings

* add tests for new layout properties

* fix current session name indication

* style(fmt): rustfmt

* adjust default config

* some cleanups

* go away clippy

---------

Signed-off-by: AlixBernard <[email protected]>
Co-authored-by: alekspickle <[email protected]>
Co-authored-by: Example Name <[email protected]>
Co-authored-by: Oleks Gnatovskyi <[email protected]>
Co-authored-by: Thomas Linford <[email protected]>
Co-authored-by: har7an <[email protected]>
Co-authored-by: Kyle Sutherland-Cash <[email protected]>
Co-authored-by: Thomas Linford <[email protected]>
Co-authored-by: Nacho114 <[email protected]>
Co-authored-by: Jae-Heon Ji <[email protected]>
Co-authored-by: Orhun Parmaksız <[email protected]>
Co-authored-by: deepsghimire <[email protected]>
Co-authored-by: Jae-Heon Ji <[email protected]>
Co-authored-by: AlixBernard <[email protected]>
  • Loading branch information
14 people authored Oct 12, 2023
1 parent 9e8ebe4 commit 23e80c1
Show file tree
Hide file tree
Showing 110 changed files with 4,665 additions and 227 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ pkg-fmt = "tgz"

[features]
# See remarks in zellij_utils/Cargo.toml
default = [ "zellij-utils/plugins_from_target" ]
disable_automatic_asset_installation = [ "zellij-utils/disable_automatic_asset_installation" ]
unstable = [ "zellij-client/unstable", "zellij-utils/unstable" ]
singlepass = [ "zellij-server/singlepass" ]
default = ["zellij-utils/plugins_from_target"]
disable_automatic_asset_installation = ["zellij-utils/disable_automatic_asset_installation"]
unstable = ["zellij-client/unstable", "zellij-utils/unstable"]
singlepass = ["zellij-server/singlepass"]

# uncomment this when developing plugins in the Zellij UI to make plugin compilation faster
# [profile.dev.package."*"]
Expand Down
1 change: 1 addition & 0 deletions docs/MANPAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ ACTIONS
Right, Up, Down).
* __Clear__ - clears current screen.
* __DumpScreen: <File\>__ - dumps the screen in the specified file.
* __DumpLayout: <File\>__ - dumps the screen in the specified or default file.
* __EditScrollback__ - replaces the current pane with the scrollback buffer.
* __ScrollUp__ - scrolls up 1 line in the focused pane.
* __ScrollDown__ - scrolls down 1 line in the focused pane.
Expand Down
119 changes: 104 additions & 15 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use dialoguer::Confirm;
use std::{fs::File, io::prelude::*, path::PathBuf, process};
use std::{fs::File, io::prelude::*, path::PathBuf, process, time::Duration};

use crate::sessions::{
assert_session, assert_session_ne, get_active_session, get_name_generator, get_sessions,
assert_dead_session, assert_session, assert_session_ne, delete_session as delete_session_impl,
get_active_session, get_name_generator, get_resurrectable_sessions, get_sessions,
get_sessions_sorted_by_mtime, kill_session as kill_session_impl, match_session_name,
print_sessions, print_sessions_with_index, session_exists, ActiveSession, SessionNameMatch,
print_sessions, print_sessions_with_index, resurrection_layout, session_exists, ActiveSession,
SessionNameMatch,
};
use zellij_client::{
old_config_converter::{
Expand Down Expand Up @@ -49,7 +51,7 @@ pub(crate) fn kill_all_sessions(yes: bool) {
}
}
for session in &sessions {
kill_session_impl(session);
kill_session_impl(&session.0);
}
process::exit(0);
},
Expand All @@ -60,6 +62,39 @@ pub(crate) fn kill_all_sessions(yes: bool) {
}
}

pub(crate) fn delete_all_sessions(yes: bool, force: bool) {
let active_sessions: Vec<String> = get_sessions()
.unwrap_or_default()
.iter()
.map(|s| s.0.clone())
.collect();
let resurrectable_sessions = get_resurrectable_sessions();
let dead_sessions: Vec<_> = if force {
resurrectable_sessions
} else {
resurrectable_sessions
.iter()
.filter(|(name, _, _)| !active_sessions.contains(name))
.cloned()
.collect()
};
if !yes {
println!("WARNING: this action will delete all resurrectable sessions.");
if !Confirm::new()
.with_prompt("Do you want to continue?")
.interact()
.unwrap()
{
println!("Abort.");
process::exit(1);
}
}
for session in &dead_sessions {
delete_session_impl(&session.0, force);
}
process::exit(0);
}

pub(crate) fn kill_session(target_session: &Option<String>) {
match target_session {
Some(target_session) => {
Expand All @@ -74,6 +109,20 @@ pub(crate) fn kill_session(target_session: &Option<String>) {
}
}

pub(crate) fn delete_session(target_session: &Option<String>, force: bool) {
match target_session {
Some(target_session) => {
assert_dead_session(target_session, force);
delete_session_impl(target_session, force);
process::exit(0);
},
None => {
println!("Please specify the session name to delete.");
process::exit(1);
},
}
}

fn get_os_input<OsInputOutput>(
fn_get_os_input: fn() -> Result<OsInputOutput, nix::Error>,
) -> OsInputOutput {
Expand Down Expand Up @@ -117,6 +166,9 @@ fn find_indexed_session(
}
}

/// Client entrypoint for all [`zellij_utils::cli::CliAction`]
///
/// Checks session to send the action to and attaches with client
pub(crate) fn send_action_to_session(
cli_action: zellij_utils::cli::CliAction,
requested_session_name: Option<String>,
Expand All @@ -141,7 +193,11 @@ pub(crate) fn send_action_to_session(
attach_with_cli_client(cli_action, &session_name, config);
},
ActiveSession::Many => {
let existing_sessions = get_sessions().unwrap();
let existing_sessions: Vec<String> = get_sessions()
.unwrap_or_default()
.iter()
.map(|s| s.0.clone())
.collect();
if let Some(session_name) = requested_session_name {
if existing_sessions.contains(&session_name) {
attach_with_cli_client(cli_action, &session_name, config);
Expand All @@ -150,14 +206,14 @@ pub(crate) fn send_action_to_session(
"Session '{}' not found. The following sessions are active:",
session_name
);
print_sessions(existing_sessions);
list_sessions(false);
std::process::exit(1);
}
} else if let Ok(session_name) = envs::get_session_name() {
attach_with_cli_client(cli_action, &session_name, config);
} else {
eprintln!("Please specify the session name to send actions to. The following sessions are active:");
print_sessions(existing_sessions);
list_sessions(false);
std::process::exit(1);
}
},
Expand Down Expand Up @@ -293,7 +349,13 @@ fn attach_with_session_name(
"Ambiguous selection: multiple sessions names start with '{}':",
prefix
);
print_sessions(sessions);
print_sessions(
sessions
.iter()
.map(|s| (s.clone(), Duration::default(), false))
.collect(),
false,
);
process::exit(1);
},
SessionNameMatch::None => {
Expand All @@ -310,7 +372,7 @@ fn attach_with_session_name(
ActiveSession::One(session_name) => ClientInfo::Attach(session_name, config_options),
ActiveSession::Many => {
println!("Please specify the session to attach to, either by using the full name or a unique prefix.\nThe following sessions are active:");
print_sessions(get_sessions().unwrap());
list_sessions(false);
process::exit(1);
},
},
Expand Down Expand Up @@ -351,6 +413,7 @@ pub(crate) fn start_client(opts: CliArgs) {
opts.command = Some(Command::Sessions(Sessions::Attach {
session_name: reconnect_to_session.name.clone(),
create: true,
force_run_commands: false,
index: None,
options: None,
}));
Expand All @@ -369,6 +432,7 @@ pub(crate) fn start_client(opts: CliArgs) {
if let Some(Command::Sessions(Sessions::Attach {
session_name,
create,
force_run_commands,
index,
options,
})) = opts.command.clone()
Expand All @@ -387,10 +451,20 @@ pub(crate) fn start_client(opts: CliArgs) {
.as_ref()
.and_then(|s| session_exists(&s).ok())
.unwrap_or(false);
if create && !session_exists {
let resurrection_layout =
session_name.as_ref().and_then(|s| resurrection_layout(&s));
if create && !session_exists && resurrection_layout.is_none() {
session_name.clone().map(start_client_plan);
}
attach_with_session_name(session_name, config_options.clone(), create)
match (session_name.as_ref(), resurrection_layout) {
(Some(session_name), Some(mut resurrection_layout)) if !session_exists => {
if force_run_commands {
resurrection_layout.recursively_add_start_suspended(Some(false));
}
ClientInfo::Resurrect(session_name.clone(), resurrection_layout)
},
_ => attach_with_session_name(session_name, config_options.clone(), create),
}
};

if let Ok(val) = std::env::var(envs::SESSION_NAME_ENV_KEY) {
Expand All @@ -399,9 +473,12 @@ pub(crate) fn start_client(opts: CliArgs) {
}
}

let attach_layout = match client {
let attach_layout = match &client {
ClientInfo::Attach(_, _) => None,
ClientInfo::New(_) => Some(layout),
ClientInfo::Resurrect(_session_name, layout_to_resurrect) => {
Some(layout_to_resurrect.clone())
},
};

let tab_position_to_focus = reconnect_to_session
Expand Down Expand Up @@ -457,9 +534,12 @@ pub(crate) fn start_client(opts: CliArgs) {
config_options.clone(),
true,
);
let attach_layout = match client {
let attach_layout = match &client {
ClientInfo::Attach(_, _) => None,
ClientInfo::New(_) => Some(layout),
ClientInfo::Resurrect(_, resurrection_layout) => {
Some(resurrection_layout.clone())
},
};
reconnect_to_session = start_client_impl(
Box::new(os_input),
Expand Down Expand Up @@ -518,15 +598,24 @@ pub(crate) fn start_client(opts: CliArgs) {
}

fn generate_unique_session_name() -> String {
let sessions = get_sessions();
let sessions = get_sessions().map(|sessions| {
sessions
.iter()
.map(|s| s.0.clone())
.collect::<Vec<String>>()
});
let dead_sessions: Vec<String> = get_resurrectable_sessions()
.iter()
.map(|(s, _, _)| s.clone())
.collect();
let Ok(sessions) = sessions else {
eprintln!("Failed to list existing sessions: {:?}", sessions);
process::exit(1);
};

let name = get_name_generator()
.take(1000)
.find(|name| !sessions.contains(name));
.find(|name| !sessions.contains(name) && !dead_sessions.contains(name));

if let Some(name) = name {
return name;
Expand Down
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,23 @@ fn main() {
}
}

if let Some(Command::Sessions(Sessions::ListSessions)) = opts.command {
commands::list_sessions();
if let Some(Command::Sessions(Sessions::ListSessions { no_formatting })) = opts.command {
commands::list_sessions(no_formatting);
} else if let Some(Command::Sessions(Sessions::KillAllSessions { yes })) = opts.command {
commands::kill_all_sessions(yes);
} else if let Some(Command::Sessions(Sessions::KillSession { ref target_session })) =
opts.command
{
commands::kill_session(target_session);
} else if let Some(Command::Sessions(Sessions::DeleteAllSessions { yes, force })) = opts.command
{
commands::delete_all_sessions(yes, force);
} else if let Some(Command::Sessions(Sessions::DeleteSession {
ref target_session,
force,
})) = opts.command
{
commands::delete_session(target_session, force);
} else if let Some(path) = opts.server {
commands::start_server(path, opts.debug);
} else {
Expand Down
Loading

0 comments on commit 23e80c1

Please sign in to comment.