diff --git a/NvimView/Support/DrawerDev/AppDelegate.swift b/NvimView/Support/DrawerDev/AppDelegate.swift index afa4c40b..e92a2863 100644 --- a/NvimView/Support/DrawerDev/AppDelegate.swift +++ b/NvimView/Support/DrawerDev/AppDelegate.swift @@ -7,16 +7,13 @@ import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { + @IBOutlet var window: NSWindow! - @IBOutlet weak var window: NSWindow! - - - func applicationDidFinishLaunching(_ aNotification: Notification) { + func applicationDidFinishLaunching(_: Notification) { // Insert code here to initialize your application } - func applicationWillTerminate(_ aNotification: Notification) { + func applicationWillTerminate(_: Notification) { // Insert code here to tear down your application } } - diff --git a/NvimView/Support/DrawerDev/FontTrait.swift b/NvimView/Support/DrawerDev/FontTrait.swift index 19231604..2d40da49 100644 --- a/NvimView/Support/DrawerDev/FontTrait.swift +++ b/NvimView/Support/DrawerDev/FontTrait.swift @@ -6,12 +6,11 @@ import Foundation public struct FontTrait: OptionSet { - public let rawValue: UInt - - public init(rawValue: UInt) { - self.rawValue = rawValue - } + + public init(rawValue: UInt) { + self.rawValue = rawValue + } static let italic = FontTrait(rawValue: 1 << 0) static let bold = FontTrait(rawValue: 1 << 1) diff --git a/NvimView/Support/DrawerDev/MyView.swift b/NvimView/Support/DrawerDev/MyView.swift index ebcac05d..c58edb1b 100644 --- a/NvimView/Support/DrawerDev/MyView.swift +++ b/NvimView/Support/DrawerDev/MyView.swift @@ -12,59 +12,58 @@ import Cocoa // let cells = ["<", "-", "-", "\u{1F600}", "", " ", "b", "c"] class MyView: NSView { - required init?(coder decoder: NSCoder) { super.init(coder: decoder) self.setupUgrid() } - override func draw(_ dirtyRect: NSRect) { + override func draw(_: NSRect) { guard let context = NSGraphicsContext.current?.cgContext else { return } let cellSize = FontUtils.cellSize(of: fira, linespacing: 1, characterspacing: 1) /* - let string = "a\u{034B}" - let attrStr = NSAttributedString(string: string, attributes: [.font: fira]) - let ctLine = CTLineCreateWithAttributedString(attrStr) - let ctRun = (CTLineGetGlyphRuns(ctLine) as! Array)[0] - let glyphCount = CTRunGetGlyphCount(ctRun) - var glyphs = Array(repeating: CGGlyph(), count: glyphCount) - var positions = Array(repeating: CGPoint(), count: glyphCount) - var advances = Array(repeating: CGSize(), count: glyphCount) - CTRunGetGlyphs(ctRun, .zero, &glyphs) - CTRunGetPositions(ctRun, .zero, &positions) - CTRunGetAdvances(ctRun, .zero, &advances) + let string = "a\u{034B}" + let attrStr = NSAttributedString(string: string, attributes: [.font: fira]) + let ctLine = CTLineCreateWithAttributedString(attrStr) + let ctRun = (CTLineGetGlyphRuns(ctLine) as! Array)[0] + let glyphCount = CTRunGetGlyphCount(ctRun) + var glyphs = Array(repeating: CGGlyph(), count: glyphCount) + var positions = Array(repeating: CGPoint(), count: glyphCount) + var advances = Array(repeating: CGSize(), count: glyphCount) + CTRunGetGlyphs(ctRun, .zero, &glyphs) + CTRunGetPositions(ctRun, .zero, &positions) + CTRunGetAdvances(ctRun, .zero, &advances) - let attrs = CTRunGetAttributes(ctRun) as! [NSAttributedStringKey: Any] - let font = attrs[NSAttributedStringKey.font] as! NSFont + let attrs = CTRunGetAttributes(ctRun) as! [NSAttributedStringKey: Any] + let font = attrs[NSAttributedStringKey.font] as! NSFont - for i in (0..", " ", "<", "=", ">"], + chunk: ["ἐ", "τ", "έ", "ἔ", "-", ">", " ", "<", "=", ">"], attrIds: Array(repeating: 0, count: 10) ) self.ugrid.update( diff --git a/NvimView/Support/DrawerPerf/AppDelegate.swift b/NvimView/Support/DrawerPerf/AppDelegate.swift index 3ef13019..5eff42cc 100644 --- a/NvimView/Support/DrawerPerf/AppDelegate.swift +++ b/NvimView/Support/DrawerPerf/AppDelegate.swift @@ -9,23 +9,22 @@ import os @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { + @IBOutlet var window: NSWindow! + var result = [[[FontGlyphRun]]](repeating: [], count: count) - @IBOutlet weak var window: NSWindow! - var result = Array<[[FontGlyphRun]]>(repeating: [], count: count) - - func applicationDidFinishLaunching(_ aNotification: Notification) { + func applicationDidFinishLaunching(_: Notification) { var results = [CFTimeInterval]() let repeatCount = 5 - for _ in (0.. Void) -> CFTimeInterval { let start = CFAbsoluteTimeGetCurrent() diff --git a/NvimView/Support/DrawerPerf/FontTrait.swift b/NvimView/Support/DrawerPerf/FontTrait.swift index 19231604..2d40da49 100644 --- a/NvimView/Support/DrawerPerf/FontTrait.swift +++ b/NvimView/Support/DrawerPerf/FontTrait.swift @@ -6,12 +6,11 @@ import Foundation public struct FontTrait: OptionSet { - public let rawValue: UInt - - public init(rawValue: UInt) { - self.rawValue = rawValue - } + + public init(rawValue: UInt) { + self.rawValue = rawValue + } static let italic = FontTrait(rawValue: 1 << 0) static let bold = FontTrait(rawValue: 1 << 1) diff --git a/NvimView/Support/DrawerPerf/PerfTester.swift b/NvimView/Support/DrawerPerf/PerfTester.swift index 50bce3dc..43c1cccf 100644 --- a/NvimView/Support/DrawerPerf/PerfTester.swift +++ b/NvimView/Support/DrawerPerf/PerfTester.swift @@ -12,14 +12,13 @@ import GameKit import os class PerfTester { - init() { self.cellSize = FontUtils.cellSize(of: self.font, linespacing: 1.25, characterspacing: 1) for name in ["0", "1", "2"] { guard let fileUrl = Bundle(for: PerfTester.self) .url(forResource: name, withExtension: "json") - else { + else { preconditionFailure("Could not find \(name).json") } @@ -39,9 +38,11 @@ class PerfTester { precondition((0...2).contains(index), "Wrong index!") let ugrid = self.ugrids[index] - let runs = self.runs(index, - forRowRange: 0...ugrid.size.height - 1, - columnRange: 0...ugrid.size.width - 1) + let runs = self.runs( + index, + forRowRange: 0...ugrid.size.height - 1, + columnRange: 0...ugrid.size.width - 1 + ) return runs.parallelMap(chunkSize: 50) { run in let font = FontUtils.font( @@ -53,7 +54,8 @@ class PerfTester { startColumn: run.cells.startIndex, offset: .zero, font: font, - cellWidth: 20) + cellWidth: 20 + ) } } @@ -68,35 +70,37 @@ class PerfTester { forRowRange rowRange: CountableClosedRange, columnRange: CountableClosedRange ) -> [AttributesRun] { - precondition(0 <= index && index <= 2, "Wrong index!") + precondition(index >= 0 && index <= 2, "Wrong index!") let ugrid = self.ugrids[index] return rowRange.map { row in - ugrid.cells[row][columnRange] - .groupedRanges(with: { _, cell in cell.attrId }) - .compactMap { range in - let cells = ugrid.cells[row][range] + ugrid.cells[row][columnRange] + .groupedRanges(with: { _, cell in cell.attrId }) + .compactMap { range in + let cells = ugrid.cells[row][range] - guard let firstCell = cells.first, - let attrs = self.cellAttrsCollection.attributes( - of: firstCell.attrId - ) - else { - // GH-666: FIXME: correct error handling - self.log.error("row: \(row), range: \(range): " + - "Could not get CellAttributes with ID " + - "\(String(describing: cells.first?.attrId))") - return nil - } - - return AttributesRun( - location: CGPoint.zero, - cells: ugrid.cells[row][range], - attrs: attrs + guard let firstCell = cells.first, + let attrs = self.cellAttrsCollection.attributes( + of: firstCell.attrId ) + else { + // GH-666: FIXME: correct error handling + self.log.error( + "row: \(row), range: \(range): " + + "Could not get CellAttributes with ID " + + "\(String(describing: cells.first?.attrId))" + ) + return nil } - } - .flatMap { $0 } + + return AttributesRun( + location: CGPoint.zero, + cells: ugrid.cells[row][range], + attrs: attrs + ) + } + } + .flatMap { $0 } } private let fontTraitRd = GKRandomDistribution( @@ -108,7 +112,7 @@ class PerfTester { private let intColorRd = GKRandomDistribution( randomSource: randomSource, lowestValue: 0, - highestValue: 16777215 + highestValue: 16_777_215 ) private let attrsRunRd = GKRandomDistribution( @@ -117,21 +121,25 @@ class PerfTester { highestValue: 10 ) - private let log = OSLog(subsystem: "com.qvacua.DrawerPerf", - category: "perf-tester") + private let log = OSLog( + subsystem: "com.qvacua.DrawerPerf", + category: "perf-tester" + ) private func initAttrs() { - for i in (1..<200) { + for i in 1..<200 { self.cellAttrsCollection.set(attributes: self.randomCellAttrs(), for: i) } } private func randomCellAttrs() -> CellAttributes { - return CellAttributes(fontTrait: self.randomFontTrait(), - foreground: self.intColorRd.nextInt(), - background: self.intColorRd.nextInt(), - special: self.intColorRd.nextInt(), - reverse: false) + CellAttributes( + fontTrait: self.randomFontTrait(), + foreground: self.intColorRd.nextInt(), + background: self.intColorRd.nextInt(), + special: self.intColorRd.nextInt(), + reverse: false + ) } private func randomFontTrait() -> FontTrait { @@ -148,4 +156,4 @@ class PerfTester { } } -private let randomSource = GKMersenneTwisterRandomSource(seed: 95749272934) +private let randomSource = GKMersenneTwisterRandomSource(seed: 95_749_272_934) diff --git a/NvimView/Support/MinimalNvimViewDemo/AppDelegate.swift b/NvimView/Support/MinimalNvimViewDemo/AppDelegate.swift index 72e1d3a4..6dd4b6c8 100644 --- a/NvimView/Support/MinimalNvimViewDemo/AppDelegate.swift +++ b/NvimView/Support/MinimalNvimViewDemo/AppDelegate.swift @@ -8,14 +8,11 @@ import RxSwift @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { - - func applicationDidFinishLaunching(_ aNotification: Notification) { - } + func applicationDidFinishLaunching(_: Notification) {} func applicationShouldTerminate( _: NSApplication ) -> NSApplication.TerminateReply { - NSDocumentController.shared .documents .compactMap { $0 as? Document } diff --git a/NvimView/Support/MinimalNvimViewDemo/Document.swift b/NvimView/Support/MinimalNvimViewDemo/Document.swift index c5a05c6d..2f0e2b73 100644 --- a/NvimView/Support/MinimalNvimViewDemo/Document.swift +++ b/NvimView/Support/MinimalNvimViewDemo/Document.swift @@ -9,7 +9,6 @@ import PureLayout import RxSwift class Document: NSDocument, NSWindowDelegate { - private var nvimView = NvimView(forAutoLayout: ()) private let disposeBag = DisposeBag() @@ -17,20 +16,18 @@ class Document: NSDocument, NSWindowDelegate { super.init() self.nvimView.font = NSFont(name: "Fira Code", size: 13) - ?? NSFont.userFixedPitchFont(ofSize: 13)! + ?? NSFont.userFixedPitchFont(ofSize: 13)! self.nvimView.usesLigatures = true self.nvimView.drawsParallel = true - nvimView + self.nvimView .events .observeOn(MainScheduler.instance) .subscribe(onNext: { event in switch event { - case .neoVimStopped: self.close() default: break - } }) .disposed(by: self.disposeBag) @@ -41,7 +38,7 @@ class Document: NSDocument, NSWindowDelegate { self.nvimView.waitTillNvimExits() } - func windowShouldClose(_ sender: NSWindow) -> Bool { + func windowShouldClose(_: NSWindow) -> Bool { self.quitWithoutSaving() return false } @@ -60,16 +57,16 @@ class Document: NSDocument, NSWindowDelegate { override var windowNibName: NSNib.Name? { // Returns the nib file name of the document // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this property and override -makeWindowControllers instead. - return NSNib.Name("Document") + NSNib.Name("Document") } - override func data(ofType typeName: String) throws -> Data { + override func data(ofType _: String) throws -> Data { // Insert code here to write your document to data of the specified type, throwing an error in case of failure. // Alternatively, you could remove this method and override fileWrapper(ofType:), write(to:ofType:), or write(to:ofType:for:originalContentsURL:) instead. throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) } - override func read(from data: Data, ofType typeName: String) throws { + override func read(from _: Data, ofType _: String) throws { // Insert code here to read your document from the given data of the specified type, throwing an error in case of failure. // Alternatively, you could remove this method and override read(from:ofType:) instead. // If you do, you should also override isEntireFileLoaded to return false if the contents are lazily loaded.