Skip to content

Instantly share code, notes, and snippets.

@3cp
Created July 20, 2020 05:48
Show Gist options
  • Save 3cp/e0e2758882b6f94c129c24f617f700ee to your computer and use it in GitHub Desktop.
Save 3cp/e0e2758882b6f94c129c24f617f700ee to your computer and use it in GitHub Desktop.
Trap SIGWINCH in a swift terminal app
import Foundation
let sigwinchSrc = DispatchSource.makeSignalSource(signal: SIGWINCH, queue: .main)
sigwinchSrc.setEventHandler {
print("got SIGWINCH")
// Use ncurses API to get tty window size
// https://github.com/iachievedit/CNCURSES
}
sigwinchSrc.resume()
dispatchMain()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment