Index: main/display-string.lisp
===================================================================
--- main/display-string.lisp	(revision main,22.1.1)
+++ main/display-string.lisp	(revision main,22.1.1)
@@ -0,0 +1,67 @@
+(defpackage #:display-string
+  (:use #:cl #:cdk #:cl-ppcre #:dso-lex)
+  (:export #:enquote #:dequote #:render))
+
+(in-package #:display-string)
+
+
+
+(defun enquote (str)
+  (regex-replace-all "`" str "``"))
+
+(defun dequote (str)
+  (regex-replace-all "`(.)" str "\\1"))
+
+
+
+(defun escape-code (two-char)
+  (aref two-char 1))
+
+(deflexer eat-dstring
+  ("`[SsRrBbUuDdKkPpIi]" escape escape-code)
+  ("(?:[^`]|``)+" literal dequote))
+
+(defun scan-dstring (dstr)
+  (labels ((f (start &optional tokens)
+             (multiple-value-bind (class image end) (eat-dstring dstr start)
+               (if class
+                   (f end (cons (list class image) tokens))
+                   (nreverse tokens)))))
+    (f 0)))
+
+(defun renderlen-part (part)
+  (destructuring-bind (class image) part
+    (if (eq class 'literal)
+        (length image)
+        0)))
+
+(defun renderlen (parts)
+  (let ((lens (mapcar 'renderlen-part parts)))
+    (reduce '+ lens)))
+
+(defconstant +attributes+ '(#\s #.(expt 2 16)
+                            #\u #.(expt 2 17)
+                            #\r #.(expt 2 18)
+                            #\k #.(expt 2 19)
+                            #\d #.(expt 2 20)
+                            #\b #.(expt 2 21)
+                            #\i #.(expt 2 23)
+                            #\p #.(expt 2 24)))
+
+(defun render (dstr window y x)
+  (let ((parts (scan-dstring dstr)))
+    (cdk:wmove window y x)
+    (dolist (p parts)
+      (destructuring-bind (class image) p
+        (if (eq class 'literal)
+            (add-string window image)
+            (let ((on (upper-case-p image))
+                  (attr (getf +attributes+ (char-downcase image))))
+              (if on
+                  (cdk::c-wattron window attr)
+                  (cdk::c-wattroff window attr))))))))
+
+(defun test ()
+  (with-screen (s)
+    (render "Now `B`Ris `bthe`r ``time.'" s 10 10)
+    (input:%wget-wch s)))
Index: main/cdk.lisp
===================================================================
--- main/cdk.lisp	(revision main,18)
+++ main/cdk.lisp	(revision main,22.1.1)
@@ -1,5 +1,5 @@
 (defpackage #:cdk
   (:use #:cl #:cffi)
-  (:export #:with-screen #:with-der-window))
+  (:export #:with-screen #:with-der-window #:add-ch #:add-string #:wmove))
 
 (in-package #:cdk)
@@ -127,8 +127,6 @@
   (x :int))
 
-(defcfun ("mvwadd_wch" c-move-and-add-char) :int
-  (window :pointer)
-  (y :int)
-  (x :int)
+(defcfun "wadd_wch" :int
+  (window :pointer)
   (wch :pointer))
 
@@ -157,5 +155,10 @@
     (inc-pointer nc-wacs (* (foreign-type-size 'cchar_t) code))))
 
-(defun move-and-add-char (window y x ch)
+(defcfun ("wmove" c-wmove) :int
+  (window :pointer)
+  (y :int)
+  (x :int))
+
+(defun add-char (window ch)
   (with-foreign-object (s 'cchar_t)
     (with-foreign-slots ((attr char) s cchar_t)
@@ -164,14 +167,17 @@
         (setf (mem-aref char :uint32 i) 0))
       (setf (mem-aref char :uint32) (char-code ch)))
-    (c-move-and-add-char window y x s)))
+    (wadd-wch window s)))
+
+(defun add-string (window s)
+  (dotimes (i (length s))
+    (add-char window (aref s i))))
+
+(defun move-and-add-char (window y x ch)
+  (wmove window y x)
+  (add-char window ch))
 
 (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 ("wmove" c-wmove) :int
-  (window :pointer)
-  (y :int)
-  (x :int))
+  (wmove window y x)
+  (add-string window s))
 
 (defcfun ("wrefresh" c-refresh-window) :int
Index: main/tui.asd
===================================================================
--- main/tui.asd	(revision main,22)
+++ main/tui.asd	(revision main,22.1.1)
@@ -2,7 +2,9 @@
 
 (asdf:defsystem #:tui
-  :depends-on (#:cffi #:dso-util)
+  :depends-on (#:cffi #:cl-ppcre #:dso-lex #:dso-util)
   :components (#|(:file "curses")|#
                (:file "cdk")
+               (:file "display-string"
+                      :depends-on ("cdk"))
                (:module "grid"
                         :depends-on ("cdk")
