|
7 | 7 | from textual.message import Message
|
8 | 8 | from textual.reactive import reactive
|
9 | 9 | from textual.widget import Widget
|
| 10 | +from textual_universal_directorytree import ( |
| 11 | + GitHubTextualPath, |
| 12 | + S3TextualPath, |
| 13 | + SFTPTextualPath, |
| 14 | + is_remote_path, |
| 15 | +) |
10 | 16 |
|
11 | 17 | from browsr.utils import FileInfo
|
12 | 18 |
|
@@ -56,23 +62,77 @@ def render(self) -> RenderableType:
|
56 | 62 | """
|
57 | 63 | Render the Current File Info Bar
|
58 | 64 | """
|
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 |
62 | 71 | if (
|
63 | 72 | self.file_info.last_modified is not None
|
64 | 73 | and self.file_info.last_modified.timestamp() != 0
|
65 | 74 | ):
|
66 | 75 | 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}" |
74 | 91 | if self.file_info.owner not in ["", None]:
|
75 |
| - status_string += " 👤 " + self.file_info.owner |
| 92 | + status_string += f" 👤 {self.file_info.owner}" |
76 | 93 | 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 |
0 commit comments