Added support for powershell on windows and linux, information if powershell is not installed and prevents running that profile
This commit is contained in:
1 parent
7260e2411f
commit
c05dc3f9f5
3 files changed
+237
-41
No files matched your search
+90
-27
@@ -9032,27 +9032,32 @@ fn profile_folder_row<'a>(
|
||||
folder: index,
|
||||
profile: profile_index,
|
||||
});
|
||||
let unavailable = profile_unavailable_reason(profile.kind);
|
||||
let name_color = if profile.hidden {
|
||||
hidden_profile_color
|
||||
} else {
|
||||
visible_profile_color
|
||||
};
|
||||
let profile_row = button(
|
||||
row![
|
||||
profile_glyph(profile.kind, profile.glyph_color),
|
||||
text(profile.name.as_str()).size(13).color(name_color)
|
||||
]
|
||||
.spacing(8)
|
||||
.align_y(Alignment::Center),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.padding(Padding {
|
||||
top: 4.0,
|
||||
right: 26.0,
|
||||
bottom: 4.0,
|
||||
left: if show_checks { 0.0 } else { 26.0 + indent },
|
||||
})
|
||||
.style(move |theme, status| theme::selectable_row(theme, status, profile_selected));
|
||||
let mut label = row![
|
||||
profile_glyph(profile.kind, profile.glyph_color),
|
||||
text(profile.name.as_str()).size(13).color(name_color)
|
||||
]
|
||||
.spacing(8)
|
||||
.align_y(Alignment::Center);
|
||||
|
||||
if unavailable.is_some() {
|
||||
label = label.push(text("⚠\u{fe0e}").size(12).color(theme::DANGER));
|
||||
}
|
||||
|
||||
let profile_row = button(label)
|
||||
.width(Length::Fill)
|
||||
.padding(Padding {
|
||||
top: 4.0,
|
||||
right: 26.0,
|
||||
bottom: 4.0,
|
||||
left: if show_checks { 0.0 } else { 26.0 + indent },
|
||||
})
|
||||
.style(move |theme, status| theme::selectable_row(theme, status, profile_selected));
|
||||
let press = if show_checks {
|
||||
Message::ProfilePressed {
|
||||
window,
|
||||
@@ -9093,6 +9098,17 @@ fn profile_folder_row<'a>(
|
||||
settings: show_checks,
|
||||
});
|
||||
|
||||
let profile_row: Element<'_, Message> = if let Some(reason) = unavailable {
|
||||
tooltip(
|
||||
profile_row,
|
||||
container(text(reason).size(11)).padding(4),
|
||||
tooltip::Position::FollowCursor,
|
||||
)
|
||||
.into()
|
||||
} else {
|
||||
profile_row.into()
|
||||
};
|
||||
|
||||
if show_checks {
|
||||
let profile_checkbox =
|
||||
container(checkbox(profile_checked).size(16).on_toggle(move |_| {
|
||||
@@ -9788,15 +9804,21 @@ fn tab_scroll_limits(state: &Moorly, window: window::Id) -> (bool, bool) {
|
||||
const TERMINAL_FOOTER_HEIGHT: f32 = 38.0;
|
||||
|
||||
/// Local profile kinds that can start a shell on this platform. PowerShell is
|
||||
/// a Windows shell; SSH keeps its existing path.
|
||||
/// resolved at runtime so profiles stay portable across operating systems; SSH
|
||||
/// keeps its existing path.
|
||||
fn local_shell(kind: ProfileKind) -> Option<terminal::Shell> {
|
||||
match kind {
|
||||
ProfileKind::Terminal => Some(terminal::Shell::Default),
|
||||
ProfileKind::PowerShell if cfg!(windows) => Some(terminal::Shell::PowerShell),
|
||||
_ => None,
|
||||
ProfileKind::PowerShell => Some(terminal::Shell::PowerShell),
|
||||
ProfileKind::Ssh => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Why a local profile cannot start on this system, if it cannot.
|
||||
fn profile_unavailable_reason(kind: ProfileKind) -> Option<String> {
|
||||
local_shell(kind)?.unavailable_reason()
|
||||
}
|
||||
|
||||
/// Starts a local terminal from a profile, either in the current window or in
|
||||
/// a fresh one. SSH profiles keep their existing (not yet implemented) path.
|
||||
fn run_profile(
|
||||
@@ -9826,6 +9848,14 @@ fn run_profile(
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
if let Some(reason) = shell.unavailable_reason() {
|
||||
state.notifications.add(
|
||||
notifications::Notification::new(notifications::NotificationKind::Warning, reason)
|
||||
.title(format!("{} unavailable", profile.kind.label())),
|
||||
);
|
||||
return Task::none();
|
||||
}
|
||||
|
||||
let (start_dir, warning) = profile_start_directory(&profile);
|
||||
if let Some(warning) = warning {
|
||||
state.notifications.add(
|
||||
@@ -10047,6 +10077,14 @@ fn restart_terminal(state: &mut Moorly, id: u32) {
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(reason) = shell.unavailable_reason() {
|
||||
state.notifications.add(
|
||||
notifications::Notification::new(notifications::NotificationKind::Warning, reason)
|
||||
.title(format!("{} unavailable", profile.kind.label())),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
match terminal::Session::spawn_with(&start_dir, rows, cols, shell) {
|
||||
Ok(session) => {
|
||||
if let Some(terminal) = state.terminal_sessions.get_mut(&id) {
|
||||
@@ -12599,15 +12637,40 @@ mod tests {
|
||||
|
||||
assert_eq!(local_shell(ProfileKind::Terminal), Some(Shell::Default));
|
||||
assert_eq!(local_shell(ProfileKind::Ssh), None);
|
||||
assert_eq!(
|
||||
local_shell(ProfileKind::PowerShell),
|
||||
Some(Shell::PowerShell)
|
||||
);
|
||||
|
||||
if cfg!(windows) {
|
||||
assert_eq!(
|
||||
local_shell(ProfileKind::PowerShell),
|
||||
Some(Shell::PowerShell)
|
||||
);
|
||||
} else {
|
||||
assert_eq!(local_shell(ProfileKind::PowerShell), None);
|
||||
}
|
||||
// Terminal profiles never depend on an optional executable.
|
||||
assert_eq!(
|
||||
super::profile_unavailable_reason(ProfileKind::Terminal),
|
||||
None
|
||||
);
|
||||
assert_eq!(super::profile_unavailable_reason(ProfileKind::Ssh), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn powershell_profiles_round_trip_through_toml_on_every_platform() {
|
||||
use super::{ProfileFile, ProfileKind};
|
||||
|
||||
let text = r#"
|
||||
name = "Pwsh"
|
||||
parent_id = "folder-id"
|
||||
kind = "powershell"
|
||||
session_end = "reconnect"
|
||||
start_path = "/tmp"
|
||||
"#;
|
||||
let file: ProfileFile = toml::from_str(text).unwrap();
|
||||
let profile = file.into_profile();
|
||||
|
||||
assert_eq!(profile.kind, ProfileKind::PowerShell);
|
||||
assert_eq!(profile.session_end, super::SessionEnd::Reconnect);
|
||||
|
||||
let encoded = toml::to_string(&ProfileFile::from_profile(&profile, "Work")).unwrap();
|
||||
assert!(encoded.contains("kind = \"powershell\""));
|
||||
assert!(encoded.contains("start_path = \"/tmp\""));
|
||||
assert!(!encoded.contains("unavailable"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user