move ls to io.files.listing
parent
ba2d9bcd93
commit
739f02d7c0
|
@ -0,0 +1 @@
|
|||
Doug Coleman
|
|
@ -0,0 +1,6 @@
|
|||
! Copyright (C) 2008 Your name.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: tools.test io.files.listing strings kernel ;
|
||||
IN: io.files.listing.tests
|
||||
|
||||
[ ] [ "" directory. ] unit-test
|
|
@ -0,0 +1,39 @@
|
|||
! Copyright (C) 2008 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays combinators io io.files kernel
|
||||
math.parser sequences system vocabs.loader calendar ;
|
||||
|
||||
IN: io.files.listing
|
||||
|
||||
: ls-time ( timestamp -- string )
|
||||
[ hour>> ] [ minute>> ] bi
|
||||
[ number>string 2 CHAR: 0 pad-left ] bi@ ":" swap 3append ;
|
||||
|
||||
: ls-timestamp ( timestamp -- string )
|
||||
[ month>> month-abbreviation ]
|
||||
[ day>> number>string 2 CHAR: \s pad-left ]
|
||||
[
|
||||
dup year>> dup now year>> =
|
||||
[ drop ls-time ] [ nip number>string ] if
|
||||
5 CHAR: \s pad-left
|
||||
] tri 3array " " join ;
|
||||
|
||||
: read>string ( ? -- string ) "r" "-" ? ; inline
|
||||
|
||||
: write>string ( ? -- string ) "w" "-" ? ; inline
|
||||
|
||||
HOOK: execute>string os ( ? -- string )
|
||||
|
||||
M: object execute>string ( ? -- string ) "x" "-" ? ; inline
|
||||
|
||||
HOOK: permissions-string os ( -- str )
|
||||
|
||||
HOOK: (directory.) os ( path -- lines )
|
||||
|
||||
: directory. ( path -- )
|
||||
[ (directory.) ] with-directory-files [ print ] each ;
|
||||
|
||||
{
|
||||
{ [ os unix? ] [ "io.files.listing.unix" ] }
|
||||
{ [ os windows? ] [ "io.files.listing.windows" ] }
|
||||
} cond require
|
|
@ -0,0 +1 @@
|
|||
unportable
|
|
@ -0,0 +1 @@
|
|||
Doug Coleman
|
|
@ -0,0 +1 @@
|
|||
unportable
|
|
@ -0,0 +1,41 @@
|
|||
! Copyright (C) 2008 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors combinators kernel system unicode.case
|
||||
io.unix.files io.files.listing generalizations ;
|
||||
IN: io.files.listing.unix
|
||||
|
||||
M: unix execute-string ( str bools -- str' )
|
||||
swap {
|
||||
{ { t t } [ >lower ] }
|
||||
{ { t f } [ >upper ] }
|
||||
{ { f t } [ drop "x" ] }
|
||||
[ 2drop "-" ]
|
||||
} case ;
|
||||
|
||||
M: unix permissions-string ( permissions -- str )
|
||||
{
|
||||
[ type>> file-type>ch 1string ]
|
||||
[ user-read? read>string ]
|
||||
[ user-write? write>string ]
|
||||
[ [ uid? ] [ user-execute? ] bi 2array "s" execute-string ]
|
||||
[ group-read? read>string ]
|
||||
[ group-write? write>string ]
|
||||
[ [ gid? ] [ group-execute? ] bi 2array "s" execute-string ]
|
||||
[ other-read? read>string ]
|
||||
[ other-write? write>string ]
|
||||
[ [ sticky? ] [ other-execute? ] bi 2array "t" execute-string ]
|
||||
} cleave 10 narray concat ;
|
||||
|
||||
M: unix ls ( path -- lines )
|
||||
[ [
|
||||
dup file-info
|
||||
{
|
||||
[ permissions-string ]
|
||||
[ nlink>> number>string 3 CHAR: \s pad-left ]
|
||||
! [ uid>> ]
|
||||
! [ gid>> ]
|
||||
[ size>> number>string 15 CHAR: \s pad-left ]
|
||||
[ modified>> ls-timestamp ]
|
||||
} cleave 4 narray swap suffix " " join
|
||||
] map
|
||||
] with-group-cache ] with-user-cache ;
|
|
@ -0,0 +1 @@
|
|||
Doug Coleman
|
|
@ -0,0 +1 @@
|
|||
unportable
|
|
@ -0,0 +1,21 @@
|
|||
! Copyright (C) 2008 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors calendar.format combinators io.files
|
||||
kernel math.parser sequences splitting system io.files.listing
|
||||
generalizations ;
|
||||
IN: io.files.listing.windows
|
||||
|
||||
: directory-or-size ( file-info -- str )
|
||||
dup directory? [
|
||||
drop "<DIR>" 20 CHAR: \s pad-right
|
||||
] [
|
||||
size>> number>string 20 CHAR: \s pad-left
|
||||
] if ;
|
||||
|
||||
M: windows (directory.) ( entries -- lines )
|
||||
[
|
||||
dup file-info {
|
||||
[ modified>> timestamp>ymdhms ]
|
||||
[ directory-or-size ]
|
||||
} cleave 2 narray swap suffix " " join
|
||||
] map ;
|
Loading…
Reference in New Issue