]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.tools.inspector: string inspection shows characters.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 30 Dec 2018 20:50:49 +0000 (12:50 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 30 Dec 2018 20:51:10 +0000 (12:51 -0800)
basis/ui/tools/inspector/inspector.factor

index 059b68680cee65fddde85addc97fe461d0f38582..257e2fc854d4ce5ce25d19937faf120f6bb305d9 100644 (file)
@@ -1,13 +1,14 @@
 ! Copyright (C) 2006, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs classes combinators fonts fry
-hashtables inspector io io.styles kernel math.vectors mirrors
-models models.arrow namespaces prettyprint sequences sorting ui
-ui.commands ui.gadgets ui.gadgets.labeled ui.gadgets.panes
-ui.gadgets.scrollers ui.gadgets.status-bar ui.gadgets.tables
+USING: accessors arrays assocs classes combinators fonts
+formatting fry hashtables inspector io io.styles kernel math
+math.parser math.vectors mirrors models models.arrow namespaces
+prettyprint sequences sorting strings ui ui.commands ui.gadgets
+ui.gadgets.labeled ui.gadgets.panes ui.gadgets.scrollers
+ui.gadgets.status-bar ui.gadgets.tables
 ui.gadgets.tables.private ui.gadgets.toolbar ui.gadgets.tracks
 ui.gestures ui.operations ui.theme ui.tools.browser
-ui.tools.common ui.tools.inspector.slots ;
+ui.tools.common ui.tools.inspector.slots unicode ;
 
 IN: ui.tools.inspector
 
@@ -68,6 +69,28 @@ GENERIC: make-slot-descriptions ( obj -- seq )
 M: object make-slot-descriptions
     make-mirror [ <slot-description> ] { } assoc>map ;
 
+M: string make-slot-descriptions
+    [
+        swap [ dup number>string ] dip dup
+        dup printable? [ 1string ] [
+            dup 0xff <= [
+                H{
+                    { CHAR: \a "\\a" }
+                    { CHAR: \b "\\b" }
+                    { CHAR: \e "\\e" }
+                    { CHAR: \f "\\f" }
+                    { CHAR: \n "\\n" }
+                    { CHAR: \r "\\r" }
+                    { CHAR: \t "\\t" }
+                    { CHAR: \v "\\v" }
+                    { CHAR: \0 "\\0" }
+                } ?at [ "\\x%02x" sprintf ] unless
+            ] [
+                "\\u{%x}" sprintf
+            ] if
+        ] if slot-description boa
+    ] map-index ;
+
 M: hashtable make-slot-descriptions
     call-next-method [ key-string>> ] sort-with ;