Skip to content

Commit 496ea79

Browse files
authored
✨ parent dir
(#28)
1 parent 09d9d74 commit 496ea79

File tree

8 files changed

+285
-266
lines changed

8 files changed

+285
-266
lines changed

browsr/_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from __future__ import annotations
66

77
import math
8+
import os
89
import pathlib
910
from copy import copy
10-
from dataclasses import dataclass
11+
from dataclasses import dataclass, field
1112
from os import PathLike
1213
from textwrap import dedent
1314
from typing import Any, ClassVar, Dict, List, Optional, Union
@@ -52,7 +53,7 @@ class TextualAppContext:
5253
App Context Object
5354
"""
5455

55-
file_path: Optional[str] = None
56+
file_path: str = field(default_factory=os.getcwd)
5657
config: Optional[Dict[str, Any]] = None
5758
debug: bool = False
5859
max_file_size: int = 20
@@ -72,7 +73,7 @@ def path(self) -> pathlib.Path:
7273
file_path = file_path[:-4]
7374
file_path = handle_github_url(url=str(file_path))
7475
self.file_path = file_path
75-
if str(self.file_path).endswith("/"):
76+
if str(self.file_path).endswith("/") and len(str(self.file_path)) > 1:
7677
self.file_path = str(self.file_path)[:-1]
7778
kwargs = self.kwargs or {}
7879
PathClass = copy(BrowsrPath)
@@ -111,7 +112,7 @@ def __init__(
111112
like a dictionary to pass into an application
112113
"""
113114
super().__init__()
114-
self.config_object = config_object
115+
self.config_object = config_object or TextualAppContext()
115116
traceback.install(show_locals=True)
116117

117118
@staticmethod

browsr/_cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
browsr command line interface
33
"""
44

5+
import os
56
from typing import Optional, Tuple
67

78
import click
@@ -186,8 +187,12 @@ def browsr(
186187
message=f"Invalid Key/Value pair: `{kwarg}` - must be in the format Key=Value",
187188
param_hint="kwargs",
188189
) from ve
190+
file_path = path or os.getcwd()
189191
config = TextualAppContext(
190-
file_path=path, debug=debug, max_file_size=max_file_size, kwargs=extra_kwargs
192+
file_path=file_path,
193+
debug=debug,
194+
max_file_size=max_file_size,
195+
kwargs=extra_kwargs,
191196
)
192197
app = Browsr(config_object=config)
193198
app.run()

browsr/browsr.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import json
9+
import os
910
import pathlib
1011
import shutil
1112
from os import getenv
@@ -65,6 +66,7 @@ class Browsr(BrowsrTextualApp):
6566
Binding(key="t", action="theme", description="Toggle Theme"),
6667
Binding(key="n", action="linenos", description="Toggle Line Numbers"),
6768
Binding(key="d", action="toggle_dark", description="Toggle Dark Mode"),
69+
Binding(key=".", action="parent_dir", description="Parent Directory"),
6870
]
6971

7072
show_tree = var(True)
@@ -189,7 +191,7 @@ def _handle_file_size(self, file_info: FileInfo) -> None:
189191
Handle a File Size
190192
"""
191193
file_size_mb = file_info.size / 1000 / 1000
192-
too_large = file_size_mb >= self.config_object.max_file_size # type: ignore[union-attr]
194+
too_large = file_size_mb >= self.config_object.max_file_size
193195
exception = (
194196
True
195197
if is_local_path(file_info.file) and ".csv" in file_info.file.suffixes
@@ -388,9 +390,20 @@ def action_download_file(self) -> None:
388390
self.table_view.display = False
389391
self.confirmation_window.display = True
390392

393+
def action_parent_dir(self) -> None:
394+
"""
395+
Go to the parent directory
396+
"""
397+
new_path = self.config_object.path.parent.resolve()
398+
if new_path != self.config_object.path:
399+
self.config_object.file_path = str(new_path)
400+
self.directory_tree.path = new_path
401+
391402

392403
app = Browsr(
393-
config_object=TextualAppContext(file_path=getenv("BROWSR_PATH"), debug=True)
404+
config_object=TextualAppContext(
405+
file_path=getenv("BROWSR_PATH", os.getcwd()), debug=True
406+
)
394407
)
395408

396409
if __name__ == "__main__":

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies = [
2020
"rich~=13.5.2",
2121
"rich-click~=1.5.2",
2222
"rich-pixels~=2.1.1",
23-
"textual==0.36.0",
23+
"textual==0.39.0",
2424
"textual-universal-directorytree~=1.0.1",
2525
"Pillow>=9.1.0",
2626
"PyMuPDF~=1.22.3"
@@ -75,7 +75,7 @@ dependencies = [
7575
"mkdocs-literate-nav~=0.6.0",
7676
"mkdocs-section-index~=0.3.5",
7777
"black~=23.3.0",
78-
"ruff~=0.0.261",
78+
"ruff~=0.0.292",
7979
"mypy~=1.2.0",
8080
"pandas-stubs~=2.0.0.230412",
8181
"pip-tools~=6.13.0",

requirements/requirements-dev.txt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,24 +1521,24 @@ rsa==4.9 \
15211521
--hash=sha256:90260d9058e514786967344d0ef75fa8727eed8a7d2e43ce9f4bcf1b536174f7 \
15221522
--hash=sha256:e38464a49c6c85d7f1351b0126661487a7e0a14a50f1675ec50eb34d4f20ef21
15231523
# via google-auth
1524-
ruff==0.0.280 \
1525-
--hash=sha256:2dae8f2d9c44c5c49af01733c2f7956f808db682a4193180dedb29dd718d7bbe \
1526-
--hash=sha256:2e7c15828d09f90e97bea8feefcd2907e8c8ce3a1f959c99f9b4b3469679f33c \
1527-
--hash=sha256:37359cd67d2af8e09110a546507c302cbea11c66a52d2a9b6d841d465f9962d4 \
1528-
--hash=sha256:48ed5aca381050a4e2f6d232db912d2e4e98e61648b513c350990c351125aaec \
1529-
--hash=sha256:4a7d52457b5dfcd3ab24b0b38eefaead8e2dca62b4fbf10de4cd0938cf20ce30 \
1530-
--hash=sha256:581c43e4ac5e5a7117ad7da2120d960a4a99e68ec4021ec3cd47fe1cf78f8380 \
1531-
--hash=sha256:5f972567163a20fb8c2d6afc60c2ea5ef8b68d69505760a8bd0377de8984b4f6 \
1532-
--hash=sha256:7008fc6ca1df18b21fa98bdcfc711dad5f94d0fc3c11791f65e460c48ef27c82 \
1533-
--hash=sha256:7784e3606352fcfb193f3cd22b2e2117c444cb879ef6609ec69deabd662b0763 \
1534-
--hash=sha256:7a37dab70114671d273f203268f6c3366c035fe0c8056614069e90a65e614bfc \
1535-
--hash=sha256:83e8f372fa5627eeda5b83b5a9632d2f9c88fc6d78cead7e2a1f6fb05728d137 \
1536-
--hash=sha256:8ffa7347ad11643f29de100977c055e47c988cd6d9f5f5ff83027600b11b9189 \
1537-
--hash=sha256:b7de5b8689575918e130e4384ed9f539ce91d067c0a332aedef6ca7188adac2d \
1538-
--hash=sha256:bd58af46b0221efb95966f1f0f7576df711cb53e50d2fdb0e83c2f33360116a4 \
1539-
--hash=sha256:d878370f7e9463ac40c253724229314ff6ebe4508cdb96cb536e1af4d5a9cd4f \
1540-
--hash=sha256:ef6ee3e429fd29d6a5ceed295809e376e6ece5b0f13c7e703efaf3d3bcb30b96 \
1541-
--hash=sha256:fe7118c1eae3fda17ceb409629c7f3b5a22dffa7caf1f6796776936dca1fe653
1524+
ruff==0.0.292 \
1525+
--hash=sha256:02f29db018c9d474270c704e6c6b13b18ed0ecac82761e4fcf0faa3728430c96 \
1526+
--hash=sha256:1093449e37dd1e9b813798f6ad70932b57cf614e5c2b5c51005bf67d55db33ac \
1527+
--hash=sha256:69654e564342f507edfa09ee6897883ca76e331d4bbc3676d8a8403838e9fade \
1528+
--hash=sha256:6bdfabd4334684a4418b99b3118793f2c13bb67bf1540a769d7816410402a205 \
1529+
--hash=sha256:6c3c91859a9b845c33778f11902e7b26440d64b9d5110edd4e4fa1726c41e0a4 \
1530+
--hash=sha256:7f67a69c8f12fbc8daf6ae6d36705037bde315abf8b82b6e1f4c9e74eb750f68 \
1531+
--hash=sha256:87616771e72820800b8faea82edd858324b29bb99a920d6aa3d3949dd3f88fb0 \
1532+
--hash=sha256:8e087b24d0d849c5c81516ec740bf4fd48bf363cfb104545464e0fca749b6af9 \
1533+
--hash=sha256:9889bac18a0c07018aac75ef6c1e6511d8411724d67cb879103b01758e110a81 \
1534+
--hash=sha256:aa7c77c53bfcd75dbcd4d1f42d6cabf2485d2e1ee0678da850f08e1ab13081a8 \
1535+
--hash=sha256:ac153eee6dd4444501c4bb92bff866491d4bfb01ce26dd2fff7ca472c8df9ad0 \
1536+
--hash=sha256:b76deb3bdbea2ef97db286cf953488745dd6424c122d275f05836c53f62d4016 \
1537+
--hash=sha256:be8eb50eaf8648070b8e58ece8e69c9322d34afe367eec4210fdee9a555e4ca7 \
1538+
--hash=sha256:e854b05408f7a8033a027e4b1c7f9889563dd2aca545d13d06711e5c39c3d003 \
1539+
--hash=sha256:f160b5ec26be32362d0774964e218f3fcf0a7da299f7e220ef45ae9e3e67101a \
1540+
--hash=sha256:f27282bedfd04d4c3492e5c3398360c9d86a295be00eccc63914438b4ac8a83c \
1541+
--hash=sha256:f4476f1243af2d8c29da5f235c13dca52177117935e1f9393f9d90f9833f69e4
15421542
# via -r requirements.in
15431543
s3fs==2023.6.0 \
15441544
--hash=sha256:63fd8ddf05eb722de784b7b503196107f2a518061298cf005a8a4715b4d49117 \
@@ -1554,9 +1554,9 @@ six==1.16.0 \
15541554
# isodate
15551555
# python-dateutil
15561556
# vcrpy
1557-
textual==0.36.0 \
1558-
--hash=sha256:7d04880bee0274f8cdf05cbe22d9effad3efa458676af2c431997a6d4576005c \
1559-
--hash=sha256:fbfc799a55938cfade6cfbf7c5ae3c3e5fc87ff9deaaed788a6dcefe72245451
1557+
textual==0.39.0 \
1558+
--hash=sha256:4103c0cb4e87bf9f87f4960213d3c1c33fbe7301a1a1c2df0903ecb62212983c \
1559+
--hash=sha256:bf98d7eb5a8a39ed87488640e2a18b2825dd340d36eab6193c9a47af98a3b818
15601560
# via
15611561
# -r requirements.in
15621562
# textual-dev

requirements/requirements-prod.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,9 +988,9 @@ six==1.16.0 \
988988
# google-auth
989989
# isodate
990990
# python-dateutil
991-
textual==0.36.0 \
992-
--hash=sha256:7d04880bee0274f8cdf05cbe22d9effad3efa458676af2c431997a6d4576005c \
993-
--hash=sha256:fbfc799a55938cfade6cfbf7c5ae3c3e5fc87ff9deaaed788a6dcefe72245451
991+
textual==0.39.0 \
992+
--hash=sha256:4103c0cb4e87bf9f87f4960213d3c1c33fbe7301a1a1c2df0903ecb62212983c \
993+
--hash=sha256:bf98d7eb5a8a39ed87488640e2a18b2825dd340d36eab6193c9a47af98a3b818
994994
# via
995995
# -r requirements.in
996996
# textual-universal-directorytree

0 commit comments

Comments
 (0)