Index: main/flat-menu.lisp
===================================================================
--- main/flat-menu.lisp	(revision main,7)
+++ main/flat-menu.lisp	(revision main,7)
@@ -0,0 +1,75 @@
+(defpackage #:flat-menu
+  (:use #:cl #:cffi)
+  (:export))
+
+(in-package #:flat-menu)
+
+
+
+(defclass entry ()
+  ((window :initarg :window)
+   (row :initarg :row)
+   (column :initarg :column)
+   (text :initarg :text)
+   (highlight :accessor highlight)))
+
+(defun draw-entry (entry)
+  (with-slots (window row column text highlight) entry
+    (when highlight
+      (cdk::c-wattron window 262144))
+    (cdk::move-and-add-string window row column text)
+    (when highlight
+      (cdk::c-wattroff window 262144))))
+
+(defmethod (setf highlight) :after (flag (entry entry))
+  (draw-entry entry))
+
+(defun activate-entry (entry)
+  (with-slots (window) entry
+    (setf (highlight entry) t)
+    (cdk::c-refresh-window window)
+    (let ((ch (cdk::c-wgetch window)))
+      (setf (highlight entry) nil)
+      ch)))
+
+(defclass menu ()
+  ((entries :type vector :initarg :entries)
+   (selected :type (integer 0) :accessor selected)))
+
+(defmethod initialize-instance :after ((menu menu) &rest initargs)
+  (with-slots (entries) menu
+    (dotimes (i (length entries))
+      (setf (highlight (aref entries i)) nil))
+    (setf (selected menu) 0)))
+
+(defun activate-menu (menu)
+  (with-slots (entries selected) menu
+    (loop
+       (multiple-value-bind (exit) (activate-entry (aref entries selected))
+         (cond
+           ((= exit 258)
+            
+            (incf selected))
+           ((= exit 259)
+            (decf selected))
+           (t (break)))
+         (setf selected (mod selected (length entries)))))))
+
+(defun test ()
+  (let ((screen (cdk::c-init-curses-screen)))
+    (cdk::c-cbreak)
+    (cdk::c-noecho)
+    (cdk::c-nonl)
+    (cdk::c-keypad screen t)
+    (cdk::c-init-color)
+    (cdk::c-erase-window screen)
+    (let ((entry1 (make-instance 'entry :window screen :row 5 :column 10 :text "Hello, world!"))
+          (entry2 (make-instance 'entry :window screen :row 6 :column 10 :text "Goodbye, galaxy!")))
+      (setf (highlight entry1) t)
+      (let ((menu (make-instance 'menu :entries (vector entry1 entry2))))
+        (activate-menu menu)
+        (format t "Here~%")
+        (read-line)))
+    (cdk::c-refresh-window screen)
+    (read-line)
+    (cdk::c-end-curses)))
Index: main/Makefile
===================================================================
--- main/Makefile	(revision main,5)
+++ main/Makefile	(revision main,7)
@@ -5,9 +5,9 @@
 form2.so: LIBS := -lform
 
-cdk_wrapper.so: LIBS := -lcdk
+cdk_wrapper.so: LIBS := -lcdkw
 
 %.so: %.c
 	rm -f $@
-	gcc -shared -fPIC -o $@ $< $(LIBS) -Wall -pedantic
+	gcc -shared -fPIC -Wall -pedantic -o $@ $< $(LIBS)
 
 clean:
Index: main/cdk.lisp
===================================================================
--- main/cdk.lisp	(revision main,6)
+++ main/cdk.lisp	(revision main,7)
@@ -50,4 +50,18 @@
   (x :int))
 
+(defcfun ("subwin" c-sub-window) :pointer
+  (orig :pointer)
+  (lines :int)
+  (columns :int)
+  (y :int)
+  (x :int))
+
+(defcfun ("derwin" c-der-window) :pointer
+  (orig :pointer)
+  (lines :int)
+  (columns :int)
+  (y :int)
+  (x :int))
+
 (defcfun ("delwin" c-delete-window) :int
   (window :pointer))
@@ -57,4 +71,70 @@
   (vertical-ch chtype)
   (horizontal-ch chtype))
+
+(defcfun ("wborder" c-window-border) :int
+  (window :pointer)
+  (ls chtype)
+  (rs chtype)
+  (ts chtype)
+  (bs chtype)
+  (tl chtype)
+  (tr chtype)
+  (bl chtype)
+  (br chtype))
+
+(defcfun ("wbkgd" c-set-window-background) :int
+  (window :pointer)
+  (ch chtype))
+
+(defcfun ("werase" c-erase-window) :int
+  (window :pointer))
+
+(defcfun ("mvwadd_wch" c-move-and-add-char) :int
+  (window :pointer)
+  (y :int)
+  (x :int)
+  (wch :pointer))
+
+(defcstruct cchar_t
+  (attr chtype)
+  (char :uint32 :count 5))
+
+
+
+(defcvar ("_nc_wacs" nc-wacs) :pointer :read-only t)
+
+(defun wacs-char (ch)
+  (let ((code (char-code (ecase ch
+                           (:ul-corner #\l)
+                           (:ll-corner #\m)
+                           (:ur-corner #\k)
+                           (:lr-corner #\j)
+                           (:r-tee #\u)
+                           (:l-tee #\t)
+                           (:b-tee #\v)
+                           (:t-tee #\w)
+                           (:h-line #\q)
+                           (:v-line #\x)
+                           (:plus #\n)))))
+    (inc-pointer nc-wacs (* (foreign-type-size 'cchar_t) code))))
+
+(defun move-and-add-char (window y x ch)
+  (with-foreign-object (s 'cchar_t)
+    (with-foreign-slots ((attr char) s cchar_t)
+      (setf attr 0)
+      (dotimes (i 5)
+        (setf (mem-aref char :uint32 i) 0))
+      (setf (mem-aref char :uint32) (char-code ch)))
+    (c-move-and-add-char window y x s)))
+
+(defun move-and-add-string (window y x s)
+  (dotimes (i (length s))
+    (move-and-add-char window y (+ x i) (aref s i))))
+
+(defcfun ("wrefresh" c-refresh-window) :int
+  (window :pointer))
+
+(defun color-pair (n)
+  (* 256 n))
 
 
@@ -149,2 +229,25 @@
   (entry :pointer)
   (ch chtype))
+
+
+
+(defcfun ("wattron" c-wattron) :int
+  (window :pointer)
+  (attrs :int))
+
+(defcfun ("wattroff" c-wattroff) :int
+  (window :pointer)
+  (attrs :int))
+
+(defcfun ("wgetch" c-wgetch) :int
+  (window :pointer))
+
+(defcfun ("cbreak" c-cbreak) :int)
+
+(defcfun ("noecho" c-noecho) :int)
+
+(defcfun ("keypad" c-keypad) :int
+  (window :pointer)
+  (bf :boolean))
+
+(defcfun ("nonl" c-nonl) :int)
Index: main/tui.asd
===================================================================
--- main/tui.asd	(revision main,5)
+++ main/tui.asd	(revision main,7)
@@ -4,3 +4,5 @@
   :depends-on (#:cffi)
   :components (#|(:file "curses")|#
-               (:file "cdk")))
+               (:file "cdk")
+               (:file "flat-menu"))
+  :serial t)
