Index: main/display-string.lisp
===================================================================
--- main/display-string.lisp	(revision main,22.1.1)
+++ main/display-string.lisp	(revision main,25)
@@ -30,13 +30,17 @@
     (f 0)))
 
+
+
 (defun renderlen-part (part)
   (destructuring-bind (class image) part
-    (if (eq class 'literal)
-        (length image)
-        0)))
+    (ecase class
+      (literal (length image))
+      (escape 0))))
 
 (defun renderlen (parts)
   (let ((lens (mapcar 'renderlen-part parts)))
     (reduce '+ lens)))
+
+
 
 (defconstant +attributes+ '(#\s #.(expt 2 16)
@@ -49,11 +53,25 @@
                             #\p #.(expt 2 24)))
 
+(defun fmt-part (part)
+  (destructuring-bind (class image) part
+    (ecase class
+      (literal (enquote image))
+      (escape (format nil "`~A" image)))))
+
+(defun fmt (parts)
+  (let ((s (mapcar 'fmt-part parts)))
+    (apply 'concatenate 'string s)))
+
+
+
 (defun render (dstr window y x)
-  (let ((parts (scan-dstring dstr)))
-    (cdk:wmove window y x)
+  (let ((parts (scan-dstring dstr))
+        (printed 0))
     (dolist (p parts)
       (destructuring-bind (class image) p
         (if (eq class 'literal)
-            (add-string window image)
+            (let ((n (length image)))
+              (add-clipped-string window y (+ x printed) image)
+              (incf printed n))
             (let ((on (upper-case-p image))
                   (attr (getf +attributes+ (char-downcase image))))
@@ -63,5 +81,11 @@
 
 (defun test ()
-  (with-screen (s)
-    (render "Now `B`Ris `bthe`r ``time.'" s 10 10)
-    (input:%wget-wch s)))
+  (let ((m "`UNow `B`Ris `bthe`r ``time.'`u"))
+    (with-screen (s)
+      (cdk::c-erase-window s)
+      (cdk::c-refresh-window s)
+      (with-der-window (w s 3 10 5 5)
+        (wmove w 0 0)
+        (add-string w (make-sequence 'string 15 :initial-element #\.))
+        (render m w 1 -2)
+        (input:%wget-wch w)))))
