mirror of
https://github.com/Pythagora-io/gpt-pilot.git
synced 2026-01-10 13:37:55 -05:00
handle KeyboardInterrupt in console UI to raise UIClosedError
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from typing import Optional
|
||||
|
||||
from core.log import get_logger
|
||||
from core.ui.base import ProjectStage, UIBase, UISource, UserInput
|
||||
from core.ui.base import ProjectStage, UIBase, UIClosedError, UISource, UserInput
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
@@ -61,7 +61,7 @@ class PlainConsoleUI(UIBase):
|
||||
try:
|
||||
choice = input("> ").strip()
|
||||
except KeyboardInterrupt:
|
||||
return UserInput(cancelled=True)
|
||||
raise UIClosedError()
|
||||
if not choice and default:
|
||||
choice = default
|
||||
if buttons and choice in buttons:
|
||||
|
||||
@@ -2,7 +2,7 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from core.ui.base import AgentSource
|
||||
from core.ui.base import AgentSource, UIClosedError
|
||||
from core.ui.console import PlainConsoleUI
|
||||
|
||||
|
||||
@@ -77,11 +77,8 @@ async def test_ask_question_interrupted(mock_input):
|
||||
ui = PlainConsoleUI()
|
||||
|
||||
await ui.start()
|
||||
input = await ui.ask_question("Hello, how are you?")
|
||||
|
||||
assert input.cancelled is True
|
||||
assert input.button is None
|
||||
assert input.text is None
|
||||
with pytest.raises(UIClosedError):
|
||||
await ui.ask_question("Hello, how are you?")
|
||||
|
||||
await ui.stop()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user