mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: store pwd with save/restore state
This commit is contained in:
@ -141,6 +141,10 @@ extension Ghostty {
|
|||||||
|
|
||||||
// MARK: - Codable
|
// MARK: - Codable
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case pwd
|
||||||
|
}
|
||||||
|
|
||||||
required convenience init(from decoder: Decoder) throws {
|
required convenience init(from decoder: Decoder) throws {
|
||||||
// Decoding uses the global Ghostty app
|
// Decoding uses the global Ghostty app
|
||||||
guard let del = NSApplication.shared.delegate,
|
guard let del = NSApplication.shared.delegate,
|
||||||
@ -149,12 +153,16 @@ extension Ghostty {
|
|||||||
throw TerminalRestoreError.delegateInvalid
|
throw TerminalRestoreError.delegateInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
self.init(app, nil)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
var config = SurfaceConfiguration()
|
||||||
|
config.workingDirectory = try container.decode(String?.self, forKey: .pwd)
|
||||||
|
|
||||||
|
self.init(app, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func encode(to encoder: Encoder) throws {
|
func encode(to encoder: Encoder) throws {
|
||||||
// We don't currently encode anything, but in the future we will
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
// want to encode pwd, etc...
|
try container.encode(surface.pwd, forKey: .pwd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,6 +283,17 @@ extension Ghostty {
|
|||||||
return ghostty_surface_needs_confirm_quit(surface)
|
return ghostty_surface_needs_confirm_quit(surface)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the pwd of the surface if it has one.
|
||||||
|
var pwd: String? {
|
||||||
|
guard let surface = self.surface else { return nil }
|
||||||
|
let v = String(unsafeUninitializedCapacity: 1024) {
|
||||||
|
Int(ghostty_surface_pwd(surface, $0.baseAddress, UInt($0.count)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v.count == 0) { return nil }
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the inspector instance for this surface, or nil if the
|
// Returns the inspector instance for this surface, or nil if the
|
||||||
// surface has been closed.
|
// surface has been closed.
|
||||||
var inspector: ghostty_inspector_t? {
|
var inspector: ghostty_inspector_t? {
|
||||||
|
Reference in New Issue
Block a user