mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 03:25:03 +03:00
Reformat
This commit is contained in:
parent
d9faae80c5
commit
61d092e516
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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<CTRun>)[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<CTRun>)[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..<positions.count) {
|
||||
positions[i].x += 20
|
||||
positions[i].y += 10
|
||||
}
|
||||
for i in (0..<positions.count) {
|
||||
positions[i].x += 20
|
||||
positions[i].y += 10
|
||||
}
|
||||
|
||||
print(glyphs)
|
||||
print(positions)
|
||||
print(advances)
|
||||
print(glyphs)
|
||||
print(positions)
|
||||
print(advances)
|
||||
|
||||
CTFontDrawGlyphs(font, glyphs, positions, glyphCount, context)
|
||||
*/
|
||||
CTFontDrawGlyphs(font, glyphs, positions, glyphCount, context)
|
||||
*/
|
||||
|
||||
/*
|
||||
// let glyphs: [CGGlyph] = [1614, 1494, 1104, 133]
|
||||
let glyphs: [CGGlyph] = [1614, 1614, 1063]
|
||||
let positions = (0..<3).compactMap {
|
||||
CGPoint(x: CGFloat($0) * cellSize.width, y: 10)
|
||||
}
|
||||
CTFontDrawGlyphs(
|
||||
fira,
|
||||
glyphs,
|
||||
positions,
|
||||
3,
|
||||
context
|
||||
)
|
||||
*/
|
||||
// let glyphs: [CGGlyph] = [1614, 1494, 1104, 133]
|
||||
let glyphs: [CGGlyph] = [1614, 1614, 1063]
|
||||
let positions = (0..<3).compactMap {
|
||||
CGPoint(x: CGFloat($0) * cellSize.width, y: 10)
|
||||
}
|
||||
CTFontDrawGlyphs(
|
||||
fira,
|
||||
glyphs,
|
||||
positions,
|
||||
3,
|
||||
context
|
||||
)
|
||||
*/
|
||||
|
||||
let runs = (0..<5).map { row in
|
||||
AttributesRun(
|
||||
@ -89,7 +88,7 @@ class MyView: NSView {
|
||||
)
|
||||
|
||||
self.runDrawer.usesLigatures = true
|
||||
runs.forEach { run in
|
||||
runs.forEach { _ in
|
||||
self.runDrawer.draw(
|
||||
runs,
|
||||
defaultAttributes: defaultAttrs,
|
||||
@ -115,11 +114,19 @@ class MyView: NSView {
|
||||
|
||||
var lines = [
|
||||
CGRect(x: 0, y: 0, width: 1, height: self.bounds.height),
|
||||
CGRect(x: self.bounds.width - 1, y: 0,
|
||||
width: 1, height: self.bounds.height),
|
||||
CGRect(
|
||||
x: self.bounds.width - 1,
|
||||
y: 0,
|
||||
width: 1,
|
||||
height: self.bounds.height
|
||||
),
|
||||
CGRect(x: 0, y: 0, width: self.bounds.width, height: 1),
|
||||
CGRect(x: 0, y: self.bounds.height - 1,
|
||||
width: self.bounds.width, height: 1),
|
||||
CGRect(
|
||||
x: 0,
|
||||
y: self.bounds.height - 1,
|
||||
width: self.bounds.width,
|
||||
height: 1
|
||||
),
|
||||
]
|
||||
let rowCount = Int(ceil(self.bounds.height / cellSize.height))
|
||||
let columnCount = Int(ceil(self.bounds.width / cellSize.width))
|
||||
@ -127,14 +134,18 @@ class MyView: NSView {
|
||||
for row in 0..<rowCount {
|
||||
for col in 0..<columnCount {
|
||||
lines.append(contentsOf: [
|
||||
CGRect(x: CGFloat(col) * cellSize.width,
|
||||
y: CGFloat(row) * cellSize.height,
|
||||
width: 1,
|
||||
height: self.bounds.height),
|
||||
CGRect(x: CGFloat(col) * cellSize.width,
|
||||
y: CGFloat(row) * cellSize.height,
|
||||
width: self.bounds.width,
|
||||
height: 1),
|
||||
CGRect(
|
||||
x: CGFloat(col) * cellSize.width,
|
||||
y: CGFloat(row) * cellSize.height,
|
||||
width: 1,
|
||||
height: self.bounds.height
|
||||
),
|
||||
CGRect(
|
||||
x: CGFloat(col) * cellSize.width,
|
||||
y: CGFloat(row) * cellSize.height,
|
||||
width: self.bounds.width,
|
||||
height: 1
|
||||
),
|
||||
])
|
||||
}
|
||||
}
|
||||
@ -151,7 +162,7 @@ class MyView: NSView {
|
||||
clearCol: 10,
|
||||
clearAttr: 0,
|
||||
chunk: [
|
||||
"하", "", "태", "", "원", "", " ", "a\u{1DC1}", "a\u{032A}", "a\u{034B}"
|
||||
"하", "", "태", "", "원", "", " ", "a\u{1DC1}", "a\u{032A}", "a\u{034B}",
|
||||
],
|
||||
attrIds: Array(repeating: 0, count: 10)
|
||||
)
|
||||
@ -170,7 +181,7 @@ class MyView: NSView {
|
||||
endCol: 10,
|
||||
clearCol: 10,
|
||||
clearAttr: 0,
|
||||
chunk: [ "ἐ", "τ" ,"έ", "ἔ", "-", ">", " ", "<", "=", ">"],
|
||||
chunk: ["ἐ", "τ", "έ", "ἔ", "-", ">", " ", "<", "=", ">"],
|
||||
attrIds: Array(repeating: 0, count: 10)
|
||||
)
|
||||
self.ugrid.update(
|
||||
|
@ -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..<repeatCount) {
|
||||
for _ in 0..<repeatCount {
|
||||
let rd = GKRandomDistribution(
|
||||
randomSource: GKMersenneTwisterRandomSource(seed: 129384832),
|
||||
randomSource: GKMersenneTwisterRandomSource(seed: 129_384_832),
|
||||
lowestValue: 0,
|
||||
highestValue: repeatCount - 1
|
||||
)
|
||||
let indices = (0..<count).map { i in rd.nextInt() % 3 }
|
||||
let indices = (0..<count).map { _ in rd.nextInt() % 3 }
|
||||
|
||||
let time = self.measure {
|
||||
for i in (0..<count) { result[i] = self.perf.render(indices[i]) }
|
||||
for i in 0..<count { result[i] = self.perf.render(indices[i]) }
|
||||
}
|
||||
results.append(time)
|
||||
}
|
||||
@ -39,8 +38,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
private let perf = PerfTester()
|
||||
|
||||
private let log = OSLog(subsystem: "com.qvacua.DrawerPerf",
|
||||
category: "perf-tester")
|
||||
private let log = OSLog(
|
||||
subsystem: "com.qvacua.DrawerPerf",
|
||||
category: "perf-tester"
|
||||
)
|
||||
|
||||
private func measure(_ body: () -> Void) -> CFTimeInterval {
|
||||
let start = CFAbsoluteTimeGetCurrent()
|
||||
|
@ -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)
|
||||
|
@ -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<Int>,
|
||||
columnRange: CountableClosedRange<Int>
|
||||
) -> [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)
|
||||
|
@ -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 }
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user