diff --git a/Package.swift b/Package.swift index 6aad9f9..893428b 100644 --- a/Package.swift +++ b/Package.swift @@ -11,9 +11,12 @@ let package = Package( targets: ["Curses"]), ], targets: [ + .systemLibrary(name: "ncurses", providers: [ + .apt(["ncurses"]), + .brew(["ncurses"]) + ]), .target( name:"Curses", dependencies: ["ncurses"]), - .systemLibrary(name: "ncurses") ] ) diff --git a/README.md b/README.md index 48fc58c..cd2e1db 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ import PackageDescription let package = Package( name: "myApplication", dependencies: [ - .package(url: "https://github.com/TheCoderMerlin/Curses.git", from: "1.0.0"), + .package(url: "https://github.com/jackgene/Curses.git", from: "1.0.0"), ], targets: [ .target( diff --git a/Sources/Curses/Curses.swift b/Sources/Curses/Curses.swift index 98746d5..e06ba98 100644 --- a/Sources/Curses/Curses.swift +++ b/Sources/Curses/Curses.swift @@ -87,11 +87,11 @@ internal class Curses { } } - func cursorPosition(windowHandle:UnsafeMutablePointer) -> Point { + func cursorPosition(windowHandle:OpaquePointer) -> Point { return getCursorPosition(windowHandle:windowHandle) } - func screenSize(windowHandle:UnsafeMutablePointer) -> Size { + func screenSize(windowHandle:OpaquePointer) -> Size { return getScreenSize(windowHandle:windowHandle) } @@ -99,7 +99,7 @@ internal class Curses { ncurses.curs_set(cursorStyle.rawValue) } - func setKeyPadMode(windowHandle:UnsafeMutablePointer) { + func setKeyPadMode(windowHandle:OpaquePointer) { ncurses.keypad(windowHandle, true) // Processes special keys into special codes rather than escape sequences } @@ -114,71 +114,71 @@ internal class Curses { } } - func setScroll(windowHandle:UnsafeMutablePointer, enabled:Bool) { + func setScroll(windowHandle:OpaquePointer, enabled:Bool) { ncurses.scrollok(windowHandle, enabled) } - func getKey(windowHandle:UnsafeMutablePointer) -> Key { + func getKey(windowHandle:OpaquePointer) -> Key { let code = ncurses.wgetch(windowHandle) let key = Key(code:code) return key } - func newWindow(position:Point, size:Size) -> UnsafeMutablePointer { + func newWindow(position:Point, size:Size) -> OpaquePointer { return ncurses.newwin(Int32(size.height), Int32(size.width), Int32(position.y), Int32(position.x)) } - func moveWindow(windowHandle:UnsafeMutablePointer, to:Point) { + func moveWindow(windowHandle:OpaquePointer, to:Point) { ncurses.mvwin(windowHandle, Int32(to.y), Int32(to.x)) } - func getWindowPosition(windowHandle:UnsafeMutablePointer) -> Point { + func getWindowPosition(windowHandle:OpaquePointer) -> Point { let xPosition = getbegx(windowHandle) let yPosition = getbegy(windowHandle) return Point(x:Int(xPosition), y:Int(yPosition)) } - func resizeWindow(windowHandle:UnsafeMutablePointer, size:Size) { + func resizeWindow(windowHandle:OpaquePointer, size:Size) { ncurses.wresize(windowHandle, Int32(size.height), Int32(size.width)) } - func refresh(windowHandle:UnsafeMutablePointer) { + func refresh(windowHandle:OpaquePointer) { ncurses.wrefresh(windowHandle) } - func clear(windowHandle:UnsafeMutablePointer) { + func clear(windowHandle:OpaquePointer) { ncurses.wclear(windowHandle) } - func clearToEndOfLine(windowHandle:UnsafeMutablePointer) { + func clearToEndOfLine(windowHandle:OpaquePointer) { ncurses.wclrtoeol(windowHandle) } - func clearToBottomOfWindow(windowHandle:UnsafeMutablePointer) { + func clearToBottomOfWindow(windowHandle:OpaquePointer) { ncurses.wclrtobot(windowHandle) } - func move(windowHandle:UnsafeMutablePointer, to:Point) { + func move(windowHandle:OpaquePointer, to:Point) { ncurses.wmove(windowHandle, Int32(to.y), Int32(to.x)) } - func write(windowHandle:UnsafeMutablePointer, string:String) { + func write(windowHandle:OpaquePointer, string:String) { ncurses.waddstr(windowHandle, string) } - func attributeOn(windowHandle:UnsafeMutablePointer, attributeValue:Int) { + func attributeOn(windowHandle:OpaquePointer, attributeValue:Int) { ncurses.wattron(windowHandle, Int32(attributeValue)) } - func attributeOff(windowHandle:UnsafeMutablePointer, attributeValue:Int) { + func attributeOff(windowHandle:OpaquePointer, attributeValue:Int) { ncurses.wattroff(windowHandle, Int32(attributeValue)) } - func attributeSet(windowHandle:UnsafeMutablePointer, attributeValue:Int) { + func attributeSet(windowHandle:OpaquePointer, attributeValue:Int) { ncurses.wattrset(windowHandle, Int32(attributeValue)) } - func backgroundSet(windowHandle:UnsafeMutablePointer, attributeValue:Int, character:Character) { + func backgroundSet(windowHandle:OpaquePointer, attributeValue:Int, character:Character) { let unicodeScalars = character.unicodeScalars let ascii = UInt32(unicodeScalars[unicodeScalars.startIndex].value) let attributeAndCharacter : UInt32 = UInt32(attributeValue) | ascii @@ -272,13 +272,13 @@ internal class Curses { // ============================== Helper Functions ============================== // NB: This appears to only update after an endwin/refresh/initscr - private func getScreenSize(windowHandle:UnsafeMutablePointer) -> Size { + private func getScreenSize(windowHandle:OpaquePointer) -> Size { let width : Int32 = getmaxx(windowHandle) let height : Int32 = getmaxy(windowHandle) return Size(width:Int(width), height:Int(height)) } - private func getCursorPosition(windowHandle:UnsafeMutablePointer) -> Point { + private func getCursorPosition(windowHandle:OpaquePointer) -> Point { let x : Int32 = getcurx(windowHandle) let y : Int32 = getcury(windowHandle) return Point(x:Int(x), y:Int(y)) @@ -333,7 +333,11 @@ internal class Curses { case winch = 28 } + #if os(macOS) + private typealias SignalHandler = sig_t + #else private typealias SignalHandler = __sighandler_t + #endif private static func trap(signalNumber:Signal, action:@escaping SignalHandler) { signal(signalNumber.rawValue, action) diff --git a/Sources/Curses/Window.swift b/Sources/Curses/Window.swift index 8117109..eabc130 100644 --- a/Sources/Curses/Window.swift +++ b/Sources/Curses/Window.swift @@ -21,7 +21,7 @@ import ncurses public class Window { private let curses = Curses.shared - let windowHandle : UnsafeMutablePointer + let windowHandle : OpaquePointer private var _cursor : Cursor! = nil public var cursor : Cursor { diff --git a/Sources/ncurses/module.modulemap b/Sources/ncurses/module.modulemap index 280beb2..e9b72c8 100644 --- a/Sources/ncurses/module.modulemap +++ b/Sources/ncurses/module.modulemap @@ -1,5 +1,5 @@ module ncurses [system] { header "ncurses.h" - link "ncursesw" + link "ncurses" export * -} \ No newline at end of file +}