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
import Foundation | |
import Terminus | |
let terminal = Terminal.shared | |
var attributedString = AttributedString("Hello, bold, underlined, world.") | |
if let boldRange = attributedString.range(of: "bold") { | |
attributedString[boldRange].terminalTextAttributes = [.bold] | |
} | |
if let underlinedRange = attributedString.range(of: "underlined") { |
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
import Terminus | |
let terminal = Terminal.shared | |
terminal.write("I am bold and underlined.\n", attributes: [.bold, .underline]) | |
let greenColor = Color(r:0, g:255, b:0) | |
terminal.write("Grass is green.\n", attributes: [.color(greenColor)]) | |
let palette = XTermPalette() | |
let blueOneYellow = ColorPair(foreground: palette.Blue1, background: palette.Yellow1) |
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
// swift-tools-version:5.5 | |
// The swift-tools-version declares the minimum version of Swift required to build this package. | |
import PackageDescription | |
... | |
let package = Package( | |
name: "SwiftNCurses", | |
products: [, | |
targets: [ |
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
struct PostData: Decodable { | |
let userId: Int | |
let id: Int | |
let title: String | |
let body: String | |
} |
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
extension String { | |
init?(htmlEncodedString: String) { | |
guard let data = htmlEncodedString.data(using: .utf8) else { | |
return nil | |
} | |
let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [ | |
.documentType: NSAttributedString.DocumentType.html, | |
.characterEncoding: String.Encoding.utf8.rawValue | |
] | |
guard let attributedString = try? NSAttributedString(data: data, options: options, documentAttributes: nil) else { |
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
struct NumericTextField<T>: UIViewRepresentable { | |
private var title: String | |
@Binding var value: T | |
private var formatter: NumberFormatter | |
@State var errorMessage = "" | |
private var keyboardType: UIKeyboardType | |
init(title: String = "", value: Binding<T>, numberFormatter: NumberFormatter, keyboardType: UIKeyboardType) { | |
self.title = title | |
self._value = value |
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
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
let contentView = ContentView() | |
if let windowScene = scene as? UIWindowScene { | |
let window = UIWindow(windowScene: windowScene) | |
window.rootViewController = UIHostingController(rootView: contentView) | |
self.window = window | |
window.makeKeyAndVisible() |
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
@main | |
struct TestApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
.onAppear(perform: UIApplication.shared.addTapGestureRecognizer) | |
} | |
} | |
} |