Function bodies 84 total
handle_mode_sync_pipe function · rust · L202-L237 (36 LOC)src/main.rs
fn handle_mode_sync_pipe(&mut self, payload: &str) -> bool {
if self.role == Role::Daemon {
return false;
}
let (id_str, mode_str) = match payload.split_once(':') {
Some(pair) => pair,
None => return false,
};
let client_id: u16 = match id_str.parse() {
Ok(id) => id,
Err(_) => return false,
};
// Only react to the Daemon that spawned us.
if client_id != self.spawned_for_client {
return false;
}
let mode = match mode_from_str(mode_str) {
Some(m) => m,
None => return false,
};
let base = self.resolve_base_mode();
if self.mode != mode {
self.mode = mode;
if self.role == Role::Tooltip && !is_tooltip_hidden_mode(mode, base) {
// Only the active clone resizes (uses correct display dimensions).
if self.own_client_id == self.spawned_foris_tooltip_hidden_mode function · rust · L241-L247 (7 LOC)src/main.rs
fn is_tooltip_hidden_mode(mode: InputMode, base_mode: InputMode) -> bool {
mode == base_mode
|| matches!(
mode,
InputMode::RenamePane | InputMode::RenameTab | InputMode::EnterSearch
)
}mode_from_str function · rust · L250-L268 (19 LOC)src/main.rs
fn mode_from_str(s: &str) -> Option<InputMode> {
match s {
"Locked" => Some(InputMode::Locked),
"Normal" => Some(InputMode::Normal),
"Pane" => Some(InputMode::Pane),
"Tab" => Some(InputMode::Tab),
"Resize" => Some(InputMode::Resize),
"Move" => Some(InputMode::Move),
"Scroll" => Some(InputMode::Scroll),
"Search" => Some(InputMode::Search),
"EnterSearch" => Some(InputMode::EnterSearch),
"RenameTab" => Some(InputMode::RenameTab),
"RenamePane" => Some(InputMode::RenamePane),
"Session" => Some(InputMode::Session),
"Prompt" => Some(InputMode::Prompt),
"Tmux" => Some(InputMode::Tmux),
_ => None,
}
}load function · rust · L273-L352 (80 LOC)src/main.rs
fn load(&mut self, configuration: BTreeMap<String, String>) {
if configuration
.get(CONFIG_IS_HUD)
.map_or(false, |v| v == "true")
{
self.role = Role::Hud;
} else if configuration
.get(CONFIG_IS_TOOLTIP)
.map_or(false, |v| v == "true")
{
self.role = Role::Tooltip;
}
match self.role {
Role::Hud | Role::Tooltip => {
self.hud_config = HudConfig::from_config(&configuration);
let ids = get_plugin_ids();
self.own_plugin_id = Some(ids.plugin_id);
self.own_client_id = ids.client_id;
self.cwd = ids.initial_cwd;
// Determine which client's Daemon spawned us for tab-following.
// Falls back to own_client_id if missing (single-client scenario).
self.spawned_for_client = configuration
.get(CONFIG_SPAWNED_FOR_CLIENT)
update function · rust · L353-L534 (182 LOC)src/main.rs
fn update(&mut self, event: Event) -> bool {
match event {
Event::PermissionRequestResult(result) => {
if result == PermissionStatus::Granted {
self.has_permission = true;
match self.role {
Role::Hud | Role::Tooltip => {
// Active clone: move pane to correct tab (backup for load() attempt
// in case break_panes_to_tab_with_index requires permissions).
if self.own_client_id == self.spawned_for_client {
if let Some(plugin_id) = self.own_plugin_id {
let tab_0based = self.initial_tab.saturating_sub(1);
break_panes_to_tab_with_index(
&[PaneId::Plugin(plugin_id)],
tab_0based,
false,
pipe function · rust · L535-L584 (50 LOC)src/main.rs
fn pipe(&mut self, message: PipeMessage) -> bool {
let payload = message.payload.as_deref().unwrap_or("");
match message.name.as_str() {
"mode_sync" => self.handle_mode_sync_pipe(payload),
"request_mode_sync" => {
// HUD/Tooltip asks for current mode on load.
// Each Daemon responds; HUD/Tooltip will use only their spawner's reply.
if self.role == Role::Daemon && self.has_permission {
self.broadcast_mode_sync();
}
false
}
"close_hud" => match self.role {
Role::Hud => {
let client_id: u16 = payload.parse().unwrap_or(0);
if client_id == self.spawned_for_client {
close_self();
}
false
}
Role::Daemon => {
let client_id: u16 = payload.parse().unwrap_or(0);render function · rust · L585-L635 (51 LOC)src/main.rs
fn render(&mut self, _rows: usize, cols: usize) {
match self.role {
Role::Hud => {
if !self.render_ready {
// Suppress rendering until first command results arrive
print!("{}", " ".repeat(cols));
return;
}
let c = &self.hud_config;
let bar_bg = c.resolve_color_with_accent(&c.bar_bg, &c.palette, self.mode);
let bar_bg_esc = bar_bg.bg();
let reset = "\x1b[0m";
let left = self.render_format(&self.hud_config.format_left.clone(), &bar_bg);
let center_fmt = self.hud_config.format_center.clone();
let right = self.render_format(&self.hud_config.format_right.clone(), &bar_bg);
let center = if center_fmt.is_empty() {
String::new()
} else {
self.render_format(¢er_fmt, &bar_bg)
};
Repobility · severity-and-effort ranking · https://repobility.com
visible_len function · rust · L9-L24 (16 LOC)src/render.rs
pub(crate) fn visible_len(s: &str) -> usize {
let mut len = 0;
let mut in_escape = false;
for ch in s.chars() {
if ch == '\x1b' {
in_escape = true;
} else if in_escape {
if ch == 'm' {
in_escape = false;
}
} else {
len += UnicodeWidthChar::width(ch).unwrap_or(0);
}
}
len
}render_format function · rust · L30-L33 (4 LOC)src/render.rs
pub(crate) fn render_format(&self, format_str: &str, bar_bg: &Color) -> String {
let mut spans = self.flatten_format(format_str);
resolve_and_emit(&mut spans, bar_bg)
}format_cwd function · rust · L34-L47 (14 LOC)src/render.rs
pub(crate) fn format_cwd(&self) -> String {
// Show "~" when cwd is the user's home directory
if let Ok(home) = std::env::var("HOME") {
if self.cwd == std::path::PathBuf::from(&home) {
return "~".to_string();
}
}
if let Some(name) = self.cwd.file_name() {
name.to_string_lossy().to_string()
} else {
self.cwd.to_string_lossy().to_string()
}
}tokenize function · rust · L53-L88 (36 LOC)src/spans.rs
fn tokenize(format_str: &str) -> Vec<Token> {
let mut tokens = Vec::new();
let mut literal = String::new();
let mut chars = format_str.chars().peekable();
while let Some(ch) = chars.next() {
if ch == '{' {
// Collect widget ref name
let mut name = String::new();
let mut closed = false;
for inner in chars.by_ref() {
if inner == '}' {
closed = true;
break;
}
name.push(inner);
}
if closed && !name.is_empty() {
if !literal.is_empty() {
tokens.push(Token::Literal(std::mem::take(&mut literal)));
}
tokens.push(Token::Ref(name));
} else {
// Unclosed brace or empty ref — keep as literal text
literal.push('{');
literal.push_str(&name);
}
} else {
literal.presolve_style function · rust · L103-L110 (8 LOC)src/spans.rs
fn resolve_style(&self, style: &WidgetStyle) -> ResolvedStyle {
let c = &self.hud_config;
ResolvedStyle {
fg: resolve_span_color(&style.fg, c, self.mode),
bg: resolve_span_color(&style.bg, c, self.mode),
attr: style.attr.clone(),
}
}flatten_format function · rust · L113-L133 (21 LOC)src/spans.rs
pub(crate) fn flatten_format(&self, format_str: &str) -> Vec<Span> {
let tokens = tokenize(format_str);
let mut spans = Vec::new();
for token in tokens {
match token {
Token::Literal(text) => {
// Top-level literal text has no specific style (bar_bg is applied later)
spans.push(Span {
text,
fg: SpanColor::Concrete(Color::None),
bg: SpanColor::Concrete(Color::None),
attr: String::new(),
});
}
Token::Ref(name) => {
self.flatten_widget(&name, &mut spans, 0);
}
}
}
spans
}flatten_widget function · rust · L136-L174 (39 LOC)src/spans.rs
fn flatten_widget(&self, name: &str, out: &mut Vec<Span>, depth: u8) {
if depth >= MAX_DEPTH {
return;
}
let c = &self.hud_config;
match name {
"mode" => {
let rs = self.resolve_style(&c.mode_style);
let mode_text = c
.mode_content
.get(&self.mode)
.cloned()
.unwrap_or_else(|| format!("{:?}", self.mode).to_uppercase());
let content = c.mode_format.replace("{content}", &mode_text);
self.flatten_format_with_style(&content, &rs, out, depth);
}
"session" => {
let rs = self.resolve_style(&c.session_style);
let content = c.session_format.replace("{name}", &self.session_name);
self.flatten_format_with_style(&content, &rs, out, depth);
}
"tabs" => {
self.flatten_tabs(out, depth);
flatten_format_with_style function · rust · L178-L201 (24 LOC)src/spans.rs
fn flatten_format_with_style(
&self,
format_str: &str,
style: &ResolvedStyle,
out: &mut Vec<Span>,
depth: u8,
) {
let tokens = tokenize(format_str);
for token in tokens {
match token {
Token::Literal(text) => {
out.push(Span {
text,
fg: style.fg.clone(),
bg: style.bg.clone(),
attr: style.attr.clone(),
});
}
Token::Ref(name) => {
self.flatten_widget(&name, out, depth + 1);
}
}
}
}Repobility · open methodology · https://repobility.com/research/
flatten_tabs function · rust · L207-L345 (139 LOC)src/spans.rs
fn flatten_tabs(&self, out: &mut Vec<Span>, depth: u8) {
let c = &self.hud_config;
let bar_bg = c.resolve_color_with_accent(&c.bar_bg, &c.palette, self.mode);
let anchor = || Span {
text: String::new(),
fg: SpanColor::Concrete(Color::None),
bg: SpanColor::Concrete(bar_bg.clone()),
attr: String::new(),
};
for (i, tab) in self.tabs.iter().enumerate() {
// Anchor before each tab: represents the bar_bg gap
out.push(anchor());
// Inter-tab separator with configurable style
if i > 0 && !c.tab_separator_content.is_empty() {
let sep_rs = self.resolve_style(&c.tab_separator_style);
out.push(Span {
text: c.tab_separator_content.clone(),
fg: sep_rs.fg,
bg: sep_rs.bg,
attr: sep_rs.attr,
});
out.push(anchor());
flatten_command_widget function · rust · L348-L369 (22 LOC)src/spans.rs
fn flatten_command_widget(&self, name: &str, out: &mut Vec<Span>, depth: u8) {
let widget = match self.hud_config.command_widgets.get(name) {
Some(w) => w,
None => return,
};
let output = match self.command_outputs.get(name) {
Some(o) => o,
None => return,
};
// Hide widget on failure or empty output
if output.exit_code != 0 || output.stdout.is_empty() {
return;
}
let rs = self.resolve_style(&widget.style);
let content = widget
.format
.replace("{stdout}", &output.stdout)
.replace("{exit_code}", &output.exit_code.to_string());
self.flatten_format_with_style(&content, &rs, out, depth);
}flatten_text_widget function · rust · L372-L380 (9 LOC)src/spans.rs
fn flatten_text_widget(&self, name: &str, out: &mut Vec<Span>, depth: u8) {
let widget = match self.hud_config.text_widgets.get(name) {
Some(w) => w,
None => return,
};
let rs = self.resolve_style(&widget.style);
let content = widget.format.replace("{content}", &widget.content);
self.flatten_format_with_style(&content, &rs, out, depth);
}attr_escape function · rust · L388-L401 (14 LOC)src/spans.rs
fn attr_escape(attr: &str) -> String {
if attr.is_empty() {
return String::new();
}
let mut out = String::new();
for part in attr.split(',') {
match part.trim() {
"bold" => out.push_str("\x1b[1m"),
"italic" => out.push_str("\x1b[3m"),
_ => {}
}
}
out
}resolve_and_emit function · rust · L405-L455 (51 LOC)src/spans.rs
pub(crate) fn resolve_and_emit(spans: &mut [Span], bar_bg: &Color) -> String {
// Forward pass: resolve PrevBg
let mut last_concrete_bg = bar_bg.clone();
for span in spans.iter_mut() {
if let SpanColor::PrevBg = &span.fg {
span.fg = SpanColor::Concrete(last_concrete_bg.clone());
}
if let SpanColor::PrevBg = &span.bg {
span.bg = SpanColor::Concrete(last_concrete_bg.clone());
}
if let SpanColor::Concrete(c) = &span.bg {
last_concrete_bg = c.clone();
}
}
// Backward pass: resolve NextBg
let mut next_concrete_bg = bar_bg.clone();
for span in spans.iter_mut().rev() {
if let SpanColor::NextBg = &span.fg {
span.fg = SpanColor::Concrete(next_concrete_bg.clone());
}
if let SpanColor::NextBg = &span.bg {
span.bg = SpanColor::Concrete(next_concrete_bg.clone());
}
if let SpanColor::Concrete(c) = &span.bg {
next_resolve_span_color function · rust · L462-L473 (12 LOC)src/spans.rs
fn resolve_span_color(
value: &str,
config: &crate::config::HudConfig,
mode: zellij_tile::prelude::InputMode,
) -> SpanColor {
match value {
"" => SpanColor::Concrete(Color::None),
"prev_bg" => SpanColor::PrevBg,
"next_bg" => SpanColor::NextBg,
_ => SpanColor::Concrete(config.resolve_color_with_accent(value, &config.palette, mode)),
}
}spawn_hud function · rust · L7-L28 (22 LOC)src/spawn.rs
pub(crate) fn spawn_hud(&mut self) {
if self.hud_is_open {
return;
}
let initial_tab = self.tabs.iter().position(|t| t.active).map(|i| i + 1).unwrap_or(1);
let mut config = self.plugin_config.clone();
config.insert(CONFIG_IS_HUD.to_string(), "true".to_string());
config.insert(
CONFIG_SPAWNED_FOR_CLIENT.to_string(),
self.own_client_id.to_string(),
);
config.insert("initial_tab".to_string(), initial_tab.to_string());
let msg = MessageToPlugin::new("spawn_hud")
.with_plugin_url("zellij:OWN_URL")
.with_plugin_config(config)
.with_floating_pane_coordinates(self.hud_coordinates())
.new_plugin_instance_should_have_pane_title(String::new());
pipe_message_to_plugin(msg);
self.hud_is_open = true;
}spawn_tooltip function · rust · L32-L65 (34 LOC)src/spawn.rs
pub(crate) fn spawn_tooltip(&mut self, active_mode: InputMode) {
if self.tooltip_is_open {
return;
}
let border = self.hud_config.tooltip_border;
let (tt_rows, tt_cols) = match &self.mode_info {
Some(mi) => tooltip_size(mi, active_mode, border),
None => return,
};
if tt_rows == 0 || tt_cols == 0 {
return;
}
let initial_tab = self.tabs.iter().position(|t| t.active).map(|i| i + 1).unwrap_or(1);
let mut config = self.plugin_config.clone();
config.insert(CONFIG_IS_TOOLTIP.to_string(), "true".to_string());
config.insert(
CONFIG_SPAWNED_FOR_CLIENT.to_string(),
self.own_client_id.to_string(),
);
config.insert("initial_tab".to_string(), initial_tab.to_string());
let msg = MessageToPlugin::new("spawn_tooltip")
.with_plugin_url("zellij:OWN_URL")
.with_plugin_config(config)
Same scanner, your repo: https://repobility.com — Repobility
close_hud_via_pipe function · rust · L69-L74 (6 LOC)src/spawn.rs
pub(crate) fn close_hud_via_pipe(&self) {
pipe_message_to_plugin(
MessageToPlugin::new("close_hud")
.with_payload(self.own_client_id.to_string()),
);
}close_tooltip_via_pipe function · rust · L77-L82 (6 LOC)src/spawn.rs
pub(crate) fn close_tooltip_via_pipe(&self) {
pipe_message_to_plugin(
MessageToPlugin::new("close_tooltip")
.with_payload(self.own_client_id.to_string()),
);
}hud_coordinates function · rust · L83-L99 (17 LOC)src/spawn.rs
pub(crate) fn hud_coordinates(&self) -> FloatingPaneCoordinates {
let (rows, cols) = self.display_area();
let height = 1;
let y = rows.saturating_sub(height);
FloatingPaneCoordinates::new(
Some("0".to_string()),
Some(format!("{}", y)),
Some(format!("{}", cols)),
Some(format!("{}", height)),
Some(true),
Some(true),
)
.unwrap_or_default()
}tooltip_coordinates function · rust · L100-L139 (40 LOC)src/spawn.rs
fn tooltip_coordinates(
&self,
tt_rows: usize,
tt_cols: usize,
) -> FloatingPaneCoordinates {
let (rows, cols) = self.display_area();
let position = &self.hud_config.tooltip_position;
let border = self.hud_config.tooltip_border;
let hud_height = if self.enable_status_bar { 1 } else { 0 };
let width = tt_cols.min(cols);
let height = tt_rows.min(rows.saturating_sub(hud_height));
let (x, y) = match position.as_str() {
"bottom-left" => {
(0, rows.saturating_sub(hud_height + height))
}
"top-right" => {
(cols.saturating_sub(width), 0)
}
"top-left" => {
(0, 0)
}
// "bottom-right" (default)
_ => {
(cols.saturating_sub(width), rows.saturating_sub(hud_height + height))
}
};
FloatingPaneCoordinates::new(
Some(display_area function · rust · L140-L147 (8 LOC)src/spawn.rs
fn display_area(&self) -> (usize, usize) {
self.tabs
.iter()
.find(|t| t.active)
.map(|t| (t.display_area_rows, t.display_area_columns))
.unwrap_or((24, 80))
}render_tooltip function · rust · L15-L103 (89 LOC)src/tooltip.rs
pub(crate) fn render_tooltip(&self, rows: usize, cols: usize) {
let mode_info = match &self.mode_info {
Some(m) => m,
None => return,
};
let ma = get_actions_for_mode(mode_info, self.mode);
let c = &self.hud_config;
let reset = "\x1b[0m";
let key_color = c.resolve_color_with_accent(&c.tooltip_key_color, &c.palette, self.mode).fg();
let sep_color = c.resolve_color_with_accent(&c.tooltip_separator_color, &c.palette, self.mode).fg();
let desc_color = c.resolve_color_with_accent(&c.tooltip_description_color, &c.palette, self.mode).fg();
let mode_color = c.resolve_color_with_accent(&c.tooltip_mode_color, &c.palette, self.mode).fg();
let separator = &c.tooltip_separator;
let has_common = !ma.common.is_empty();
let main_rows = if has_common {
rows.saturating_sub(1)
} else {
rows
};
let key_width = ma
.actionresize_tooltip_for_mode function · rust · L106-L134 (29 LOC)src/tooltip.rs
pub(crate) fn resize_tooltip_for_mode(&self) {
let (plugin_id, mode_info) =
match (self.own_plugin_id, &self.mode_info) {
(Some(id), Some(mi)) => (id, mi),
_ => return,
};
if self.tabs.is_empty() {
return;
}
let ma = get_actions_for_mode(mode_info, self.mode);
if ma.actions.is_empty() && ma.common.is_empty() {
return;
}
let border = self.hud_config.tooltip_border;
let coords = tooltip_coordinates(
&ma,
&self.tabs,
self.hud_config.enable_status_bar,
&self.hud_config.tooltip_position,
border,
);
change_floating_panes_coordinates(vec![(
PaneId::Plugin(plugin_id),
coords,
)]);
}update_tooltip_title function · rust · L137-L152 (16 LOC)src/tooltip.rs
pub(crate) fn update_tooltip_title(&self) {
let plugin_id = match self.own_plugin_id {
Some(id) => id,
None => return,
};
let template = &self.hud_config.tooltip_title;
if template.is_empty() {
rename_plugin_pane(plugin_id, "");
return;
}
let mode_name = format!("{:?}", self.mode).to_lowercase();
let title = template.replace("{mode}", &mode_name);
rename_plugin_pane(plugin_id, &title);
}If a scraper extracted this row, it came from Repobility (https://repobility.com)
tooltip_size function · rust · L156-L162 (7 LOC)src/tooltip.rs
pub(crate) fn tooltip_size(mode_info: &ModeInfo, mode: InputMode, border: bool) -> (usize, usize) {
let ma = get_actions_for_mode(mode_info, mode);
if ma.actions.is_empty() && ma.common.is_empty() {
return (0, 0);
}
tooltip_dimensions(&ma, border)
}tooltip_dimensions function · rust · L165-L202 (38 LOC)src/tooltip.rs
fn tooltip_dimensions(ma: &ModeActions, border: bool) -> (usize, usize) {
let key_width = ma
.actions
.iter()
.map(|a| a.key.len())
.max()
.unwrap_or(0);
let desc_width = ma
.actions
.iter()
.map(|a| {
let icon = a.action_type.icon();
visible_len(icon) + 1 + a.description.len()
})
.max()
.unwrap_or(0);
// " key ➜ icon desc"
let main_width = 1 + key_width + 3 + desc_width;
// Common line: "icon icon desc"
let common_width = if ma.common.is_empty() {
0
} else {
let icons_width: usize = ma.common.len(); // each icon is 1 visible char
let sep_width = ma.common.len().saturating_sub(1); // spaces between icons
let desc_len = ma.common[0].description.len();
icons_width + sep_width + 1 + desc_len
};
let content_width = main_width.max(common_width);
let content_height =
ma.actions.len() + if matooltip_coordinates function · rust · L205-L248 (44 LOC)src/tooltip.rs
fn tooltip_coordinates(
ma: &ModeActions,
tabs: &[TabInfo],
status_bar_enabled: bool,
position: &str,
border: bool,
) -> FloatingPaneCoordinates {
let (rows, cols) = tabs
.iter()
.find(|t| t.active)
.map(|t| (t.display_area_rows, t.display_area_columns))
.unwrap_or((24, 80));
let (height, width) = tooltip_dimensions(ma, border);
let hud_height = if status_bar_enabled { 1 } else { 0 };
let w = width.min(cols);
let h = height.min(rows.saturating_sub(hud_height));
let (x, y) = match position {
"bottom-left" => {
(0, rows.saturating_sub(hud_height + h))
}
"top-right" => {
(cols.saturating_sub(w), 0)
}
"top-left" => {
(0, 0)
}
// "bottom-right" (default)
_ => {
(cols.saturating_sub(w), rows.saturating_sub(hud_height + h))
}
};
FloatingPaneCoordinates::new(
Some(format!("{}", x)),‹ prevpage 2 / 2