Skip to content

Commit dd3bc1a

Browse files
committed
Adding ability to set background
1 parent 471c455 commit dd3bc1a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Sources/Curses.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ internal class Curses {
162162
func attributeSet(windowHandle:UnsafeMutablePointer<WINDOW>, attributeValue:Int) {
163163
CNCURSES.wattrset(windowHandle, Int32(attributeValue))
164164
}
165+
166+
func backgroundSet(windowHandle:UnsafeMutablePointer<WINDOW>, attributeValue:Int, character:Character) {
167+
let unicodeScalars = character.unicodeScalars
168+
let ascii = UInt(unicodeScalars[unicodeScalars.startIndex].value)
169+
let attributeAndCharacter : UInt = UInt(attributeValue) + ascii
170+
CNCURSES.wbkgd(windowHandle, attributeAndCharacter)
171+
}
165172

166173
var maxColorCount : Int {
167174
return Int(COLORS)

Sources/Window.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public class Window {
4949
curses.refresh(windowHandle:windowHandle)
5050
}
5151

52+
public func backgroundSet(attribute:Attribute, character:Character = " ") {
53+
let attributeValue = attribute.value
54+
curses.backgroundSet(windowHandle:windowHandle, attributeValue:attributeValue, character:character)
55+
}
56+
5257
public func clear() {
5358
curses.clear(windowHandle:windowHandle)
5459
}

0 commit comments

Comments
 (0)