Skip to content
16 changes: 16 additions & 0 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
2B7AC06B282452FB0082A5B8 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2B7AC06A282452FB0082A5B8 /* Media.xcassets */; };
2BE487EF28245162003F3F64 /* FinderSync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE487EE28245162003F3F64 /* FinderSync.swift */; };
2BE487F428245162003F3F64 /* OpenWithCodeEdit.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 2BE487EC28245162003F3F64 /* OpenWithCodeEdit.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
3E0196732A3921AC002648D8 /* codeedit_shell_integration.zsh in Resources */ = {isa = PBXBuildFile; fileRef = 3E0196722A3921AC002648D8 /* codeedit_shell_integration.zsh */; };
3E01967A2A392B45002648D8 /* codeedit_shell_integration.bash in Resources */ = {isa = PBXBuildFile; fileRef = 3E0196792A392B45002648D8 /* codeedit_shell_integration.bash */; };
474397C52893AC4B00518C8C /* codeedit-midnight.json in Resources */ = {isa = PBXBuildFile; fileRef = 474397C42893AC4B00518C8C /* codeedit-midnight.json */; };
4E7F066629602E7B00BB3C12 /* CodeEditSplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E7F066529602E7B00BB3C12 /* CodeEditSplitViewController.swift */; };
4EE96ECB2960565E00FFBEA8 /* DocumentsUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE96ECA2960565E00FFBEA8 /* DocumentsUnitTests.swift */; };
Expand Down Expand Up @@ -517,6 +519,8 @@
2BE487EC28245162003F3F64 /* OpenWithCodeEdit.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OpenWithCodeEdit.appex; sourceTree = BUILT_PRODUCTS_DIR; };
2BE487EE28245162003F3F64 /* FinderSync.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinderSync.swift; sourceTree = "<group>"; };
2BE487F028245162003F3F64 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3E0196722A3921AC002648D8 /* codeedit_shell_integration.zsh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = codeedit_shell_integration.zsh; sourceTree = "<group>"; };
3E0196792A392B45002648D8 /* codeedit_shell_integration.bash */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = codeedit_shell_integration.bash; sourceTree = "<group>"; };
474397C42893AC4B00518C8C /* codeedit-midnight.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "codeedit-midnight.json"; sourceTree = "<group>"; };
4E7F066529602E7B00BB3C12 /* CodeEditSplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeEditSplitViewController.swift; sourceTree = "<group>"; };
4EE96ECA2960565E00FFBEA8 /* DocumentsUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentsUnitTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1099,6 +1103,15 @@
path = OpenWithCodeEdit;
sourceTree = "<group>";
};
3E0196712A392170002648D8 /* ShellIntegration */ = {
isa = PBXGroup;
children = (
3E0196792A392B45002648D8 /* codeedit_shell_integration.bash */,
3E0196722A3921AC002648D8 /* codeedit_shell_integration.zsh */,
);
path = ShellIntegration;
sourceTree = "<group>";
};
4EE96EC82960562000FFBEA8 /* Documents */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2217,6 +2230,7 @@
B658FB2E27DA9E0F00EA4DBD /* CodeEdit */ = {
isa = PBXGroup;
children = (
3E0196712A392170002648D8 /* ShellIntegration */,
5831E3C52933E6CB00D5A6D2 /* Features */,
D7211D4427E066D4008F2ED7 /* Localization */,
B658FB3527DA9E1000EA4DBD /* Preview Content */,
Expand Down Expand Up @@ -2594,8 +2608,10 @@
283BDCBD2972EEBD002AFF81 /* Package.resolved in Resources */,
B658FB3727DA9E1000EA4DBD /* Preview Assets.xcassets in Resources */,
28A51006281701B40087B0CC /* codeedit-github-dark.json in Resources */,
3E0196732A3921AC002648D8 /* codeedit_shell_integration.zsh in Resources */,
28F43DE029738792008BBA45 /* codeedit-solarized-dark.json in Resources */,
58A5DFA529339F6400D1BD5D /* default_keybindings.json in Resources */,
3E01967A2A392B45002648D8 /* codeedit_shell_integration.bash in Resources */,
28A51002281673530087B0CC /* codeedit-xcode-light.json in Resources */,
28A51005281701B40087B0CC /* codeedit-github-light.json in Resources */,
D7211D4727E06BFE008F2ED7 /* Localizable.strings in Resources */,
Expand Down
16 changes: 15 additions & 1 deletion CodeEdit/Features/DebugArea/Views/DebugAreaTerminalTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,22 @@ struct DebugAreaTerminalTab: View {
private var isFocused: Bool

var body: some View {
var terminalTitle = Binding<String>(
get: {
self.terminal.title
}, set: {
if $0.trimmingCharacters(in: .whitespaces) == "" && !isFocused {
self.terminal.title = self.terminal.terminalTitle
self.terminal.customTitle = false
} else {
self.terminal.title = $0
self.terminal.customTitle = true
}
}
)

Label {
TextField("Name", text: $terminal.title)
TextField("Name", text: terminalTitle)
.focused($isFocused)
.padding(.leading, -8)
.background {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ struct DebugAreaTerminal: Identifiable, Equatable {
var id: UUID
var url: URL?
var title: String
var terminalTitle: String
var shell: String
var customTitle: Bool

init(id: UUID, url: URL, title: String, shell: String) {
self.id = id
self.title = title
self.terminalTitle = title
self.url = url
self.shell = shell
self.customTitle = false
}
}

Expand Down Expand Up @@ -107,7 +111,10 @@ struct DebugAreaTerminalView: View {
title: String? = nil
) {
if let newTitle = title {
terminal.title = newTitle
if !terminal.customTitle {
terminal.title = newTitle
}
terminal.terminalTitle = newTitle
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ extension TerminalEmulatorView {
@State
private var url: URL

init(url: URL) {
public var onTitleChange: (_ title: String) -> Void

init(url: URL, onTitleChange: @escaping (_ title: String) -> Void) {
self._url = .init(wrappedValue: url)
self.onTitleChange = onTitleChange
super.init()
}

func hostCurrentDirectoryUpdate(source: TerminalView, directory: String?) {}

func sizeChanged(source: LocalProcessTerminalView, newCols: Int, newRows: Int) {}

func setTerminalTitle(source: LocalProcessTerminalView, title: String) {}
func setTerminalTitle(source: LocalProcessTerminalView, title: String) {
onTitleChange(title)
}

func processTerminated(source: TerminalView, exitCode: Int32?) {
guard let exitCode else {
Expand Down
17 changes: 15 additions & 2 deletions CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ struct TerminalEmulatorView: NSViewRepresentable {
}
}

private func setupShellTitle(shell: String) {
if let shellSetupScript = Bundle.main.url(forResource: "codeedit_shell_integration", withExtension: shell) {
let scriptPath = (shellSetupScript.absoluteString[7..<shellSetupScript.absoluteString.count]) ?? ""
terminal.send(txt: "source \(scriptPath)\n")
}

terminal.send(txt: "clear\n")
}

private func getTerminalCursor() -> CursorStyle {
let blink = terminalSettings.cursorBlink
switch terminalSettings.cursorStyle {
Expand Down Expand Up @@ -195,7 +204,9 @@ struct TerminalEmulatorView: NSViewRepresentable {
terminal.getTerminal().silentLog = true
if TerminalEmulatorView.lastTerminal[url.path] == nil {
let shell = getShell()
let shellIdiom = "-" + NSString(string: shell).lastPathComponent
let shellName = NSString(string: shell).lastPathComponent
onTitleChange(shellName)
let shellIdiom = "-" + shellName

// changes working directory to project root
// TODO: Get rid of FileManager shared instance to prevent problems
Expand All @@ -214,6 +225,8 @@ struct TerminalEmulatorView: NSViewRepresentable {
terminal.cursorStyleChanged(source: terminal.getTerminal(), newStyle: getTerminalCursor())
terminal.layer?.backgroundColor = .clear
terminal.optionAsMetaKey = optionAsMeta

setupShellTitle(shell: shellName)
}
terminal.appearance = colorAppearance
scroller?.isHidden = true
Expand Down Expand Up @@ -251,6 +264,6 @@ struct TerminalEmulatorView: NSViewRepresentable {
}

func makeCoordinator() -> Coordinator {
Coordinator(url: url)
Coordinator(url: url, onTitleChange: onTitleChange)
}
}
Loading