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)
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import SwiftUI
|
||||
|
||||
/// The Git view's icons, drawn on Lucide's 24-unit grid at stroke 1.75; the flag is a plain pennant.
|
||||
/// Icons with arcs Lucide draws as curves (cloud, eraser) use the nearest SF Symbol.
|
||||
/// The Git and Schema views' icons, drawn on Lucide's 24-unit grid at stroke 1.75; the flag is a plain pennant.
|
||||
/// Icons with arcs Lucide draws as curves (cloud, eraser, sparkle) use the nearest SF Symbol.
|
||||
enum GitIcon {
|
||||
case gitBranch, cloud, arrowDownToLine, arrowUpFromLine, minimize, chevronDown, chevronRight, eraser, check, flag
|
||||
case database, terminal, search, minus, plus, x, sparkle
|
||||
|
||||
fileprivate var symbol: String? {
|
||||
switch self {
|
||||
case .cloud: "cloud"
|
||||
case .eraser: "eraser"
|
||||
case .sparkle: "sparkle"
|
||||
default: nil
|
||||
}
|
||||
}
|
||||
@@ -49,7 +51,32 @@ enum GitIcon {
|
||||
case .flag:
|
||||
line((5, 22), (5, 3))
|
||||
line((5, 4), (19, 9), (5, 14))
|
||||
case .cloud, .eraser:
|
||||
case .database:
|
||||
path.addEllipse(in: CGRect(x: 3 * k, y: 2 * k, width: 18 * k, height: 6 * k))
|
||||
line((3, 5), (3, 19))
|
||||
line((21, 5), (21, 19))
|
||||
for y in [12.0, 19.0] {
|
||||
// A lower half-ellipse, 9 wide and 3 deep each side, as two Bézier quarters.
|
||||
let c = 0.5523
|
||||
path.move(to: p(3, y))
|
||||
path.addCurve(to: p(12, y + 3), control1: p(3, y + 3 * c), control2: p(12 - 9 * c, y + 3))
|
||||
path.addCurve(to: p(21, y), control1: p(12 + 9 * c, y + 3), control2: p(21, y + 3 * c))
|
||||
}
|
||||
case .terminal:
|
||||
line((4, 17), (10, 11), (4, 5))
|
||||
line((12, 19), (20, 19))
|
||||
case .search:
|
||||
path.addEllipse(in: CGRect(x: 3 * k, y: 3 * k, width: 16 * k, height: 16 * k))
|
||||
line((21, 21), (16.65, 16.65))
|
||||
case .minus:
|
||||
line((5, 12), (19, 12))
|
||||
case .plus:
|
||||
line((5, 12), (19, 12))
|
||||
line((12, 5), (12, 19))
|
||||
case .x:
|
||||
line((18, 6), (6, 18))
|
||||
line((6, 6), (18, 18))
|
||||
case .cloud, .eraser, .sparkle:
|
||||
break
|
||||
}
|
||||
return path
|
||||
|
||||
@@ -31,7 +31,7 @@ struct GitTopBar: View {
|
||||
}
|
||||
|
||||
/// A 28pt bordered button with an icon, a label and an amber mono count or key hint.
|
||||
private struct GitBarButton: View {
|
||||
struct GitBarButton: View {
|
||||
let icon: GitIcon
|
||||
let label: String
|
||||
let trailing: String?
|
||||
|
||||
Reference in New Issue
Block a user