summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/InputPrompt.test.tsx
diff options
context:
space:
mode:
authorMatias <[email protected]>2025-07-16 00:35:58 -0300
committerGitHub <[email protected]>2025-07-16 03:35:58 +0000
commitd622e596a14338771bdd43a8812ff7fc02f7ebe8 (patch)
tree81247df10964998cda08187ef11ed63a5aeaa9dc /packages/cli/src/ui/components/InputPrompt.test.tsx
parent0903421b1a1c5b43f4271e779aafa440ffec595c (diff)
feat(cli): clear input buffer on CTRL+C when not executing commands (#1729)
Co-authored-by: Scott Densmore <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/components/InputPrompt.test.tsx')
-rw-r--r--packages/cli/src/ui/components/InputPrompt.test.tsx26
1 files changed, 26 insertions, 0 deletions
diff --git a/packages/cli/src/ui/components/InputPrompt.test.tsx b/packages/cli/src/ui/components/InputPrompt.test.tsx
index 53a2cb0e..e1d68125 100644
--- a/packages/cli/src/ui/components/InputPrompt.test.tsx
+++ b/packages/cli/src/ui/components/InputPrompt.test.tsx
@@ -543,4 +543,30 @@ describe('InputPrompt', () => {
expect(props.buffer.newline).toHaveBeenCalled();
unmount();
});
+
+ it('should clear the buffer on Ctrl+C if it has text', async () => {
+ props.buffer.setText('some text to clear');
+ const { stdin, unmount } = render(<InputPrompt {...props} />);
+ await wait();
+
+ stdin.write('\x03'); // Ctrl+C character
+ await wait();
+
+ expect(props.buffer.setText).toHaveBeenCalledWith('');
+ expect(mockCompletion.resetCompletionState).toHaveBeenCalled();
+ expect(props.onSubmit).not.toHaveBeenCalled();
+ unmount();
+ });
+
+ it('should NOT clear the buffer on Ctrl+C if it is empty', async () => {
+ props.buffer.text = '';
+ const { stdin, unmount } = render(<InputPrompt {...props} />);
+ await wait();
+
+ stdin.write('\x03'); // Ctrl+C character
+ await wait();
+
+ expect(props.buffer.setText).not.toHaveBeenCalled();
+ unmount();
+ });
});