 
   public func pd(s: String) {
     _log.append(s)
+    invalidate()
   }
 
   public func printLogs() {

    pd("mouse click \(KEY_MOUSE)")
  }

  var invalidated = false
  var mainDiv = NCDiv()

  public func start(fn: (inout div: NCDiv) throws -> Void) throws {
    Signal.trap(Signal.INT, ncIntSignalHandler)

}


public typealias NCIntervalHandler = (timer: NCInterval) -> Void


public class NCInterval {

  public var id: Int
  public var handler: NCIntervalHandler
  public var value: Int // Milliseconds
  public var millis: Int

  init(id: Int, value: Int, millis: Int, handler: NCIntervalHandler) {
    self.id = id
    self.value = value
    self.millis = millis
    self.handler = handler
  }

  public func stop() {
    if id != -1 {
      NC.stopInterval(id)
      id = -1
    }
  }

  public func iterate(n: Int) {
    if n - millis >= value {
      self.millis = n
      handler(timer: self)
    }
  }

}


public class NCImpl {

  public let NORMAL    = Int32(0)
