Skip to content

Commit

Permalink
fix fg info when isn't necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Jan 11, 2025
1 parent a6e6ad1 commit 6497115
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 68 deletions.
2 changes: 2 additions & 0 deletions docs/docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ language: 'en'
- `COLUMNS`: current columns
- `LINES`: current lines
- So, for example if you have: `{{COLUMNS}}x{{LINES}}` would show something like `88x66`.
- Window title is now updated regardless the Navigation Mode.
- Performance: Background and foreground data are only retrieved if is asked (either color automation is enabled or `window.title` contains any request for it).
- Fixed: Nix build [#853](https://github.com/raphamorim/rio/pull/853).
- Support to `window.macos-use-shadow` (enable or disable shadow on MacOS).
- Support to `window.windows-corner-preference` (options: `Default`, `DoNotRound`,`Round` and `RoundSmall`).
Expand Down
47 changes: 19 additions & 28 deletions frontends/rioterm/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::ansi::CursorShape;
use crate::context::grid::ContextDimension;
use crate::context::grid::ContextGrid;
use crate::context::grid::Delta;
use crate::context::title::{update_title, ContextManagerTitles};
use crate::context::title::{
create_title_extra_from_context, update_title, ContextManagerTitles,
};
use crate::event::sync::FairMutex;
use crate::event::RioEvent;
use crate::ime::Ime;
Expand Down Expand Up @@ -128,7 +130,7 @@ pub struct ContextManagerConfig {
pub spawn_performer: bool,
pub use_current_path: bool,
pub is_native: bool,
pub should_update_titles: bool,
pub should_update_title_extra: bool,
pub split_color: [f32; 4],
pub title: rio_backend::config::title::Title,
}
Expand Down Expand Up @@ -198,7 +200,7 @@ pub fn create_mock_context<
},
spawn_performer: false,
is_native: false,
should_update_titles: false,
should_update_title_extra: false,
use_current_path: false,
..ContextManagerConfig::default()
};
Expand Down Expand Up @@ -369,11 +371,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
}
};

let titles = ContextManagerTitles::new(
0,
String::from("tab"),
ctx_config.working_dir.clone().unwrap_or_default(),
);
let titles = ContextManagerTitles::new(0, String::from("tab"), None);

// Sugarloaf has found errors and context need to notify it for the user
if let Some(errors) = sugarloaf_errors {
Expand Down Expand Up @@ -423,7 +421,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
},
spawn_performer: false,
is_native: false,
should_update_titles: false,
should_update_title_extra: false,
use_current_path: false,
..ContextManagerConfig::default()
};
Expand All @@ -437,7 +435,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
&config,
)?;

let titles = ContextManagerTitles::new(0, String::new(), String::new());
let titles = ContextManagerTitles::new(0, String::new(), None);

