terminfo: makes it so terminfo files are looked up from a set of dirs

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.
char-rename
Björn Lindqvist 2016-07-30 17:28:09 +02:00
parent ba4bb45d4d
commit e8f03d9e3a
1 changed files with 28 additions and 13 deletions

View File

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