dymokomi/luced
Source of release 0.4.1
0.4.1 / src / workspace / explorer.luc
from luce_std import files
from luce_std.files import FileKind
import workspace.paths as paths
pub struct Entry:
pub let name: str
pub let path: str
pub let directory: bool
pub class Explorer:
pub var directory: str
pub var entries: list[Entry]
pub var show_hidden: bool = false
## Absolute paths a project marks as generated; hidden unless show_hidden.
pub var hidden_paths: list[str]
pub func init(self, directory: str) -> unit!:
self.entries = []
self.hidden_paths = []
self.show_hidden = false
self.directory = files.canonical(directory)
self.open(self.directory)
pub func open(self, path: str) -> unit!:
let absolute = files.canonical(path)
var directories: list[Entry] = []
var regular: list[Entry] = []
for name in files.list(absolute):
if name in [".DS_Store", "__pycache__", ".", ".."]:
continue
if name.starts_with(".") and not self.show_hidden:
continue
let full = paths.join(absolute, name)
if full in self.hidden_paths and not self.show_hidden:
continue
let kind = files.metadata(full).kind catch failure: continue
if kind == FileKind.directory:
directories.append(Entry(name, full, true))
elif kind == FileKind.regular:
regular.append(Entry(name, full, false))
let parent = paths.parent(absolute)
self.entries = ([Entry("..", parent, true)] if parent != absolute else []) + directories + regular
self.directory = absolute