Skip to content

Commit eba40d0

Browse files
add test for new stacked hotkeys instructions on narrow screens (#6278)
1 parent d8e56c7 commit eba40d0

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

packages/wrangler/src/__tests__/cli-hotkeys.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,37 @@ describe("Hot Keys", () => {
199199
something 2"
200200
`);
201201
});
202+
203+
it("provides stacked formatted instructions in narrow views", async () => {
204+
const originalColumns = process.stdout.columns;
205+
try {
206+
process.stdout.columns = 30;
207+
208+
const handlerA = vi.fn();
209+
const handlerB = vi.fn();
210+
const handlerC = vi.fn();
211+
const handlerD = vi.fn();
212+
const options = [
213+
{ keys: ["a"], label: "first option", handler: handlerA },
214+
{ keys: ["b"], label: "second option", handler: handlerB },
215+
{ keys: ["c"], label: () => "third option", handler: handlerC },
216+
{ keys: ["d"], label: "disabled", disabled: true, handler: handlerD },
217+
];
218+
219+
// should print instructions immediately
220+
const unregisterHotKeys = registerHotKeys(options);
221+
222+
expect(std.out).toMatchInlineSnapshot(`
223+
"╭─────────────────────╮
224+
│ [a] first option │
225+
│ [b] second option │
226+
│ [c] third option │
227+
╰─────────────────────╯"
228+
`);
229+
unregisterHotKeys();
230+
} finally {
231+
process.stdout.columns = originalColumns;
232+
}
233+
});
202234
});
203235
});

packages/wrangler/src/cli-hotkeys.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ export default function (
1616
/**
1717
* Formats all options, comma-separated, prefixed by the first key in square brackets.
1818
*
19-
* Example output:
19+
* Example output (wide screen):
2020
* ╭─────────────────────────────────────────────────────────╮
2121
* │ [a] first option, [b] second option, [c] third option │
2222
* ╰─────────────────────────────────────────────────────────╯
2323
*
24-
* Limitations:
25-
* - doesn't break nicely across lines
24+
* Example output (narrow screen):
25+
*
26+
* ╭──────────────────────╮
27+
* │ [a] first option, |
28+
* | [b] second option |
29+
* | [c] third option │
30+
* ╰──────────────────────╯
31+
*
2632
*/
2733
function formatInstructions() {
2834
const instructions = options

0 commit comments

Comments
 (0)