mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-01 15:38:35 +00:00
macos: hook up paste protection delegate, cancel button
This commit is contained in:
@@ -1,18 +1,57 @@
|
||||
import SwiftUI
|
||||
|
||||
protocol PasteProtectionViewDelegate: AnyObject {
|
||||
func pasteProtectionComplete(_ action: PasteProtectionView.Action)
|
||||
}
|
||||
|
||||
struct PasteProtectionView: View {
|
||||
enum Action : String {
|
||||
case cancel
|
||||
case paste
|
||||
}
|
||||
|
||||
let contents: String
|
||||
weak var delegate: PasteProtectionViewDelegate? = nil
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Image("AppIconImage")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 128, height: 128)
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
Text("Oh, no. 😭").font(.title)
|
||||
Text("Something went fatally wrong.\nCheck the logs and restart Ghostty.")
|
||||
VStack {
|
||||
HStack {
|
||||
Image(systemName: "exclamationmark.triangle.fill")
|
||||
.foregroundColor(.yellow)
|
||||
.font(.system(size: 42))
|
||||
.padding()
|
||||
.frame(alignment: .center)
|
||||
|
||||
Text("Pasting this text to the terminal may be dangerous as it looks like " +
|
||||
"some commands may be executed.")
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding()
|
||||
}
|
||||
|
||||
TextEditor(text: .constant(contents))
|
||||
.disabled(true)
|
||||
.textSelection(.enabled)
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.padding(.all, 4)
|
||||
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Cancel") { onCancel() }
|
||||
.keyboardShortcut(.cancelAction)
|
||||
Button("Paste") { onPaste() }
|
||||
.keyboardShortcut(.defaultAction)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.bottom)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
private func onCancel() {
|
||||
AppDelegate.logger.warning("PASTE onCancel")
|
||||
delegate?.pasteProtectionComplete(.cancel)
|
||||
}
|
||||
|
||||
private func onPaste() {
|
||||
delegate?.pasteProtectionComplete(.paste)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user