Skip to content

Commit bbc1d7d

Browse files
committed
✨ FileInfo
1 parent d92e8bb commit bbc1d7d

File tree

3 files changed

+84
-15
lines changed

3 files changed

+84
-15
lines changed

browsr/screens/code_browser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __init__(
6262
self.file_information.file_info = get_file_info(
6363
file_path=self.code_browser.selected_file_path
6464
)
65+
else:
66+
self.file_information.file_info = get_file_info(self.config_object.path)
6567
self.footer = Footer()
6668

6769
def compose(self) -> Iterable[Widget]:

browsr/widgets/files.py

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
from textual.message import Message
88
from textual.reactive import reactive
99
from textual.widget import Widget
10+
from textual_universal_directorytree import (
11+
GitHubTextualPath,
12+
S3TextualPath,
13+
SFTPTextualPath,
14+
is_remote_path,
15+
)
1016

1117
from browsr.utils import FileInfo
1218

@@ -56,23 +62,77 @@ def render(self) -> RenderableType:
5662
"""
5763
Render the Current File Info Bar
5864
"""
59-
if self.file_info is None or not self.file_info.is_file:
60-
return Text("")
61-
status_string = "🗄️️️ " + self._convert_size(self.file_info.size)
65+
status_string = self.render_file_protocol()
66+
if self.file_info is None:
67+
return Text(status_string)
68+
elif self.file_info.is_file:
69+
file_options = self.render_file_options()
70+
status_string += file_options
6271
if (
6372
self.file_info.last_modified is not None
6473
and self.file_info.last_modified.timestamp() != 0
6574
):
6675
modify_time = self.file_info.last_modified.strftime("%b %d, %Y %I:%M %p")
67-
status_string += " 📅 " + modify_time
68-
parent_name = self.file_info.file.parent.name
69-
if not parent_name:
70-
parent_name = str(self.file_info.file.parent)
71-
parent_name = parent_name.lstrip(f"{self.file_info.file.protocol}://")
72-
parent_name = parent_name.rstrip("/")
73-
status_string += " 💾 " + self.file_info.file.name + " 📂 " + parent_name
76+
status_string += f" 📅 {modify_time}"
77+
directory_options = self.render_directory_options()
78+
status_string += directory_options
79+
return Text(status_string.strip(), style="dim")
80+
81+
def render_file_options(self) -> str:
82+
"""
83+
Render the file options
84+
"""
85+
status_string = ""
86+
if not self.file_info:
87+
return status_string
88+
if self.file_info.is_file:
89+
file_size = self._convert_size(self.file_info.size)
90+
status_string += f" 🗄️️ {file_size}"
7491
if self.file_info.owner not in ["", None]:
75-
status_string += " 👤 " + self.file_info.owner
92+
status_string += f" 👤 {self.file_info.owner}"
7693
if self.file_info.group.strip() not in ["", None]:
77-
status_string += " 🏠 " + self.file_info.group
78-
return Text(status_string, style="dim")
94+
status_string += f" 🏠 {self.file_info.group}"
95+
return status_string
96+
97+
def render_directory_options(self) -> str:
98+
"""
99+
Render the directory options
100+
"""
101+
status_string = ""
102+
if not self.file_info:
103+
return status_string
104+
if self.file_info.is_file:
105+
directory_name = self.file_info.file.parent.name
106+
if not directory_name or (
107+
self.file_info.file.protocol
108+
and f"{self.file_info.file.protocol}://" in directory_name
109+
):
110+
directory_name = str(self.file_info.file.parent)
111+
directory_name = directory_name.lstrip(
112+
f"{self.file_info.file.protocol}://"
113+
)
114+
directory_name = directory_name.rstrip("/")
115+
status_string += f" 📂 {directory_name}"
116+
status_string += f" 💾 {self.file_info.file.name}"
117+
else:
118+
status_string += f" 📂 {self.file_info.file.name}"
119+
return status_string
120+
121+
def render_file_protocol(self) -> str:
122+
"""
123+
Render the file protocol
124+
"""
125+
status_string = ""
126+
if not self.file_info:
127+
return status_string
128+
if is_remote_path(self.file_info.file):
129+
if isinstance(self.file_info.file, GitHubTextualPath):
130+
protocol = "GitHub"
131+
elif isinstance(self.file_info.file, S3TextualPath):
132+
protocol = "S3"
133+
elif isinstance(self.file_info.file, SFTPTextualPath):
134+
protocol = "SFTP"
135+
else:
136+
protocol = self.file_info.file.protocol
137+
status_string += f"🗂️ {protocol}"
138+
return status_string

browsr/widgets/windows.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,13 @@ class WindowSwitcher(Container):
290290

291291
show_tree: Reactive[bool] = reactive(True)
292292

293-
datatable_extensions: ClassVar[list[str]] = [".csv", ".parquet", ".feather", ".fea"]
293+
datatable_extensions: ClassVar[list[str]] = [
294+
".csv",
295+
".parquet",
296+
".feather",
297+
".fea",
298+
".csv.gz",
299+
]
294300
image_extensions: ClassVar[list[str]] = image_file_extensions.copy()
295301
markdown_extensions: ClassVar[list[str]] = [".md"]
296302
json_extensions: ClassVar[list[str]] = [".json"]
@@ -343,7 +349,8 @@ def render_file(self, file_path: UPath, scroll_home: bool = True) -> None:
343349
Render a file
344350
"""
345351
switch_window = self.static_window
346-
if file_path.suffix.lower() in self.datatable_extensions:
352+
joined_suffixes = "".join(file_path.suffixes).lower()
353+
if joined_suffixes in self.datatable_extensions:
347354
self.datatable_window.refresh_from_file(
348355
file_path=file_path, max_lines=self.config_object.max_lines
349356
)

0 commit comments

Comments
 (0)