Skip to content

Commit b40d115

Browse files
committed
Added ability to move/resize windows
1 parent f99b1fe commit b40d115

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Sources/Curses.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ internal class Curses {
126126
func newWindow(position:Point, size:Size) -> UnsafeMutablePointer<WINDOW> {
127127
return CNCURSES.newwin(Int32(size.height), Int32(size.width), Int32(position.y), Int32(position.x))
128128
}
129+
130+
func moveWindow(windowHandle:UnsafeMutablePointer<WINDOW>, to:Point) {
131+
CNCURSES.mvwin(windowHandle, Int32(to.y), Int32(to.x))
132+
}
133+
134+
func getWindowPosition(windowHandle:UnsafeMutablePointer<WINDOW>) -> Point {
135+
let xPosition = getbegx(windowHandle)
136+
let yPosition = getbegy(windowHandle)
137+
return Point(x:Int(xPosition), y:Int(yPosition))
138+
}
139+
140+
func resizeWindow(windowHandle:UnsafeMutablePointer<WINDOW>, size:Size) {
141+
CNCURSES.wresize(windowHandle, Int32(size.height), Int32(size.width))
142+
}
129143

130144
func refresh(windowHandle:UnsafeMutablePointer<WINDOW>) {
131145
CNCURSES.wrefresh(windowHandle)

Sources/Window.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,23 @@ public class Window {
6767
}
6868

6969
public var size : Size {
70-
return curses.screenSize(windowHandle:windowHandle)
70+
get {
71+
return curses.screenSize(windowHandle:windowHandle)
72+
}
73+
74+
set (newSize) {
75+
curses.resizeWindow(windowHandle:windowHandle, size:newSize)
76+
}
77+
}
78+
79+
public var position : Point {
80+
get {
81+
return curses.getWindowPosition(windowHandle:windowHandle)
82+
}
83+
84+
set (newPosition) {
85+
curses.moveWindow(windowHandle:windowHandle, to:newPosition)
86+
}
7187
}
7288

7389
public func write(_ string:String) {

0 commit comments

Comments
 (0)