summaryrefslogtreecommitdiffstats
path: root/packages/x11-wm/stumpwm/files/stumpwm-printing.patch
blob: bea70b178cee3ad7002afa4da2128a76c7d79a32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Source: Elias Pipping <pipping@exherbo.org>
Upstream: no (pasted on irc)
Reason: A window whose title contains the string ^\ cannot have it printed

From 56b478ae447ca8bf4b0d6d80e10fe00fb1c8d95b Mon Sep 17 00:00:00 2001
From: Elias Pipping <pipping@exherbo.org>
Date: Sat, 5 Jan 2013 22:03:53 +0100
Subject: [PATCH 1/2] Typo

---
 primitives.lisp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/primitives.lisp b/primitives.lisp
index 50d062e..3d42012 100644
--- a/primitives.lisp
+++ b/primitives.lisp
@@ -753,7 +753,7 @@ do:
                   (format t "%~a~@[~a~]" len from-left-p)
                   (let* ((fmt (cadr (assoc (car cur) fmt-alist :test 'char=)))
                          (str (cond (fmt
-                                     ;; it can return any type, not jut as string.
+                                     ;; it can return any type, not just a string.
                                      (format nil "~a" (apply fmt args)))
                                     ((char= (car cur) #\%)
                                      (string #\%))
-- 
1.8.0.3

From db588e4393567b3016c2be57511d35d3c01e4e46 Mon Sep 17 00:00:00 2001
From: Elias Pipping <pipping@exherbo.org>
Date: Sat, 5 Jan 2013 22:08:11 +0100
Subject: [PATCH 2/2] Escape window information before printing

Otherwise, a window with a title like ^\ will wreak havoc when
echo-string-list fails to parse it.
---
 primitives.lisp | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/primitives.lisp b/primitives.lisp
index 3d42012..88b45d4 100644
--- a/primitives.lisp
+++ b/primitives.lisp
@@ -732,6 +732,15 @@ do:
 ;;; 
 ;;; formatting routines
 
+(defun escape-string (str)
+  (let (buf)
+    (map nil #'(lambda (ch)
+                 (push ch buf)
+                 (when (char= ch #\^)
+                   (push ch buf)))
+         str)
+    (coerce (reverse buf) 'string)))
+
 (defun format-expand (fmt-alist fmt &rest args)
   (let* ((chars (coerce fmt 'list))
          (output "")
@@ -753,8 +762,11 @@ do:
                   (format t "%~a~@[~a~]" len from-left-p)
                   (let* ((fmt (cadr (assoc (car cur) fmt-alist :test 'char=)))
                          (str (cond (fmt
-                                     ;; it can return any type, not just a string.
-                                     (format nil "~a" (apply fmt args)))
+                                     ;; Any sequence that could be interpreted as
+                                     ;; a colorisation directive is escaped here
+                                     (escape-string
+                                      ;; it can return any type, not just a string.
+                                      (format nil "~a" (apply fmt args))))
                                     ((char= (car cur) #\%)
                                      (string #\%))
                                     (t
-- 
1.8.0.3