Skip to content

Commit

Permalink
feat(sessions): resurrect sessions through the session-manager (and p…
Browse files Browse the repository at this point in the history
…lugin API) (#2902)

* working with table and scrolling

* ui and functionality complete

* fix formatting

* refactor: background jobs

* style(fmt): rustfmt
  • Loading branch information
imsnif authored Nov 4, 2023
1 parent 37bc636 commit 4c6b03a
Show file tree
Hide file tree
Showing 16 changed files with 737 additions and 97 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions default-plugins/session-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ zellij-tile = { path = "../../zellij-tile" }
chrono = "0.4.0"
fuzzy-matcher = "0.3.7"
unicode-width = "0.1.10"
humantime = "2.1.0"
52 changes: 47 additions & 5 deletions default-plugins/session-manager/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
mod resurrectable_sessions;
mod session_list;
mod ui;
use zellij_tile::prelude::*;

use std::collections::BTreeMap;

use ui::{
components::{render_controls_line, render_new_session_line, render_prompt, Colors},
components::{
render_controls_line, render_new_session_line, render_prompt, render_resurrection_toggle,
Colors,
},
SessionUiInfo,
};

use resurrectable_sessions::ResurrectableSessions;
use session_list::SessionList;

#[derive(Default)]
struct State {
session_name: Option<String>,
sessions: SessionList,
resurrectable_sessions: ResurrectableSessions,
search_term: String,
new_session_name: Option<String>,
browsing_resurrection_sessions: bool,
colors: Colors,
}

Expand Down Expand Up @@ -45,7 +52,9 @@ impl ZellijPlugin for State {
Event::PermissionRequestResult(_result) => {
should_render = true;
},
Event::SessionUpdate(session_infos) => {
Event::SessionUpdate(session_infos, resurrectable_session_list) => {
self.resurrectable_sessions
.update(resurrectable_session_list);
self.update_session_infos(session_infos);
should_render = true;
},
Expand All @@ -55,6 +64,11 @@ impl ZellijPlugin for State {
}

fn render(&mut self, rows: usize, cols: usize) {
if self.browsing_resurrection_sessions {
self.resurrectable_sessions.render(rows, cols);
return;
}
render_resurrection_toggle(cols, false);
render_prompt(
self.new_session_name.is_some(),
&self.search_term,
Expand Down Expand Up @@ -94,12 +108,16 @@ impl State {
}
should_render = true;
} else if let Key::Down = key {
if self.new_session_name.is_none() {
if self.browsing_resurrection_sessions {
self.resurrectable_sessions.move_selection_down();
} else if self.new_session_name.is_none() {
self.sessions.move_selection_down();
}
should_render = true;
} else if let Key::Up = key {
if self.new_session_name.is_none() {
if self.browsing_resurrection_sessions {
self.resurrectable_sessions.move_selection_up();
} else if self.new_session_name.is_none() {
self.sessions.move_selection_up();
}
should_render = true;
Expand All @@ -108,6 +126,8 @@ impl State {
self.handle_selection();
} else if let Some(new_session_name) = self.new_session_name.as_mut() {
new_session_name.push(character);
} else if self.browsing_resurrection_sessions {
self.resurrectable_sessions.handle_character(character);
} else {
self.search_term.push(character);
self.sessions
Expand All @@ -121,6 +141,8 @@ impl State {
} else {
new_session_name.pop();
}
} else if self.browsing_resurrection_sessions {
self.resurrectable_sessions.handle_backspace();
} else {
self.search_term.pop();
self.sessions
Expand Down Expand Up @@ -153,13 +175,33 @@ impl State {
hide_self();
}
should_render = true;
} else if let Key::BackTab = key {
self.browsing_resurrection_sessions = !self.browsing_resurrection_sessions;
should_render = true;
} else if let Key::Delete = key {
if self.browsing_resurrection_sessions {
self.resurrectable_sessions.delete_selected_session();
should_render = true;
}
} else if let Key::Ctrl('d') = key {
if self.browsing_resurrection_sessions {
self.resurrectable_sessions
.show_delete_all_sessions_warning();
should_render = true;
}
} else if let Key::Esc = key {
hide_self();
}
should_render
}
fn handle_selection(&mut self) {
if let Some(new_session_name) = &self.new_session_name {
if self.browsing_resurrection_sessions {
if let Some(session_name_to_resurrect) =
self.resurrectable_sessions.get_selected_session_name()
{
switch_session(Some(&session_name_to_resurrect));
}
} else if let Some(new_session_name) = &self.new_session_name {
if new_session_name.is_empty() {
switch_session(None);
} else if self.session_name.as_ref() == Some(new_session_name) {
Expand Down
Loading

0 comments on commit 4c6b03a

Please sign in to comment.