forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(terminal): support selecting different profile #8487
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| import * as vscode from "vscode" | ||
|
|
||
| export interface TerminalProfile { | ||
| name: string | ||
| path?: string | ||
| args?: string[] | ||
| icon?: string | ||
| color?: string | ||
| env?: Record<string, string> | ||
| } | ||
|
|
||
| export interface TerminalProfileInfo { | ||
| name: string | ||
| displayName: string | ||
| shellPath?: string | ||
| isDefault?: boolean | ||
| } | ||
|
|
||
| export class TerminalProfileService { | ||
| /** | ||
| * Gets the current platform identifier for terminal profiles | ||
| */ | ||
| private static getPlatform(): string { | ||
| switch (process.platform) { | ||
| case "win32": | ||
| return "windows" | ||
| case "darwin": | ||
| return "osx" | ||
| case "linux": | ||
| return "linux" | ||
| default: | ||
| return "linux" | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets all available terminal profiles for the current platform | ||
| */ | ||
| public static getAvailableProfiles(): TerminalProfileInfo[] { | ||
| const platform = this.getPlatform() | ||
| const config = vscode.workspace.getConfiguration("terminal.integrated") | ||
|
|
||
| // Get profiles for the current platform | ||
| const profiles = config.get<Record<string, TerminalProfile>>(`profiles.${platform}`) || {} | ||
|
|
||
| // Get the default profile name | ||
| const defaultProfile = config.get<string>(`defaultProfile.${platform}`) | ||
|
|
||
| // Convert profiles to our format | ||
| const profileInfos: TerminalProfileInfo[] = Object.entries(profiles).map(([name, profile]) => ({ | ||
| name, | ||
| displayName: name, | ||
| shellPath: profile.path, | ||
| isDefault: name === defaultProfile, | ||
| })) | ||
|
|
||
| // If no profiles are configured, return an empty array | ||
| // VSCode will use its built-in defaults | ||
| return profileInfos | ||
| } | ||
|
|
||
| /** | ||
| * Gets the default profile for the current platform | ||
| */ | ||
| public static getDefaultProfile(): TerminalProfileInfo | undefined { | ||
| const platform = this.getPlatform() | ||
| const config = vscode.workspace.getConfiguration("terminal.integrated") | ||
|
|
||
| const defaultProfileName = config.get<string>(`defaultProfile.${platform}`) | ||
|
|
||
| if (defaultProfileName) { | ||
| const profiles = this.getAvailableProfiles() | ||
| return profiles.find((profile) => profile.name === defaultProfileName) | ||
| } | ||
|
|
||
| return undefined | ||
| } | ||
|
|
||
| /** | ||
| * Gets a specific profile by name | ||
| */ | ||
| public static getProfileByName(name: string): TerminalProfileInfo | undefined { | ||
| const profiles = this.getAvailableProfiles() | ||
| return profiles.find((profile) => profile.name === name) | ||
| } | ||
|
|
||
| /** | ||
| * Gets the shell path for a given profile name | ||
| * Returns undefined if profile doesn't exist or doesn't specify a path | ||
| */ | ||
| public static getShellPathForProfile(profileName: string): string | undefined { | ||
| if (!profileName) { | ||
| return undefined | ||
| } | ||
|
|
||
| // Check regular profiles | ||
| const profile = this.getProfileByName(profileName) | ||
| return profile?.shellPath | ||
| } | ||
|
|
||
| /** | ||
| * Gets the full profile configuration from terminal.integrated.profiles.{platform} | ||
| */ | ||
| public static getProfileConfiguration(profileName: string): Partial<vscode.TerminalOptions> | undefined { | ||
| if (!profileName) { | ||
| return undefined | ||
| } | ||
|
|
||
| const platform = this.getPlatform() | ||
| const config = vscode.workspace.getConfiguration("terminal.integrated") | ||
| const profiles = config.get<Record<string, TerminalProfile>>(`profiles.${platform}`) || {} | ||
|
|
||
| const profile = profiles[profileName] | ||
| if (!profile) { | ||
| return undefined | ||
| } | ||
|
|
||
| // Convert VSCode terminal profile to vscode.TerminalOptions | ||
| const terminalOptions: Partial<vscode.TerminalOptions> = {} | ||
|
|
||
| if (profile.path) { | ||
| terminalOptions.shellPath = profile.path | ||
| } | ||
|
|
||
| if (profile.args) { | ||
| terminalOptions.shellArgs = profile.args | ||
| } | ||
|
|
||
| if (profile.env) { | ||
| terminalOptions.env = profile.env | ||
| } | ||
|
|
||
| if (profile.icon) { | ||
| terminalOptions.iconPath = new vscode.ThemeIcon(profile.icon) | ||
| } | ||
|
|
||
| if (profile.color) { | ||
| terminalOptions.color = new vscode.ThemeColor(profile.color) | ||
| } | ||
|
|
||
| return terminalOptions | ||
| } | ||
|
|
||
| /** | ||
| * Gets the terminal options that Roo should use for terminals | ||
| * Priority: 1. User's preferred profile, 2. Default profile, 3. undefined (VSCode default) | ||
| */ | ||
| public static getTerminalOptionsForRoo(preferredProfile?: string): Partial<vscode.TerminalOptions> | undefined { | ||
| // 1. Check user's preferred profile | ||
| if (preferredProfile) { | ||
| const profileConfig = this.getProfileConfiguration(preferredProfile) | ||
| if (profileConfig) { | ||
| return profileConfig | ||
| } | ||
| } | ||
|
|
||
| // 2. Check default profile | ||
| const defaultProfile = this.getDefaultProfile() | ||
| if (defaultProfile) { | ||
| const profileConfig = this.getProfileConfiguration(defaultProfile.name) | ||
| if (profileConfig) { | ||
| return profileConfig | ||
| } | ||
| } | ||
|
|
||
| // 3. Let VSCode use its default | ||
| return undefined | ||
| } | ||
|
|
||
| /** | ||
| * Gets the shell path that Roo should use for terminals (backward compatibility) | ||
| * Priority: 1. User's preferred profile, 2. Default profile, 3. undefined (VSCode default) | ||
| */ | ||
| public static getShellPathForRoo(preferredProfile?: string): string | undefined { | ||
| const terminalOptions = this.getTerminalOptionsForRoo(preferredProfile) | ||
| return terminalOptions?.shellPath | ||
| } | ||
|
|
||
| /** | ||
| * Gets all profiles that should be shown in the UI | ||
| */ | ||
| public static getAllSelectableProfiles(): TerminalProfileInfo[] { | ||
| const profiles = this.getAvailableProfiles() | ||
|
|
||
| // Add a "Default" option that represents using VSCode's default behavior | ||
| profiles.unshift({ | ||
| name: "", | ||
| displayName: "Default (VSCode Default)", | ||
| isDefault: false, | ||
| }) | ||
|
|
||
| return profiles | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P3] Comment claims conditional override but code unconditionally sets values. The comment states "Keep our icon and name unless profile specifies otherwise" but lines 44-45 always override any profile-specified name/icon from the Object.assign on line 36. Either remove the "unless" clause from the comment or use conditional assignment like
terminalOptions.name = profileOptions.name ?? "Roo Code".Fix it with Roo Code or mention @roomote and request a fix.