]> gitweb.factorcode.org Git - factor.git/commitdiff
terminfo: makes it so terminfo files are looked up from a set of dirs
authorBjörn Lindqvist <bjourne@gmail.com>
Sat, 30 Jul 2016 15:28:09 +0000 (17:28 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Sat, 30 Jul 2016 17:03:22 +0000 (19:03 +0200)
On Ubuntu, terminfo files are stored in /lib/terminfo, but they can also
be found in any of the other dirs listed in TERMINFO-DIRS.

extra/terminfo/terminfo.factor

index 3372a07e8277541bca715ba555d67347be4ece36..156ca33be1c7d5ef8b077c5985dd5c9720c99f80 100644 (file)
@@ -1,15 +1,21 @@
 ! Copyright (C) 2013 John Benediktsson.
 ! See http://factorcode.org/license.txt for BSD license.
 
-USING: accessors assocs combinators formatting fry grouping
-hashtables io io.binary io.directories io.encodings.binary
-io.files kernel math math.parser memoize pack sequences
-sequences.generalizations splitting strings system ;
+USING: accessors assocs combinators formatting fry grouping hashtables
+io io.binary io.directories io.encodings.binary io.files
+io.files.types io.pathnames kernel math math.parser memoize pack
+sequences sequences.generalizations splitting strings system ;
 
 IN: terminfo
 
 ! Reads compiled terminfo files
-! typically located in /usr/share/terminfo
+! typically located in any of the directories below.
+CONSTANT: TERMINFO-DIRS {
+    "~/.terminfo"
+    "/etc/terminfo"
+    "/lib/terminfo"
+    "/usr/share/terminfo"
+}
 
 <PRIVATE
 
@@ -69,18 +75,27 @@ PRIVATE>
 : file>terminfo ( path -- terminfo )
     binary [ read-terminfo ] with-file-reader ;
 
-HOOK: terminfo-path os ( name -- path )
+HOOK: terminfo-relative-path os ( name -- path )
+
+M: macosx terminfo-relative-path ( name -- path )
+    [ first >hex ] keep "%s/%s" sprintf ;
+
+M: linux terminfo-relative-path ( name -- path )
+    [ first ] keep "%c/%s" sprintf ;
 
-M: macosx terminfo-path ( name -- path )
-    [ first >hex ] keep "/usr/share/terminfo/%s/%s" sprintf ;
+: terminfo-path ( name -- path )
+    terminfo-relative-path TERMINFO-DIRS [ swap append-path ] with map
+    [ exists? ] find nip ;
 
-M: linux terminfo-path ( name -- path )
-    [ first ] keep "/usr/share/terminfo/%c/%s" sprintf ;
+: terminfo-names-for-path ( path -- names )
+    [
+        [ type>> +directory+ = ] filter
+        [ name>> directory-files ] map concat
+    ] with-directory-entries ;
 
 MEMO: terminfo-names ( -- names )
-    "/usr/share/terminfo" [
-        [ directory-files ] map concat
-    ] with-directory-files ;
+    TERMINFO-DIRS [ exists? ] filter
+    [ terminfo-names-for-path ] map concat ;
 
 <PRIVATE