ghostty/macos/Sources/Features/Settings/ConfigurationErrorsView.swift
2023-09-11 15:13:02 -07:00

60 lines
2.0 KiB
Swift

import SwiftUI
struct ConfigurationErrorsView: View {
class Model: ObservableObject {
@Published var errors: [String] = []
}
@ObservedObject var model: Model
var body: some View {
VStack {
HStack {
Image(systemName: "exclamationmark.triangle.fill")
.foregroundColor(.yellow)
.font(.system(size: 52))
.padding()
.frame(alignment: .center)
Text("""
^[\(model.errors.count) error(s) were](inflect: true) found while loading the configuration. \
Please review the errors below and reload your configuration.
""")
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
}
GeometryReader { geo in
ScrollView {
VStack(alignment: .leading) {
ForEach(model.errors, id: \.self) { error in
Text(error)
.lineLimit(nil)
.font(.system(size: 12).monospaced())
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .topLeading)
}
Spacer()
}
.padding(.all)
.frame(minHeight: geo.size.height)
.background(Color.white)
}
}
HStack {
Spacer()
Button("Reload Configuration") { reloadConfig() }
.padding([.bottom, .trailing])
}
}
.frame(minWidth: 480, maxWidth: 960, minHeight: 270)
}
private func reloadConfig() {
guard let delegate = NSApplication.shared.delegate as? AppDelegate else { return }
delegate.reloadConfig(nil)
}
}