Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(collaboration): implement multiple users #957

Merged
merged 4 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/plugins/status-bar.wasm
100644 → 100755
Binary file not shown.
Binary file modified assets/plugins/strider.wasm
100644 → 100755
Binary file not shown.
Binary file modified assets/plugins/tab-bar.wasm
100644 → 100755
Binary file not shown.
1 change: 1 addition & 0 deletions default-plugins/tab-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl ZellijPlugin for State {
t.is_sync_panes_active,
self.mode_info.palette,
self.mode_info.capabilities,
t.other_focused_clients.as_slice(),
);
all_tabs.push(tab);
}
Expand Down
76 changes: 51 additions & 25 deletions default-plugins/tab-bar/src/tab.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,62 @@
use crate::{line::tab_separator, LinePart};
use ansi_term::ANSIStrings;
use ansi_term::{ANSIString, ANSIStrings};
use unicode_width::UnicodeWidthStr;
use zellij_tile::prelude::*;
use zellij_tile_utils::style;

pub fn active_tab(text: String, palette: Palette, separator: &str) -> LinePart {
let left_separator = style!(palette.gray, palette.green).paint(separator);
let tab_text_len = text.width() + 2 + separator.width() * 2; // 2 for left and right separators, 2 for the text padding
let tab_styled_text = style!(palette.black, palette.green)
.bold()
.paint(format!(" {} ", text));
let right_separator = style!(palette.green, palette.gray).paint(separator);
let tab_styled_text =
ANSIStrings(&[left_separator, tab_styled_text, right_separator]).to_string();
LinePart {
part: tab_styled_text,
len: tab_text_len,
fn cursors(focused_clients: &[ClientId], palette: Palette) -> (Vec<ANSIString>, usize) {
// cursor section, text length
let mut len = 0;
let mut cursors = vec![];
for client_id in focused_clients.iter() {
if let Some(color) = client_id_to_colors(*client_id, palette) {
cursors.push(style!(color.1, color.0).paint(" "));
len += 1;
}
}
(cursors, len)
}

pub fn non_active_tab(text: String, palette: Palette, separator: &str) -> LinePart {
let left_separator = style!(palette.gray, palette.fg).paint(separator);
let tab_text_len = text.width() + 2 + separator.width() * 2; // 2 for left and right separators, 2 for the text padding
let tab_styled_text = style!(palette.black, palette.fg)
pub fn render_tab(
text: String,
palette: Palette,
separator: &str,
focused_clients: &[ClientId],
active: bool,
) -> LinePart {
let background_color = if active { palette.green } else { palette.fg };
let left_separator = style!(palette.gray, background_color).paint(separator);
let mut tab_text_len = text.width() + 2 + separator.width() * 2; // 2 for left and right separators, 2 for the text padding

let tab_styled_text = style!(palette.black, background_color)
.bold()
.paint(format!(" {} ", text));
let right_separator = style!(palette.fg, palette.gray).paint(separator);
let tab_styled_text =
ANSIStrings(&[left_separator, tab_styled_text, right_separator]).to_string();

let right_separator = style!(background_color, palette.gray).paint(separator);
let tab_styled_text = if !focused_clients.is_empty() {
let (cursor_section, extra_length) = cursors(focused_clients, palette);
tab_text_len += extra_length;
let mut s = String::new();
let cursor_beginning = style!(palette.black, background_color)
.bold()
.paint("[")
.to_string();
let cursor_section = ANSIStrings(&cursor_section).to_string();
let cursor_end = style!(palette.black, background_color)
.bold()
.paint("]")
.to_string();
s.push_str(&left_separator.to_string());
s.push_str(&tab_styled_text.to_string());
s.push_str(&cursor_beginning);
s.push_str(&cursor_section);
s.push_str(&cursor_end);
s.push_str(&right_separator.to_string());
s
} else {
ANSIStrings(&[left_separator, tab_styled_text, right_separator]).to_string()
};

LinePart {
part: tab_styled_text,
len: tab_text_len,
Expand All @@ -40,15 +69,12 @@ pub fn tab_style(
is_sync_panes_active: bool,
palette: Palette,
capabilities: PluginCapabilities,
focused_clients: &[ClientId],
) -> LinePart {
let separator = tab_separator(capabilities);
let mut tab_text = text;
if is_sync_panes_active {
tab_text.push_str(" (Sync)");
}
if is_active_tab {
active_tab(tab_text, palette, separator)
} else {
non_active_tab(tab_text, palette, separator)
}
render_tab(tab_text, palette, separator, focused_clients, is_active_tab)
}
Loading