Repository navigation
Settings: Font card with live preview, font gallery, and line height #15210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
teamleaderleo
wants to merge
11
commits into
main
Choose a base branch
from
terminal-font-card
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8fe58f5
Settings: Font card with live preview, font gallery, line height
teamleaderleo 2aedd3b
Settings: build the line height label without a localized format
teamleaderleo 134a719
Settings: UI test for the Font card preview and font gallery
teamleaderleo 86f5e72
Settings: match Ghostty's adjust-cell-height parsing, keep pixel unit…
teamleaderleo 9a3a5d8
Settings: widen the font button and drop the font list below it
teamleaderleo 6b4d75d
Settings: font strings for the remaining catalog locales; saturate pi…
teamleaderleo 7da97d8
Settings: walk the Font card in its UI test (hover, search, pick, lin…
teamleaderleo 9d545a5
Settings: read the line height stepper's own label in the Font card U…
teamleaderleo e8296c0
Settings: identify font list rows so the UI test doesn't also match t…
teamleaderleo b005102
Settings: expose the line height as the stepper's accessibility value
teamleaderleo d1a7642
fix: safely serialize large line height percentages
teamleaderleo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...oundation/Sources/CmuxFoundation/GhosttyTerminalOptions/GhosttyCellHeightAdjustment.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import Foundation | ||
|
|
||
| /// An `adjust-cell-height` value: extra line height added to the font's own, | ||
| /// as a percentage (`8%`, `12.5%`) or a number of device pixels (`2`). | ||
| /// Negative values tighten the lines. | ||
| public enum GhosttyCellHeightAdjustment: Equatable, Sendable { | ||
| case percent(Double) | ||
| case pixels(Int) | ||
|
|
||
| /// No adjustment, Ghostty's default. | ||
| public static let unadjusted = GhosttyCellHeightAdjustment.percent(0) | ||
|
|
||
| /// Parses Ghostty's `20%`, `-12.5%`, or `2` spelling. Like Ghostty, only | ||
| /// the ends of the value are trimmed, so `15 %` is invalid. | ||
| public init?(configValue: String) { | ||
| let value = configValue.trimmingCharacters(in: .whitespaces) | ||
| if value.hasSuffix("%") { | ||
| guard let percent = Double(value.dropLast()), percent.isFinite else { return nil } | ||
| self = .percent(percent) | ||
| } else if let pixels = Int(value) { | ||
| self = .pixels(pixels) | ||
| } else { | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| /// The adjustment one stepper step away: 2% for a percentage, 1 pixel | ||
| /// for a pixel value, so a value set in a config file keeps its unit. | ||
| public func stepped(by steps: Int) -> GhosttyCellHeightAdjustment { | ||
| switch self { | ||
| case .percent(let percent): return .percent((percent / 2).rounded() * 2 + Double(steps * 2)) | ||
| case .pixels(let pixels): | ||
| let (sum, overflow) = pixels.addingReportingOverflow(steps) | ||
| return .pixels(overflow ? (steps > 0 ? .max : .min) : sum) | ||
| } | ||
| } | ||
|
|
||
| /// Ghostty's spelling: `8%`, `12.5%`, or `2`. | ||
| public var configValue: String { | ||
| switch self { | ||
| case .percent(let percent): | ||
| if percent == percent.rounded(), let integer = Int(exactly: percent) { | ||
| return "\(integer)%" | ||
| } | ||
| return "\(percent)%" | ||
| case .pixels(let pixels): | ||
| return String(pixels) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Packages/macOS/CmuxSettingsUI/Sources/CmuxSettingsUI/Models/NSFont+TerminalFamily.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import AppKit | ||
|
|
||
| extension NSFont { | ||
| /// Ghostty's built-in font, used when no `font-family` is set. | ||
| static let ghosttyBuiltInFamily = "JetBrains Mono" | ||
|
|
||
| /// The regular face of `family` at `size`, for previewing a terminal font | ||
| /// choice. `nil` means Ghostty's built-in font, which is shown with the | ||
| /// installed JetBrains Mono when present and the system monospaced font | ||
| /// otherwise. A family with no regular face falls back to its first member. | ||
| static func terminalPreview(family: String?, size: CGFloat) -> NSFont { | ||
| let manager = NSFontManager.shared | ||
| let resolvedFamily = family ?? ghosttyBuiltInFamily | ||
| if let font = manager.font(withFamily: resolvedFamily, traits: [], weight: 5, size: size) { | ||
| return font | ||
| } | ||
| if let member = manager.availableMembers(ofFontFamily: resolvedFamily)?.first, | ||
| let name = member.first as? String, | ||
| let font = NSFont(name: name, size: size) { | ||
| return font | ||
| } | ||
| return .monospacedSystemFont(ofSize: size, weight: .regular) | ||
| } | ||
| } |
79 changes: 79 additions & 0 deletions
79
...ages/macOS/CmuxSettingsUI/Sources/CmuxSettingsUI/Models/TerminalGhosttyOptionsModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import CmuxFoundation | ||
| import Foundation | ||
| import Observation | ||
|
|
||
| /// The Ghostty option values Settings > Terminal shows, shared by the Font card | ||
| /// and the options card so an edit in one isn't undone by the other's refresh. | ||
| /// | ||
| /// Each edit shows right away, is written to cmux's Ghostty config after a | ||
| /// short pause, and is then checked against a re-read of the effective values. | ||
| @MainActor | ||
| @Observable | ||
| final class TerminalGhosttyOptionsModel { | ||
| /// Coalesces stepper autorepeat and quick clicks into one write and reload. | ||
| private static let writeDelay: Duration = .milliseconds(250) | ||
|
|
||
| @ObservationIgnored private let hostActions: SettingsHostActions | ||
| @ObservationIgnored private let tasks = MainActorTaskStore<GhosttyTerminalOptionKey>() | ||
| /// Changes shown optimistically whose write hasn't finished yet, reapplied | ||
| /// over each re-read so one row's refresh doesn't undo another row's edit. | ||
| @ObservationIgnored private var pendingChanges: [GhosttyTerminalOptionKey: GhosttyTerminalOptionChange] = [:] | ||
| @ObservationIgnored private var isLoading = false | ||
|
|
||
| private(set) var options = GhosttyTerminalOptions.defaults | ||
| private(set) var hasLoaded = false | ||
| /// Installed fixed-pitch families, sorted; empty until loaded. | ||
| private(set) var monospacedFamilies: [String] = [] | ||
| private(set) var saveFailed = false | ||
| /// Keys whose written value a later-loading config file overrides, with | ||
| /// that file's display path. | ||
| private(set) var overriddenKeys: [GhosttyTerminalOptionKey: String] = [:] | ||
|
|
||
| init(hostActions: SettingsHostActions) { | ||
| self.hostActions = hostActions | ||
| } | ||
|
|
||
| /// Reads the effective values and the installed monospaced families once. | ||
| func load() async { | ||
| guard !hasLoaded, !isLoading else { return } | ||
| isLoading = true | ||
| let families = Task.detached(priority: .utility) { MonospacedFontFamilies().load() } | ||
| options = await hostActions.terminalGhosttyOptions().options | ||
| hasLoaded = true | ||
| monospacedFamilies = await families.value | ||
| isLoading = false | ||
| } | ||
|
|
||
| /// Installed monospaced families, plus the configured family when it isn't | ||
| /// flagged fixed-pitch, so a picker always shows the current choice. | ||
| var fontFamilyChoices: [String] { | ||
| guard let current = options.fontFamily, !monospacedFamilies.contains(current) else { | ||
| return monospacedFamilies | ||
| } | ||
| return ([current] + monospacedFamilies).sorted { $0.localizedStandardCompare($1) == .orderedAscending } | ||
| } | ||
|
|
||
| /// Shows `change` right away, then writes it after a short pause (a newer | ||
| /// change to the same key replaces this task, so stepper autorepeat writes | ||
| /// once), and re-reads the effective values. When a later-loading config | ||
| /// file still overrides the key, the row names that file instead of | ||
| /// silently snapping back. | ||
| func apply(_ change: GhosttyTerminalOptionChange) { | ||
| let key = change.key | ||
| options = options.applying(change) | ||
| pendingChanges[key] = change | ||
| tasks.replaceOnMainActor(key) { [self] in | ||
| try? await Task.sleep(for: Self.writeDelay) | ||
| guard !Task.isCancelled else { return } | ||
| let saved = await hostActions.applyTerminalGhosttyOption(change) | ||
| guard !Task.isCancelled else { return } | ||
| pendingChanges[key] = nil | ||
| saveFailed = !saved | ||
| let snapshot = await hostActions.terminalGhosttyOptions() | ||
| overriddenKeys[key] = saved && !snapshot.options.reflects(change) | ||
| ? snapshot.sourcePaths[key] | ||
| : nil | ||
| options = pendingChanges.values.reduce(snapshot.options) { $0.applying($1) } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.