Skip to content

Commit

Permalink
display symlinks with italic
Browse files Browse the repository at this point in the history
  • Loading branch information
semicontinuity committed Aug 5, 2023
1 parent 2998bdb commit 92fd480
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion fsel/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,16 @@ def list_folders(self, path: Sequence[str]) -> List[Tuple[str, int]]:
full_fs_path = os.path.join(self.root, *path)
try:
result = []
# see DirEntry
for entry in os.scandir(full_fs_path):
if entry.is_dir() and not entry.name.startswith('.'):
result.append((entry.name, entry.stat().st_mode | ItemModel.FLAG_DIRECTORY))
st_mode = entry.stat().st_mode
result.append(
(
entry.name,
(st_mode | ItemModel.FLAG_DIRECTORY) | (ItemModel.FLAG_ITALIC if entry.is_symlink() else 0)
)
)
return sorted(result, key=lambda e: e[0])
except PermissionError:
return []
Expand Down Expand Up @@ -192,13 +199,17 @@ def resolve(self, j, s: AnyStr):

class ItemModel:
FLAG_DIRECTORY = 0x8000
FLAG_ITALIC = 0x10000

def attrs(self, item: Tuple[str, int]):
return item[1]

def is_leaf(self, item: Tuple[str, int]):
return (item[1] & ItemModel.FLAG_DIRECTORY) == 0

def is_italic(self, item: Tuple[str, int]):
return (item[1] & ItemModel.FLAG_ITALIC) != 0

def max_item_text_length(self, items):
return max(len(item[0]) for item in items)

Expand Down Expand Up @@ -257,6 +268,7 @@ def show_real_line(self, item, i):

if match_from != -1:
self.attr_reset()
self.attr_italic(item_model.is_italic(item))
self.attr_color(palette[Colors.C_IDX_REG_FG], palette[Colors.C_IDX_BG])

p_ctx.paint_string(l[:match_from])
Expand All @@ -276,6 +288,7 @@ def show_real_line(self, item, i):
p_ctx.paint_string(l[match_to:])
else:
self.attr_reset()
self.attr_italic(item_model.is_italic(item))
self.attr_color(palette[Colors.C_IDX_REG_FG], palette[Colors.C_IDX_BG])
p_ctx.paint_string(l)

Expand All @@ -300,6 +313,10 @@ def attr_underlined(double: bool):
def attr_not_underlined():
Screen.wr("\x1b[24m")

@staticmethod
def attr_italic(on: bool):
Screen.wr("\x1b[3m" if on else "\x1b[23m")

@staticmethod
def attr_reversed():
Screen.wr("\x1b[7m")
Expand Down

0 comments on commit 92fd480

Please sign in to comment.