File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
lib/Terminal/Widgets/Volatile Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 5858 "Terminal::Widgets::Utils::Color" : " lib/Terminal/Widgets/Utils/Color.rakumod" ,
5959 "Terminal::Widgets::Viewer::Log" : " lib/Terminal/Widgets/Viewer/Log.rakumod" ,
6060 "Terminal::Widgets::Viz::SmokeChart" : " lib/Terminal/Widgets/Viz/SmokeChart.rakumod" ,
61+ "Terminal::Widgets::Volatile::DirTree" : " lib/Terminal/Widgets/Volatile/DirTree.rakumod" ,
6162 "Terminal::Widgets::Widget" : " lib/Terminal/Widgets/Widget.rakumod"
6263 },
6364 "resources" : [
Original file line number Diff line number Diff line change 1+ # ABSTRACT: A volatile data structure representing a live directory tree
2+
3+ unit module Terminal::Widgets::Volatile::DirTree ;
4+
5+
6+ role Node {
7+ has IO ::Path: D () $ . path is required ;
8+ has Node $ . parent ;
9+
10+ method gist () {
11+ my $ short-name = self .^ name . subst (' Terminal::Widgets::Volatile::' , ' ' );
12+ $ short-name ~ ' :' ~ $ ! path . path
13+ }
14+ }
15+
16+ class Dev does Node {
17+ }
18+
19+ class File does Node {
20+ }
21+
22+ class SymLink does Node {
23+ has IO ::Path: D () $ . target is required ;
24+
25+ method gist () {
26+ self . Node:: gist ~ ' => ' ~ $ ! target . path
27+ }
28+ }
29+
30+ class Dir does Node {
31+ has Node: D @ ! children is built;
32+ has Instant : D $ . cache-time .= from-posix-nanos(0 );
33+
34+ method children (Bool : D : $ refresh = False ) {
35+ # XXXX: For now, just fake real caching and be lazy
36+ if $ refresh || ! $ ! cache-time {
37+ $ ! cache-time = now;
38+ @ ! children = $ ! path . dir . map : {
39+ . d ?? Dir. new ( parent => self , path => $ _ ) !!
40+ . l ?? SymLink. new (parent => self , path => $ _ , target => . readlink) !!
41+ . f ?? File. new ( parent => self , path => $ _ ) !!
42+ . dev ?? Dev. new ( parent => self , path => $ _ ) !!
43+ Node. new ( parent => self , path => $ _ ) ;
44+ };
45+ }
46+ @ ! children
47+ }
48+ }
49+
50+ class Root is Dir {
51+ }
You can’t perform that action at this time.
0 commit comments