1+ import SwiftUI
2+ import gitdiff
3+
4+ struct ConfigurationView : View {
5+ @State private var showLineNumbers = true
6+ @State private var fontSize : CGFloat = 13
7+ @State private var lineSpacing : DiffConfiguration . LineSpacing = . compact
8+ @State private var wordWrap = true
9+ @State private var selectedTheme : DiffTheme = . github
10+
11+ var body : some View {
12+ NavigationView {
13+ VStack {
14+ Form {
15+ Section ( " Display Options " ) {
16+ Toggle ( " Show Line Numbers " , isOn: $showLineNumbers)
17+
18+ HStack {
19+ Text ( " Font Size " )
20+ Spacer ( )
21+ Text ( " \( Int ( fontSize) ) pt " )
22+ . foregroundColor ( . secondary)
23+ Stepper ( " " , value: $fontSize, in: 10 ... 20 )
24+ . labelsHidden ( )
25+ }
26+
27+ Picker ( " Line Spacing " , selection: $lineSpacing) {
28+ Text ( " Compact " ) . tag ( DiffConfiguration . LineSpacing. compact)
29+ Text ( " Comfortable " ) . tag ( DiffConfiguration . LineSpacing. comfortable)
30+ Text ( " Spacious " ) . tag ( DiffConfiguration . LineSpacing. spacious)
31+ }
32+
33+ Toggle ( " Word Wrap " , isOn: $wordWrap)
34+ }
35+
36+ Section ( " Preset Configurations " ) {
37+ Button ( " Default " ) {
38+ applyConfiguration ( . default)
39+ }
40+
41+ Button ( " Code Review " ) {
42+ applyConfiguration ( . codeReview)
43+ }
44+
45+ Button ( " Mobile " ) {
46+ applyConfiguration ( . mobile)
47+ }
48+
49+ Button ( " Presentation " ) {
50+ applyConfiguration ( . presentation)
51+ }
52+ }
53+ }
54+
55+ ScrollView {
56+ VStack ( alignment: . leading) {
57+ Text ( " Preview " )
58+ . font ( . headline)
59+ . padding ( . horizontal)
60+
61+ DiffRenderer ( diffText: sampleDiff)
62+ . diffTheme ( selectedTheme)
63+ . diffLineNumbers ( showLineNumbers)
64+ . diffFont ( size: fontSize)
65+ . diffLineSpacing ( lineSpacing)
66+ . diffWordWrap ( wordWrap)
67+ . padding ( )
68+ }
69+ }
70+ }
71+ . navigationTitle ( " Configuration " )
72+ . navigationBarTitleDisplayMode ( . inline)
73+ }
74+ }
75+
76+ private func applyConfiguration( _ config: DiffConfiguration ) {
77+ selectedTheme = config. theme
78+ showLineNumbers = config. showLineNumbers
79+ fontSize = config. fontSize
80+ lineSpacing = config. lineSpacing
81+ wordWrap = config. wordWrap
82+ }
83+
84+ private let sampleDiff = """
85+ diff --git a/Config.swift b/Config.swift
86+ index 1234567..abcdefg 100644
87+ --- a/Config.swift
88+ +++ b/Config.swift
89+ @@ -10,8 +10,10 @@ struct Config {
90+ let apiKey: String
91+ let baseURL: URL
92+
93+ - init(apiKey: String) {
94+ + init(apiKey: String, environment: Environment = .production) {
95+ self.apiKey = apiKey
96+ - self.baseURL = URL(string: " https://api.example.com " )!
97+ + self.baseURL = environment.baseURL
98+ }
99+ +
100+ + enum Environment { case production, staging }
101+ }
102+ """
103+ }
0 commit comments