Ok(ContextManager {
current_index: 0,
Expand Down Expand Up @@ -643,10 +641,6 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
}

pub fn update_titles(&mut self) {
if !self.config.should_update_titles {
return;
}

let interval_time = Duration::from_secs(2);
if self
.titles
Expand All @@ -659,22 +653,20 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
for (i, context) in self.contexts.iter_mut().enumerate() {
let content = update_title(&self.config.title.content, context.current());

#[cfg(unix)]
let path = teletypewriter::foreground_process_path(
*context.current().main_fd,
context.current().shell_pid,
)
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_default();

#[cfg(not(unix))]
let path = String::default();

self.event_proxy
.send_event(RioEvent::Title(content.to_owned()), self.window_id);

id.push_str(&format!("{}{};", i, content));
self.titles.set_key_val(i, content, path);

if self.config.should_update_title_extra {
self.titles.set_key_val(
i,
content,
create_title_extra_from_context(context.current()),
);
} else {
self.titles.set_key_val(i, content, None);
}
}

self.titles.set_key(id);
Expand Down Expand Up @@ -909,8 +901,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
is_native: config.navigation.is_native(),
// When navigation is collapsed and does not contain any color rule
// does not make sense fetch for foreground process names
should_update_titles: !(config.navigation.is_collapsed_mode()
&& config.navigation.color_automation.is_empty()),
should_update_title_extra: !config.navigation.color_automation.is_empty(),
split_color: config.colors.split,
title: config.title,
};
Expand Down
51 changes: 34 additions & 17 deletions frontends/rioterm/src/context/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ use crate::context::Context;
use rustc_hash::FxHashMap;
use std::time::Instant;

pub struct ContextTitleExtra {
pub program: String,
pub path: String,
}

pub struct ContextTitle {
pub content: String,
pub current_path: String,
pub extra: Option<ContextTitleExtra>,
}

pub struct ContextManagerTitles {
Expand All @@ -17,17 +22,11 @@ impl ContextManagerTitles {
pub fn new(
idx: usize,
content: String,
current_path: String,
extra: Option<ContextTitleExtra>,
) -> ContextManagerTitles {
let key = format!("{}{};", idx, content);
let mut map = FxHashMap::default();
map.insert(
idx,
ContextTitle {
content,
current_path,
},
);
map.insert(idx, ContextTitle { content, extra });
ContextManagerTitles {
key,
titles: map,
Expand All @@ -36,14 +35,13 @@ impl ContextManagerTitles {
}

#[inline]
pub fn set_key_val(&mut self, idx: usize, content: String, current_path: String) {
self.titles.insert(
idx,
ContextTitle {
content,
current_path,
},
);
pub fn set_key_val(
&mut self,
idx: usize,
content: String,
extra: Option<ContextTitleExtra>,
) {
self.titles.insert(idx, ContextTitle { content, extra });
}

#[inline]
Expand All @@ -52,6 +50,25 @@ impl ContextManagerTitles {
}
}

pub fn create_title_extra_from_context<T: rio_backend::event::EventListener>(
context: &Context<T>,
) -> Option<ContextTitleExtra> {
#[cfg(unix)]
let path =
teletypewriter::foreground_process_path(*context.main_fd, context.shell_pid)
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_default();

#[cfg(not(unix))]
let path = String::default();

#[cfg(unix)]
let program =
teletypewriter::foreground_process_name(*context.main_fd, context.shell_pid);

Some(ContextTitleExtra { program, path })
}

// Possible options:

// - `TITLE`: terminal title via OSC sequences for setting terminal title
Expand Down
34 changes: 21 additions & 13 deletions frontends/rioterm/src/renderer/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,16 @@ impl ScreenNavigation {
}

if let Some(title) = titles.get(&i) {
if let Some(color_overwrite) = get_color_overwrite(
&self.color_automation,
&title.content,
&title.current_path,
) {
color = *color_overwrite;
if !self.color_automation.is_empty() {
if let Some(extra) = &title.extra {
if let Some(color_overwrite) = get_color_overwrite(
&self.color_automation,
&extra.program,
&extra.path,
) {
color = *color_overwrite;
}
}
}
}

Expand Down Expand Up @@ -222,13 +226,17 @@ impl ScreenNavigation {
if let Some(title) = titles.get(&i) {
name = title.content.to_owned();

if let Some(color_overwrite) = get_color_overwrite(
&self.color_automation,
&title.content,
&title.current_path,
) {
foreground_color = colors.tabs;
background_color = *color_overwrite;
if !self.color_automation.is_empty() {
if let Some(extra) = &title.extra {
if let Some(color_overwrite) = get_color_overwrite(
&self.color_automation,
&extra.program,
&extra.path,
) {
foreground_color = colors.tabs;
background_color = *color_overwrite;
}
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions frontends/rioterm/src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,9 @@ impl Screen<'_> {
#[cfg(not(target_os = "windows"))]
use_fork: config.use_fork,
is_native,
// When navigation is collapsed and does not contain any color rule
// does not make sense fetch for foreground process names
should_update_titles: !(is_collapsed
&& config.navigation.color_automation.is_empty()),
// When navigation does not contain any color rule
// does not make sense fetch for foreground process names/path
should_update_title_extra: !config.navigation.color_automation.is_empty(),
split_color: config.colors.split,
title: config.title.clone(),
};
Expand Down
2 changes: 1 addition & 1 deletion rio-window/src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ declare_class!(
unsafe { &*string }.to_string()
};

let is_control = string.chars().next().map_or(false, |c| c.is_control());
let is_control = string.chars().next().is_some_and(|c| c.is_control());

// Commit only if we have marked text.
if unsafe { self.hasMarkedText() } && self.is_ime_enabled() && !is_control {
Expand Down
2 changes: 1 addition & 1 deletion sugarloaf/src/font_introspector/text/lang_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub const LANG_BY_TAG3: [(u32, u32); 711] = [
];

#[rustfmt::skip]
pub const LANG_ENTRIES: [(&'static str, &'static str); 715] = [
pub static LANG_ENTRIES: [(&'static str, &'static str); 715] = [
("Abaza", "abq"), ("Abkhazian", "ab"), ("Acoli", "ach"), ("Achi", "acr"), ("Adyghe", "ady"), ("Afrikaans", "af"), ("Afar", "aa"), ("Qimant", "ahg"), ("Aiton", "aio"), ("Akan", "ak"), ("Swiss German", "gsw"), ("Northern Altai", "atv"), ("Southern Altai", "alt"), ("Amharic", "am"), ("Old English (ca. 450-1100)", "ang"), ("Arabic", "ar"), ("Aragonese", "an"),
("Aari", "aiw"), ("Marma", "rmz"), ("Rakhine", "rki"), ("Assamese", "as"), ("Asturian", "ast"), ("Tsetsaut", "txc"), ("Mattole", "mvb"), ("Wailaki", "wlk"), ("Coquille", "coq"), ("Chetco", "ctc"), ("Galice", "gce"), ("Tolowa", "tol"), ("Tututni", "tuu"), ("Kaska", "kkz"), ("Hupa", "hup"), ("Tagish", "tgx"), ("Ahtena", "aht"),
("Tanaina", "tfn"), ("Lower Tanana", "taa"), ("Upper Tanana", "tau"), ("Tanacross", "tcb"), ("Upper Kuskokwim", "kuu"), ("Southern Tutchone", "tce"), ("Northern Tutchone", "ttm"), ("Tahltan", "tht"), ("Koyukon", "koy"), ("Kato", "ktw"), ("Degexit'an", "ing"), ("Kiowa Apache", "apk"), ("Jicarilla Apache", "apj"), ("Lipan Apache", "apl"), ("Mescalero-Chiricahua Apache", "apm"), ("Western Apache", "apw"), ("Navajo", "nv"),
Expand Down
8 changes: 4 additions & 4 deletions sugarloaf/src/font_introspector/text/unicode_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ const RECORD_INDEX1: [u16; 6304] = [
];

#[rustfmt::skip]
const RECORD_INDEX2: [u16; 14744] = [
static RECORD_INDEX2: [u16; 14744] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 26, 27, 27,
27, 9, 14, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 16, 29, 17,
Expand Down Expand Up @@ -2685,7 +2685,7 @@ use self::{
};

#[rustfmt::skip]
pub const RECORDS: [Record; 2035] = [
pub static RECORDS: [Record; 2035] = [
r(32,C::Control,B::BasicLatin,S::Common,0,Bc::BN,Jt::U,Cb::CN,Wb::XX,Lb::CM,Uc::O,Mc::O), r(32,C::Control,B::BasicLatin,S::Common,0,Bc::S,Jt::U,Cb::CN,Wb::XX,Lb::BA,Uc::O,Mc::O),
r(32,C::Control,B::BasicLatin,S::Common,0,Bc::B,Jt::U,Cb::LF,Wb::LF,Lb::LF,Uc::O,Mc::O), r(32,C::Control,B::BasicLatin,S::Common,0,Bc::S,Jt::U,Cb::CN,Wb::NL,Lb::BK,Uc::O,Mc::O),
r(32,C::Control,B::BasicLatin,S::Common,0,Bc::WS,Jt::U,Cb::CN,Wb::NL,Lb::BK,Uc::O,Mc::O), r(32,C::Control,B::BasicLatin,S::Common,0,Bc::B,Jt::U,Cb::CR,Wb::CR,Lb::CR,Uc::O,Mc::O),
Expand Down Expand Up @@ -4761,7 +4761,7 @@ pub fn decompose_compat_index(x: usize) -> usize {
DECOMPOSE_COMPAT_INDEX2[index + offset] as usize
}
#[rustfmt::skip]
pub const DECOMPOSE: [u32; 5469] = [
pub static DECOMPOSE: [u32; 5469] = [
0, 255, 2, 65, 768, 2, 65, 769, 2, 65, 770, 2, 65, 771, 2, 65, 776, 2, 65, 778, 2, 67, 807, 2,
69, 768, 2, 69, 769, 2, 69, 770, 2, 69, 776, 2, 73, 768, 2, 73, 769, 2, 73, 770, 2, 73, 776, 2,
78, 771, 2, 79, 768, 2, 79, 769, 2, 79, 770, 2, 79, 771, 2, 79, 776, 2, 85, 768, 2, 85, 769, 2,
Expand Down Expand Up @@ -5043,7 +5043,7 @@ pub const DECOMPOSE: [u32; 5469] = [
];

#[rustfmt::skip]
pub const DECOMPOSE_COMPAT: [u32; 9307] = [
pub static DECOMPOSE_COMPAT: [u32; 9307] = [
0, 255, 1, 32, 2, 32, 776, 1, 97, 2, 32, 772, 1, 50, 1, 51, 2, 32, 769, 1, 956, 2, 32, 807, 1,
49, 1, 111, 3, 49, 8260, 52, 3, 49, 8260, 50, 3, 51, 8260, 52, 2, 73, 74, 2, 105, 106, 2, 76,
183, 2, 108, 183, 2, 700, 110, 1, 115, 3, 68, 90, 780, 3, 68, 122, 780, 3, 100, 122, 780, 2,
Expand Down

0 comments on commit 6497115

Please sign in to comment.