Skip to content

Commit 57727f4

Browse files
committed
fix: extract border label and fix formatting
1 parent cd571c0 commit 57727f4

4 files changed

Lines changed: 46 additions & 34 deletions

File tree

apick.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def format_for_fzf(endpoints: list[dict]) -> str:
136136
}
137137
color = colors.get(ep["method"], "\033[0m")
138138
reset = "\033[0m"
139-
lines.append(f"{i:04d} {color}{method}{reset} {path} {summary}")
139+
lines.append(f"{i:04d}\t{color}{method}{reset} {path} {summary}")
140140
return "\n".join(lines)
141141

142142

@@ -245,6 +245,9 @@ def pick_endpoint(endpoints: list[dict], spec: dict, script_path: str) -> dict |
245245
json.dump(spec, spec_file)
246246
spec_file_name = spec_file.name
247247

248+
api_title = spec.get("info", {}).get("title")
249+
border_label = f" apick — {api_title} " if api_title else " apick "
250+
248251
try:
249252
preview_cmd = (
250253
f"{sys.executable} {script_path} --_preview {{1}} --_spec-file {spec_file_name}"
@@ -255,11 +258,18 @@ def pick_endpoint(endpoints: list[dict], spec: dict, script_path: str) -> dict |
255258
"fzf",
256259
"--ansi",
257260
"--reverse",
258-
"--nth", "2..",
259-
"--with-nth", "2..",
260-
"--border", "rounded",
261-
"--border-label", " apick ",
262-
"--pointer", "▶",
261+
"--delimiter",
262+
"\t",
263+
"--nth",
264+
"2..",
265+
"--with-nth",
266+
"2..",
267+
"--border",
268+
"rounded",
269+
"--border-label",
270+
border_label,
271+
"--pointer",
272+
"▶",
263273
"--header",
264274
"Select an endpoint (type to search)",
265275
"--preview",
@@ -511,7 +521,7 @@ def format_history_for_fzf(entries: list[dict]) -> str:
511521
url = entry.get("url", "")
512522
summary = entry.get("summary", "")
513523
lines.append(
514-
f"{real_idx:04d} {ts} {color}{method:7s}{reset} [{status_str:>3s}] {url} {summary}"
524+
f"{real_idx:04d}\t{ts} {color}{method:7s}{reset} [{status_str:>3s}] {url} {summary}"
515525
)
516526
return "\n".join(lines)
517527

@@ -525,11 +535,18 @@ def pick_history_entry(entries: list[dict]) -> dict | None:
525535
"fzf",
526536
"--ansi",
527537
"--reverse",
528-
"--nth", "2..",
529-
"--with-nth", "2..",
530-
"--border", "rounded",
531-
"--border-label", " history ",
532-
"--pointer", "▶",
538+
"--delimiter",
539+
"\t",
540+
"--nth",
541+
"2..",
542+
"--with-nth",
543+
"2..",
544+
"--border",
545+
"rounded",
546+
"--border-label",
547+
" history ",
548+
"--pointer",
549+
"▶",
533550
"--header",
534551
"Select a request to replay (type to search)",
535552
"--preview",

demo.gif

381 KB
Loading

demo.tape

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,33 @@ Set FontSize 16
88
Set Width 1200
99
Set Height 700
1010
Set Padding 20
11-
Set TypingSpeed 50ms
11+
Set TypingSpeed 30ms
1212
Set Theme "Catppuccin Mocha"
1313
Set WindowBar Colorful
1414
Set WindowBarSize 40
1515

1616
Sleep 500ms
1717

1818
# Launch apick with the Petstore OpenAPI spec
19-
Type "apick https://petstore3.swagger.io/api/v3/openapi.json"
19+
Type "uv run apick https://petstore3.swagger.io/api/v3/openapi.json"
2020
Sleep 300ms
2121
Enter
2222

23-
# Wait for spec download + fzf to appear
24-
Sleep 6s
25-
26-
# Browse endpoints (scroll down to show the list)
27-
Down
28-
Sleep 300ms
29-
Down
30-
Sleep 300ms
31-
Down
32-
Sleep 300ms
33-
Down
34-
Sleep 500ms
23+
# Wait for uv startup + spec download + fzf to appear
24+
Sleep 8s
3525

3626
# Search for GET /pet/{petId}
3727
Type "GET petId"
38-
Sleep 2s
28+
Sleep 1s
3929

4030
# Select the endpoint
4131
Enter
42-
Sleep 1.5s
32+
Sleep 2s
4333

4434
# Enter the petId path parameter
4535
Type "7"
46-
Sleep 300ms
36+
Sleep 200ms
4737
Enter
4838

4939
# Wait for the API response
50-
Sleep 5s
40+
Sleep 3s

tests/test_apick.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ def test_alignment_and_indexing(self):
150150
output = apick.format_for_fzf(eps)
151151
lines = output.split("\n")
152152
assert len(lines) == 2
153-
assert lines[0].startswith("0000 ")
154-
assert lines[1].startswith("0001 ")
153+
assert lines[0].startswith("0000\t")
154+
assert lines[1].startswith("0001\t")
155155

156156
def test_color_codes(self):
157157
eps = [
@@ -448,8 +448,13 @@ def test_format_history_colors(self):
448448

449449
def test_format_history_null_status_shows_err(self):
450450
entries = [
451-
{"method": "GET", "url": "https://a.com", "timestamp": "",
452-
"status_code": None, "summary": ""},
451+
{
452+
"method": "GET",
453+
"url": "https://a.com",
454+
"timestamp": "",
455+
"status_code": None,
456+
"summary": "",
457+
},
453458
]
454459
output = apick.format_history_for_fzf(entries)
455460
assert "err" in output

0 commit comments

Comments
 (0)