twd-m4sc0 3.0.3__py3-none-any.whl → 3.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- twd/cli.py +5 -2
- twd/data.py +0 -1
- twd/tui.py +7 -3
- twd/utils.py +12 -11
- {twd_m4sc0-3.0.3.dist-info → twd_m4sc0-3.0.4.dist-info}/METADATA +1 -1
- twd_m4sc0-3.0.4.dist-info/RECORD +12 -0
- {twd_m4sc0-3.0.3.dist-info → twd_m4sc0-3.0.4.dist-info}/WHEEL +1 -1
- twd_m4sc0-3.0.3.dist-info/RECORD +0 -12
- {twd_m4sc0-3.0.3.dist-info → twd_m4sc0-3.0.4.dist-info}/entry_points.txt +0 -0
- {twd_m4sc0-3.0.3.dist-info → twd_m4sc0-3.0.4.dist-info}/top_level.txt +0 -0
twd/cli.py
CHANGED
|
@@ -24,10 +24,13 @@ def cli(ctx):
|
|
|
24
24
|
|
|
25
25
|
path = TWDApp(manager=ctx.obj['manager']).run()
|
|
26
26
|
|
|
27
|
+
if not path:
|
|
28
|
+
print("Exiting...")
|
|
29
|
+
exit(0)
|
|
30
|
+
|
|
27
31
|
# write to fd3
|
|
28
32
|
os.write(3, bytes(str(path), "utf-8"))
|
|
29
|
-
|
|
30
|
-
pass
|
|
33
|
+
exit(0)
|
|
31
34
|
|
|
32
35
|
@cli.command()
|
|
33
36
|
@click.argument('path')
|
twd/data.py
CHANGED
twd/tui.py
CHANGED
|
@@ -8,7 +8,7 @@ from textual.color import Color
|
|
|
8
8
|
|
|
9
9
|
from twd.config import Config
|
|
10
10
|
from twd.data import TwdManager
|
|
11
|
-
from twd.utils import
|
|
11
|
+
from twd.utils import fuzzy_search, linear_search
|
|
12
12
|
|
|
13
13
|
class Mode(Enum):
|
|
14
14
|
NORMAL = "normal"
|
|
@@ -177,9 +177,13 @@ class TWDApp(App):
|
|
|
177
177
|
|
|
178
178
|
# TODO: filter entries and repopulate table
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
if query is None:
|
|
181
|
+
self._populate_table()
|
|
182
|
+
return
|
|
183
|
+
|
|
184
|
+
search_result = fuzzy_search(query, all_entries)
|
|
181
185
|
|
|
182
|
-
filtered = [
|
|
186
|
+
filtered = [item[0] for item in search_result]
|
|
183
187
|
|
|
184
188
|
self._populate_table(filtered)
|
|
185
189
|
|
twd/utils.py
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
from rapidfuzz import fuzz
|
|
2
2
|
from typing import List
|
|
3
3
|
|
|
4
|
-
FUZZY_THRESHOLD = 50
|
|
5
|
-
|
|
6
4
|
def normalize(name) -> str:
|
|
7
5
|
return name.lower().replace('-', ' ').replace('_', ' ')
|
|
8
6
|
|
|
9
|
-
def
|
|
7
|
+
def fuzzy_search(query, items, threshold = 50) -> List:
|
|
10
8
|
"""
|
|
11
9
|
query: search input
|
|
12
10
|
items: list of (alias, name)
|
|
11
|
+
threshold: threshold score over which the entries are selected
|
|
13
12
|
|
|
14
|
-
returns: list of (
|
|
13
|
+
returns: list of (entry, score)
|
|
15
14
|
"""
|
|
16
15
|
|
|
17
16
|
# return all items if query is empty
|
|
18
17
|
if not query:
|
|
19
|
-
return [(
|
|
18
|
+
return [(e, 100) for e in items]
|
|
20
19
|
|
|
21
20
|
normalized_query = normalize(query)
|
|
22
21
|
results = []
|
|
23
22
|
|
|
24
23
|
# filtering
|
|
25
|
-
for
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
for entry in items:
|
|
25
|
+
alias, name = normalize(entry.alias), normalize(entry.name)
|
|
26
|
+
|
|
27
|
+
alias_score = fuzz.ratio(normalized_query, alias)
|
|
28
|
+
name_score = fuzz.ratio(normalized_query, name)
|
|
28
29
|
|
|
29
30
|
# choose higher score
|
|
30
31
|
best_score = max(alias_score, name_score)
|
|
31
32
|
|
|
32
33
|
# filter out low scores
|
|
33
|
-
if best_score
|
|
34
|
-
results.append((
|
|
34
|
+
if best_score > threshold:
|
|
35
|
+
results.append((entry, best_score))
|
|
35
36
|
|
|
36
|
-
results.sort(key=lambda x: x[
|
|
37
|
+
results.sort(key=lambda x: x[1], reverse=True)
|
|
37
38
|
|
|
38
39
|
return results
|
|
39
40
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
twd/__init__.py,sha256=76brvw44gXGskDSsajfwk5rvxoRjk4PT99d4qGUs_64,162
|
|
2
|
+
twd/cli.py,sha256=e7weY8SSf6Qp3Z7sigQVnsdO5c-iEyGwzdqap_0jMJg,2626
|
|
3
|
+
twd/config.py,sha256=pGAaurguz1Bv6NxjwKbLBbvJ9tuAVJx_l7tcvd0B84I,1996
|
|
4
|
+
twd/data.py,sha256=bz3uqd8aefaom1Awo40nSFuAlGa3bllVqWLSsG1bWks,4105
|
|
5
|
+
twd/tui.py,sha256=8RTbp4QhbFSIoqnUMuTl5J_qFsZU5KE_bZpHTxpVSSo,6119
|
|
6
|
+
twd/tui.tcss,sha256=GVEtk-fUcAaaGP3I-VjTFUzZocPAEcASDCBNGVoUBWw,778
|
|
7
|
+
twd/utils.py,sha256=xsMa69vAotpNMd3Vp5_F7ELwZCwT-sd45taN7PRI9pE,1201
|
|
8
|
+
twd_m4sc0-3.0.4.dist-info/METADATA,sha256=qK_h_Jvrowt7G5JndPl5BdckqnWmZ7_ftsWZfLzGjME,437
|
|
9
|
+
twd_m4sc0-3.0.4.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
10
|
+
twd_m4sc0-3.0.4.dist-info/entry_points.txt,sha256=KeIDpaQx0GSqgJFYql14wmT3yj_JHTwq7rRsm-mKckc,36
|
|
11
|
+
twd_m4sc0-3.0.4.dist-info/top_level.txt,sha256=B93Li7fIZ4uWoKq8rKVuGPU_MtzyjxxDb0NF96oGZ0o,4
|
|
12
|
+
twd_m4sc0-3.0.4.dist-info/RECORD,,
|
twd_m4sc0-3.0.3.dist-info/RECORD
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
twd/__init__.py,sha256=76brvw44gXGskDSsajfwk5rvxoRjk4PT99d4qGUs_64,162
|
|
2
|
-
twd/cli.py,sha256=Shm8ZeHrPKPr-lbo6Mvb_mjWEH8mYBVlpvZ3OcWb2sw,2550
|
|
3
|
-
twd/config.py,sha256=pGAaurguz1Bv6NxjwKbLBbvJ9tuAVJx_l7tcvd0B84I,1996
|
|
4
|
-
twd/data.py,sha256=YPVU2NhZuDOps-pkquRG9y4GW5RHf46eXIm23rgY_Lo,4131
|
|
5
|
-
twd/tui.py,sha256=2SGGQ5EhjZSun6NrOiU9aC6AQWfjWEZzFZjKlcIQ9vU,6062
|
|
6
|
-
twd/tui.tcss,sha256=GVEtk-fUcAaaGP3I-VjTFUzZocPAEcASDCBNGVoUBWw,778
|
|
7
|
-
twd/utils.py,sha256=F42JxIlqUMLsklQ7_zXoIOPmh872E2pHdu1jGLt6-vw,1144
|
|
8
|
-
twd_m4sc0-3.0.3.dist-info/METADATA,sha256=IB8U5YkNDs3MldgdSy6ffadSt84fFpgT15yz3QIjktg,437
|
|
9
|
-
twd_m4sc0-3.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
-
twd_m4sc0-3.0.3.dist-info/entry_points.txt,sha256=KeIDpaQx0GSqgJFYql14wmT3yj_JHTwq7rRsm-mKckc,36
|
|
11
|
-
twd_m4sc0-3.0.3.dist-info/top_level.txt,sha256=B93Li7fIZ4uWoKq8rKVuGPU_MtzyjxxDb0NF96oGZ0o,4
|
|
12
|
-
twd_m4sc0-3.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|