Skip to content

Commit

Permalink
Add tty working dir and hold
Browse files Browse the repository at this point in the history
  • Loading branch information
leb-kuchen authored and jackpot51 committed Apr 26, 2024
1 parent bf66f31 commit fa74407
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
3 changes: 3 additions & 0 deletions i18n/en/cosmic_term.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ tab-title-description = Override the default tab title
add-profile = Add profile
new-profile = New profile
make-default = Make default
working-directory = Working directory
hold = Hold
remain-open = Remain open after child process exits.
## Settings
settings = Settings
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ pub struct Profile {
pub syntax_theme_light: String,
#[serde(default)]
pub tab_title: String,
#[serde(default)]
pub working_directory: String,
#[serde(default)]
pub hold: bool,
}

impl Default for Profile {
Expand All @@ -198,6 +202,8 @@ impl Default for Profile {
syntax_theme_dark: COSMIC_THEME_DARK.to_string(),
syntax_theme_light: COSMIC_THEME_LIGHT.to_string(),
tab_title: String::new(),
working_directory: String::new(),
hold: true,
}
}
}
Expand Down
52 changes: 47 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ pub enum Message {
PasteValue(Option<segmented_button::Entity>, String),
ProfileCollapse(ProfileId),
ProfileCommand(ProfileId, String),
ProfileDirectory(ProfileId, String),
ProfileExpand(ProfileId),
ProfileHold(ProfileId, bool),
ProfileName(ProfileId, String),
ProfileNew,
ProfileOpen(ProfileId),
Expand Down Expand Up @@ -849,6 +851,16 @@ impl App {
])
.spacing(space_xxxs)
.into(),
widget::column::with_children(vec![
widget::text(fl!("working-directory")).into(),
widget::text_input("", &profile.working_directory)
.on_input(move |text| {
Message::ProfileDirectory(profile_id, text)
})
.into(),
])
.spacing(space_xxxs)
.into(),
widget::column::with_children(vec![
widget::text(fl!("tab-title")).into(),
widget::text_input("", &profile.tab_title)
Expand Down Expand Up @@ -899,11 +911,28 @@ impl App {
.add(
widget::settings::item::builder(fl!("make-default")).control(
widget::toggler(
"".to_string(),
None,
self.get_default_profile().is_some_and(|p| p == profile_id),
move |t| Message::UpdateDefaultProfile((t, profile_id)),
),
),
)
.add(
widget::row::with_children(vec![
widget::column::with_children(vec![
widget::text(fl!("hold")).into(),
widget::text::caption(fl!("remain-open")).into(),
])
.spacing(space_xxxs)
.into(),
widget::horizontal_space(Length::Fill).into(),
widget::toggler(None, profile.hold, move |t| {
Message::ProfileHold(profile_id, t)
})
.into(),
])
.align_items(Alignment::Center)
.padding([0, space_s]),
);

let padding = Padding {
Expand Down Expand Up @@ -1164,12 +1193,13 @@ impl App {
shell = Some(tty::Shell::new(command, args));
}
}
let working_directory = (!profile.working_directory.is_empty())
.then(|| profile.working_directory.clone().into());

let options = tty::Options {
shell,
//TODO: configurable working directory?
working_directory: None,
//TODO: configurable hold (keep open when child exits)?
hold: false,
working_directory,
hold: profile.hold,
env: HashMap::new(),
};
let tab_title_override = if !profile.tab_title.is_empty() {
Expand Down Expand Up @@ -1891,9 +1921,21 @@ impl Application for App {
return self.save_profiles();
}
}
Message::ProfileDirectory(profile_id, text) => {
if let Some(profile) = self.config.profiles.get_mut(&profile_id) {
profile.working_directory = text;
return self.save_profiles();
}
}
Message::ProfileExpand(profile_id) => {
self.profile_expanded = Some(profile_id);
}
Message::ProfileHold(profile_id, hold) => {
if let Some(profile) = self.config.profiles.get_mut(&profile_id) {
profile.hold = hold;
return self.save_profiles();
}
}
Message::ProfileName(profile_id, text) => {
if let Some(profile) = self.config.profiles.get_mut(&profile_id) {
profile.name = text;
Expand Down

0 comments on commit fa74407

Please sign in to comment.