adds schema view and schema generating command
This commit is contained in:
@@ -2,7 +2,6 @@ import AppKit
|
||||
import HelderCore
|
||||
import SwiftUI
|
||||
|
||||
/// The real git commands and their output, then a `$ git` input line. A click that selects nothing focuses the input.
|
||||
/// The real git commands and their output, then a `$ git` input line. A click that selects nothing focuses the input.
|
||||
struct GitConsolePanel: View {
|
||||
let model: WorkspaceModel
|
||||
@@ -14,13 +13,17 @@ struct GitConsolePanel: View {
|
||||
header
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
// First pick of the height: the log takes what its lines need, the input sits right under it.
|
||||
ConsoleLogView(entries: store.lines, onPlainClick: { focusTick += 1 })
|
||||
ConsoleLogView(entries: store.lines.map { ConsoleLogLine(id: $0.id, text: $0.line.text, color: Palette.console($0.line.kind)) },
|
||||
onPlainClick: { focusTick += 1 })
|
||||
.layoutPriority(1)
|
||||
// An AppKit field has no text baseline for SwiftUI, so the row centres instead.
|
||||
HStack(alignment: .center, spacing: 8) {
|
||||
Text("$ git").typeRole(Typography.console).foregroundStyle(Palette.gitNew).lineLimit(1).fixedSize()
|
||||
ConsoleInputField(
|
||||
text: Binding(get: { store.consoleInput }, set: { store.consoleInput = $0 }),
|
||||
placeholder: "status · add -A · commit -m \"…\" · push · pull · log",
|
||||
role: Typography.console,
|
||||
makeEditor: { GitConsoleFieldEditor() },
|
||||
focusTick: focusTick,
|
||||
onSubmit: { model.perform(.submitConsoleInput) },
|
||||
onUp: { store.recallPreviousInput() }
|
||||
@@ -79,11 +82,18 @@ private struct EraserButton: View {
|
||||
|
||||
// MARK: Log
|
||||
|
||||
/// One console line as the log draws it; the id stays put while older lines drop off the top.
|
||||
struct ConsoleLogLine: Equatable {
|
||||
let id: Int
|
||||
let text: String
|
||||
let color: Color
|
||||
}
|
||||
|
||||
/// A read-only, selectable text view of the console lines; it follows the newest line.
|
||||
/// Its height is measured in `sizeThatFits`, so the input row follows the last line in the same layout pass.
|
||||
private struct ConsoleLogView: NSViewRepresentable {
|
||||
let entries: [GitConsoleEntry]
|
||||
let onPlainClick: () -> Void
|
||||
struct ConsoleLogView: NSViewRepresentable {
|
||||
let entries: [ConsoleLogLine]
|
||||
var onPlainClick: () -> Void = {}
|
||||
|
||||
func makeCoordinator() -> Coordinator { Coordinator() }
|
||||
|
||||
@@ -144,7 +154,7 @@ private struct ConsoleLogView: NSViewRepresentable {
|
||||
private var measured: (width: CGFloat, height: CGFloat)?
|
||||
|
||||
/// Rebuilt only when lines were added or dropped, since one console holds up to 400 of them.
|
||||
func text(for entries: [GitConsoleEntry]) -> NSAttributedString {
|
||||
func text(for entries: [ConsoleLogLine]) -> NSAttributedString {
|
||||
let next = Signature(count: entries.count, first: entries.first?.id, last: entries.last?.id)
|
||||
if next != signature {
|
||||
signature = next
|
||||
@@ -154,7 +164,7 @@ private struct ConsoleLogView: NSViewRepresentable {
|
||||
return cached
|
||||
}
|
||||
|
||||
func height(of entries: [GitConsoleEntry], width: CGFloat) -> CGFloat {
|
||||
func height(of entries: [ConsoleLogLine], width: CGFloat) -> CGFloat {
|
||||
let text = text(for: entries)
|
||||
if let measured, measured.width == width { return measured.height }
|
||||
let storage = NSTextStorage(attributedString: text)
|
||||
@@ -169,7 +179,7 @@ private struct ConsoleLogView: NSViewRepresentable {
|
||||
return height
|
||||
}
|
||||
|
||||
private static func build(_ entries: [GitConsoleEntry]) -> NSAttributedString {
|
||||
private static func build(_ entries: [ConsoleLogLine]) -> NSAttributedString {
|
||||
let role = Typography.console
|
||||
let paragraph = NSMutableParagraphStyle()
|
||||
paragraph.minimumLineHeight = role.lineHeight ?? 19.2
|
||||
@@ -181,9 +191,9 @@ private struct ConsoleLogView: NSViewRepresentable {
|
||||
let spare = paragraph.maximumLineHeight - NSLayoutManager().defaultLineHeight(for: role.nsFont)
|
||||
let out = NSMutableAttributedString()
|
||||
for (index, entry) in entries.enumerated() {
|
||||
let line = entry.line.text + (index == entries.count - 1 ? "" : "\n")
|
||||
let line = entry.text + (index == entries.count - 1 ? "" : "\n")
|
||||
out.append(NSAttributedString(string: line, attributes: [
|
||||
.font: role.nsFont, .foregroundColor: NSColor(Palette.console(entry.line.kind)), .paragraphStyle: paragraph,
|
||||
.font: role.nsFont, .foregroundColor: NSColor(entry.color), .paragraphStyle: paragraph,
|
||||
.baselineOffset: max(0, spare / 2),
|
||||
]))
|
||||
}
|
||||
@@ -193,7 +203,7 @@ private struct ConsoleLogView: NSViewRepresentable {
|
||||
}
|
||||
|
||||
/// Grows with each new line; every resize lands on the newest line.
|
||||
private final class ConsoleLogScrollView: NSScrollView {
|
||||
final class ConsoleLogScrollView: NSScrollView {
|
||||
override func setFrameSize(_ newSize: NSSize) {
|
||||
let grew = newSize.height != frame.height
|
||||
super.setFrameSize(newSize)
|
||||
@@ -202,7 +212,7 @@ private final class ConsoleLogScrollView: NSScrollView {
|
||||
}
|
||||
|
||||
/// A click that leaves no selection hands the keyboard to the input line.
|
||||
private final class ConsoleLogTextView: PointerBoundTextView {
|
||||
final class ConsoleLogTextView: PointerBoundTextView {
|
||||
var onPlainClick: () -> Void = {}
|
||||
|
||||
override func mouseDown(with event: NSEvent) {
|
||||
@@ -213,19 +223,26 @@ private final class ConsoleLogTextView: PointerBoundTextView {
|
||||
|
||||
// MARK: Input
|
||||
|
||||
/// The borderless input after `$ git`: ↵ runs it, ↑ recalls the last command. It never takes focus on its own.
|
||||
private struct ConsoleInputField: NSViewRepresentable {
|
||||
/// A borderless one-line input: the Git console's `$ git` line and the Schema table search.
|
||||
/// ↵ submits and ↑ recalls; it takes focus only when `focusTick` moves.
|
||||
struct ConsoleInputField: NSViewRepresentable {
|
||||
@Binding var text: String
|
||||
let focusTick: Int
|
||||
let placeholder: String
|
||||
let role: TypeRole
|
||||
/// The field editor's class tells the key router which field holds the keyboard.
|
||||
let makeEditor: () -> PointerBoundTextView
|
||||
var focusTick = 0
|
||||
let onSubmit: () -> Void
|
||||
let onUp: () -> Void
|
||||
var onUp: () -> Void = {}
|
||||
|
||||
func makeCoordinator() -> Coordinator { Coordinator(self) }
|
||||
|
||||
func makeNSView(context: Context) -> ConsoleFieldBox {
|
||||
let font = Typography.console.nsFont
|
||||
let font = role.nsFont
|
||||
let field = NSTextField()
|
||||
field.cell = ConsoleFieldCell(textCell: "")
|
||||
let cell = ConsoleFieldCell(textCell: "")
|
||||
cell.makeEditor = makeEditor
|
||||
field.cell = cell
|
||||
field.isBordered = false
|
||||
field.isEditable = true
|
||||
field.isSelectable = true
|
||||
@@ -234,7 +251,7 @@ private struct ConsoleInputField: NSViewRepresentable {
|
||||
field.font = font
|
||||
field.textColor = NSColor(hex: 0xF4F5F4)
|
||||
field.placeholderAttributedString = NSAttributedString(
|
||||
string: "status · add -A · commit -m \"…\" · push · pull · log",
|
||||
string: placeholder,
|
||||
attributes: [.foregroundColor: NSColor(hex: 0x6C7783), .font: font]
|
||||
)
|
||||
field.stringValue = text
|
||||
@@ -291,7 +308,7 @@ private struct ConsoleInputField: NSViewRepresentable {
|
||||
}
|
||||
|
||||
/// The box around the console input: it takes the I-beam on the policy's terms and focuses the field on a click.
|
||||
private final class ConsoleFieldBox: NSView, PointerTextTarget {
|
||||
final class ConsoleFieldBox: NSView, PointerTextTarget {
|
||||
let field: NSTextField
|
||||
var pointerLayer = PointerLayer.overlay {
|
||||
didSet { if pointerLayer != oldValue { PointerPolicy.setNeedsRefresh(in: window) } }
|
||||
@@ -362,9 +379,10 @@ private final class ConsoleFieldCell: NSTextFieldCell {
|
||||
var pointerLayer = PointerLayer.overlay {
|
||||
didSet { editor.pointerLayer = pointerLayer }
|
||||
}
|
||||
var makeEditor: () -> PointerBoundTextView = { PointerBoundTextView() }
|
||||
|
||||
private lazy var editor: GitConsoleFieldEditor = {
|
||||
let editor = GitConsoleFieldEditor()
|
||||
private lazy var editor: PointerBoundTextView = {
|
||||
let editor = makeEditor()
|
||||
editor.isFieldEditor = true
|
||||
editor.pointerLayer = pointerLayer
|
||||
editor.insertionPointColor = NSColor(hex: 0xE8913A)
|
||||
|
||||
Reference in New Issue
Block a user