feat: print complete default configuration from CLI

This commit is contained in:
2026-10-11 17:03:51 +02:00
parent 41e4a458cf
commit 35181634d6
6 changed files with 36 additions and 1 deletions
@@ -15,6 +15,26 @@ public struct PlayerConfiguration: Equatable, Sendable {
self.keys = keys
}
public static var defaultTOML: String {
let defaults = Self()
let encoder = JSONEncoder()
encoder.outputFormatting = .withoutEscapingSlashes
var lines = [
"automatic_quality = \(defaults.automaticQuality)",
"", "[ui]",
"buffer_info = \(defaults.showBufferInfo)",
"compact_snap_to_edges = \(defaults.snapToEdges)",
"", "[keys]"
]
for (name, action) in PlayerAction.namedActions {
let chords = defaults.keys.shortcuts(for: action).map(\.description)
// JSON string arrays are valid TOML arrays; preserve escaping for printable keys.
let value = String(decoding: try! encoder.encode(chords), as: UTF8.self)
lines.append("\(name) = \(value)")
}
return lines.joined(separator: "\n") + "\n"
}
public static func fileURL(environment: [String: String], homeDirectory: URL) -> URL {
let directory: URL
if let path = environment["XDG_CONFIG_HOME"], path.hasPrefix("/") {