     }
   }
 
+  var _genTimerId = 0
+  var _timers = [Int: NCInterval]()
+  var _timersCount = 0
+
+  public func doInterval(milliseconds: Int, fn: NCIntervalHandler)
+      -> NCInterval {
+    _genTimerId += 1
+    let n = _genTimerId
+    let o = NCInterval(id: n, value: milliseconds, millis: Tick.millis,
+        handler: fn)
+    _timers[n] = o
+    _timersCount += 1
+    return o
+  }
+
+  public func interval(seconds: Int, fn: NCIntervalHandler) -> NCInterval {
+    return doInterval(seconds * 1000, fn: fn)
+  }
+
+  public func interval(seconds: Double, fn: NCIntervalHandler) -> NCInterval {
+    return doInterval(Int(seconds * 1000), fn: fn)
+  }
+
+  public func stopInterval(id: Int) {
+    if let _ = _timers[id] {
+      _timersCount -= 1
+    }
+  }
+
+  public func iterateTimers(millis: Int) {
+    if _timersCount > 0 {
+      for (_, timer) in _timers {
+        timer.iterate(millis)
+      }
+    }
+  }
+
   public func exitWithError() {
     endwin()
     exit(1)


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

  public func printLogs() {

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

  var _invalidated = false
  var _lastInvalidatedAt = -1

  public func invalidate() {
    if !_invalidated && _lastInvalidatedAt < 0 {
      _lastInvalidatedAt = Tick.millis
    }
  }

  public func iterateInvalidation(millis: Int) {
    if _lastInvalidatedAt >= 0 && millis - _lastInvalidatedAt >= 100 {
      _invalidated = true
    }
  }

  public var mainDiv = NCDiv()

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