Last active
July 4, 2025 02:15
-
-
Save GeorgeLyon/bbd443dcabef5ca5ae71ae83db6524ef to your computer and use it in GitHub Desktop.
Revisions
-
GeorgeLyon revised this gist
Jul 8, 2020 . 1 changed file with 6 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,18 @@ #!/usr/bin/env xcrun -sdk macosx swift // Displays UI in an NSWindow which can interact with the commandline // Usage: `echo "Bar" | ./swift-ui-commandline-tool.swift` import Foundation import SwiftUI extension CommandLine { static let input: String = { AnyIterator { readLine() }.joined() }() } struct App: SwiftUI.App { var body: some Scene { WindowGroup { VStack { Text("Hello, George!") Button("Print \"Foo\"") { print("Foo") } @@ -20,13 +21,7 @@ struct ContentView: View { } .padding(100) } .windowStyle(HiddenTitleBarWindowStyle()) } } App.main() -
GeorgeLyon revised this gist
Jul 8, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/usr/bin/env xcrun -sdk macosx swift // Displays UI which can interact with the commandline // Usage: `echo "Bar" | ./swift-ui-commandline-tool.swift` import Foundation -
GeorgeLyon revised this gist
Jul 8, 2020 . 1 changed file with 6 additions and 25 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,6 @@ // Usage: `echo "Bar" | ./swift-ui-commandline-tool.swift` import Foundation import SwiftUI extension CommandLine { @@ -23,29 +22,11 @@ struct ContentView: View { } } struct App: SwiftUI.App { var body: some SwiftUI.Scene { WindowGroup { ContentView() } } } App.main() -
GeorgeLyon revised this gist
Sep 19, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ #!/usr/bin/env xcrun -sdk macosx swift // Displays UI in an NSWindow which can interact with the commandline // Usage: `echo "Bar" | ./swift-ui-commandline-tool.swift` import Foundation -
GeorgeLyon revised this gist
Sep 19, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import Cocoa import SwiftUI extension CommandLine { static let input: String = { AnyIterator { readLine(strippingNewline: false) }.joined() }() } struct ContentView: View { -
GeorgeLyon revised this gist
Sep 19, 2019 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ #!/usr/bin/env xcrun -sdk macosx swift // Usage: `echo "Bar" | ./swift-ui-commandline-tool.swift` import Foundation import Cocoa import SwiftUI -
GeorgeLyon revised this gist
Sep 19, 2019 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,7 @@ import Cocoa import SwiftUI extension CommandLine { static let input: String = { AnyIterator { readLine() }.joined() }() } struct ContentView: View { -
GeorgeLyon revised this gist
Sep 19, 2019 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,12 +11,10 @@ extension CommandLine { } struct ContentView: View { var body: some View { VStack { Text("Hello, George!") Button("Print \"Foo\"") { print("Foo") } Button("Echo Input") { print(CommandLine.input) } Button("Done") { exit(0) } } -
GeorgeLyon revised this gist
Sep 19, 2019 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,23 @@ #!/usr/bin/env xcrun -sdk macosx swift import Foundation import Cocoa import SwiftUI extension CommandLine { static let input: String = { AnyIterator { readLine() }.joined() }() } struct ContentView: View { var body: some View { VStack { Text("Hello, George!") Button("Print \"Foo\"") { print("Foo") } Button("Echo Input") { print(CommandLine.input) } Button("Done") { exit(0) } } .padding(100) -
GeorgeLyon revised this gist
Sep 19, 2019 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,11 +7,10 @@ struct ContentView: View { var body: some View { VStack { Text("Hello, George!") Button("Print \"Foo\"") { print("Foo") } Button("Done") { exit(0) } } .padding(100) } } -
GeorgeLyon created this gist
Sep 19, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ #!/usr/bin/env xcrun -sdk macosx swift import Cocoa import SwiftUI struct ContentView: View { var body: some View { VStack { Text("Hello, George!") .frame(maxWidth: .infinity, maxHeight: .infinity) Button("Print \"Foo\"") { print("Foo") } Button("Done") { exit(0) } .padding(.bottom, 10) } } } class AppDelegate: NSObject, NSApplicationDelegate { var window: NSWindow! func applicationDidFinishLaunching(_ aNotification: Notification) { let contentView = ContentView() let window = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 480, height: 300), styleMask: [.titled, .closable, .fullSizeContentView], backing: .buffered, defer: false) window.center() window.contentView = NSHostingView(rootView: contentView) window.titlebarAppearsTransparent = true window.level = .modalPanel // The default close action causes a crash, and this way we can set the exit status let closeButton = window.standardWindowButton(.closeButton)! closeButton.target = self closeButton.action = #selector(close) window.makeKeyAndOrderFront(nil) } @objc func close() { exit(1) } } let application = NSApplication.shared let delegate = AppDelegate() application.delegate = delegate application.run()