mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-30 12:27:57 +00:00
core: change apprt action to enum value instead of a new one
This commit is contained in:
@@ -127,6 +127,20 @@ extension Ghostty.Action {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum PromptTitle {
|
||||
case surface
|
||||
case tab
|
||||
|
||||
init(_ c: ghostty_action_prompt_title_e) {
|
||||
switch c {
|
||||
case GHOSTTY_PROMPT_TITLE_TAB:
|
||||
self = .tab
|
||||
default:
|
||||
self = .surface
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Putting the initializer in an extension preserves the automatic one.
|
||||
|
||||
@@ -523,10 +523,7 @@ extension Ghostty {
|
||||
setTitle(app, target: target, v: action.action.set_title)
|
||||
|
||||
case GHOSTTY_ACTION_PROMPT_TITLE:
|
||||
return promptTitle(app, target: target)
|
||||
|
||||
case GHOSTTY_ACTION_PROMPT_TAB_TITLE:
|
||||
return promptTabTitle(app, target: target)
|
||||
return promptTitle(app, target: target, v: action.action.prompt_title)
|
||||
|
||||
case GHOSTTY_ACTION_PWD:
|
||||
pwdChanged(app, target: target, v: action.action.pwd)
|
||||
@@ -1353,47 +1350,49 @@ extension Ghostty {
|
||||
|
||||
private static func promptTitle(
|
||||
_ app: ghostty_app_t,
|
||||
target: ghostty_target_s) -> Bool {
|
||||
switch (target.tag) {
|
||||
case GHOSTTY_TARGET_APP:
|
||||
Ghostty.logger.warning("set title prompt does nothing with an app target")
|
||||
return false
|
||||
target: ghostty_target_s,
|
||||
v: ghostty_action_prompt_title_e) -> Bool {
|
||||
let promptTitle = Action.PromptTitle(v)
|
||||
switch promptTitle {
|
||||
case .surface:
|
||||
switch (target.tag) {
|
||||
case GHOSTTY_TARGET_APP:
|
||||
Ghostty.logger.warning("set title prompt does nothing with an app target")
|
||||
return false
|
||||
|
||||
case GHOSTTY_TARGET_SURFACE:
|
||||
guard let surface = target.target.surface else { return false }
|
||||
guard let surfaceView = self.surfaceView(from: surface) else { return false }
|
||||
surfaceView.promptTitle()
|
||||
case GHOSTTY_TARGET_SURFACE:
|
||||
guard let surface = target.target.surface else { return false }
|
||||
guard let surfaceView = self.surfaceView(from: surface) else { return false }
|
||||
surfaceView.promptTitle()
|
||||
return true
|
||||
|
||||
default:
|
||||
assertionFailure()
|
||||
}
|
||||
default:
|
||||
assertionFailure()
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
case .tab:
|
||||
switch (target.tag) {
|
||||
case GHOSTTY_TARGET_APP:
|
||||
guard let window = NSApp.mainWindow ?? NSApp.keyWindow,
|
||||
let controller = window.windowController as? BaseTerminalController
|
||||
else { return false }
|
||||
controller.promptTabTitle()
|
||||
return true
|
||||
|
||||
private static func promptTabTitle(
|
||||
_ app: ghostty_app_t,
|
||||
target: ghostty_target_s) -> Bool {
|
||||
switch (target.tag) {
|
||||
case GHOSTTY_TARGET_APP:
|
||||
guard let window = NSApp.mainWindow ?? NSApp.keyWindow,
|
||||
let controller = window.windowController as? BaseTerminalController
|
||||
else { return false }
|
||||
controller.promptTabTitle()
|
||||
return true
|
||||
case GHOSTTY_TARGET_SURFACE:
|
||||
guard let surface = target.target.surface else { return false }
|
||||
guard let surfaceView = self.surfaceView(from: surface) else { return false }
|
||||
guard let window = surfaceView.window,
|
||||
let controller = window.windowController as? BaseTerminalController
|
||||
else { return false }
|
||||
controller.promptTabTitle()
|
||||
return true
|
||||
|
||||
case GHOSTTY_TARGET_SURFACE:
|
||||
guard let surface = target.target.surface else { return false }
|
||||
guard let surfaceView = self.surfaceView(from: surface) else { return false }
|
||||
guard let window = surfaceView.window,
|
||||
let controller = window.windowController as? BaseTerminalController
|
||||
else { return false }
|
||||
controller.promptTabTitle()
|
||||
return true
|
||||
|
||||
default:
|
||||
assertionFailure()
|
||||
return false
|
||||
default:
|
||||
assertionFailure()
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user