Skip to content

Commit

Permalink
fix bug in load
Browse files Browse the repository at this point in the history
  • Loading branch information
Asugawara committed Mar 14, 2024
1 parent 817cf64 commit 8816682
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions pgcs/custom_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def _(event: KeyPressEvent) -> None:
def custom_select(
choices: Dict[str, Entry], max_preview_height: int = 10, **kwargs: Any
) -> str:
print(choices)
text_area = TextArea(prompt="QUERY> ", multiline=False)

def filter_candidates(choices: List[str]) -> List[Tuple[str, str]]:
Expand Down
19 changes: 13 additions & 6 deletions pgcs/file_system/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ def get(self, entry_name: str, default: Optional[Entry] = None) -> Optional[Entr
return self._children.get(entry_name, default)

def add(self, entry: Entry) -> None:
if entry.path().startswith(self.path()):
if entry.name and entry.path().startswith(self.path()):
if entry.name not in self._children:
self._children[entry.name] = entry

def load(self, force: bool = False) -> None:
if not self._children or force:
if force:
self._children = {}
if not self._children:
for _, dirnames, filenames in gfs.walk(self.path(), maxdepth=1):
print(f"{dirnames=}, {filenames=}")
for dirname in dirnames:
self.add(Directory(dirname, self))
for filename in filenames:
Expand Down Expand Up @@ -95,17 +98,21 @@ def get(self, entry_name: str, default: Optional[Entry] = None) -> Optional[Entr
return self._children.get(entry_name, default)

def add(self, entry: Entry) -> None:
if entry.path().startswith(self.path()):
if entry.name and entry.path().startswith(self.path()):
if entry.name not in self._children:
self._children[entry.name] = entry

def load(self, force: bool = False) -> None:
if not self._children or force:
if force:
self._children = {}
if not self._children:
for _, dirnames, filenames in gfs.walk(self.path(), maxdepth=1):
for dirname in dirnames:
self.add(Directory(dirname, self))
if dirname:
self.add(Directory(dirname, self))
for filename in filenames:
self.add(File(filename, self))
if filename:
self.add(File(filename, self))

def ls(self) -> List[str]:
return [entry.path() for entry in self._children.values()]
Expand Down

0 comments on commit 8816682

Please sign in to comment.