mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-24 06:56:42 +00:00
Merge pull request #1173 from GNS3/console-tests
Windows console bugfix tests
This commit is contained in:
commit
7492899b95
@ -19,6 +19,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
import inspect
|
||||||
|
import io
|
||||||
|
|
||||||
from prompt_toolkit import prompt
|
from prompt_toolkit import prompt
|
||||||
from prompt_toolkit.history import InMemoryHistory
|
from prompt_toolkit.history import InMemoryHistory
|
||||||
@ -29,6 +30,7 @@ from prompt_toolkit.interface import CommandLineInterface
|
|||||||
from prompt_toolkit.layout.screen import Size
|
from prompt_toolkit.layout.screen import Size
|
||||||
from prompt_toolkit.shortcuts import create_prompt_application, create_asyncio_eventloop
|
from prompt_toolkit.shortcuts import create_prompt_application, create_asyncio_eventloop
|
||||||
from prompt_toolkit.terminal.vt100_output import Vt100_Output
|
from prompt_toolkit.terminal.vt100_output import Vt100_Output
|
||||||
|
from prompt_toolkit.input import StdinInput
|
||||||
|
|
||||||
from .telnet_server import AsyncioTelnetServer, TelnetConnection
|
from .telnet_server import AsyncioTelnetServer, TelnetConnection
|
||||||
from .input_stream import InputStream
|
from .input_stream import InputStream
|
||||||
@ -151,6 +153,24 @@ class EmbedShell:
|
|||||||
return commands
|
return commands
|
||||||
|
|
||||||
|
|
||||||
|
class PatchedStdinInput(StdinInput):
|
||||||
|
"""
|
||||||
|
`prompt_toolkit.input.StdinInput` checks whether stdin is tty or not, we don't need do that.
|
||||||
|
Fixes issue when PyCharm runs own terminal without emulation.
|
||||||
|
https://github.com/GNS3/gns3-server/issues/1172
|
||||||
|
"""
|
||||||
|
def __init__(self, stdin=None):
|
||||||
|
self.stdin = stdin or sys.stdin
|
||||||
|
try:
|
||||||
|
self.stdin.fileno()
|
||||||
|
except io.UnsupportedOperation:
|
||||||
|
if 'idlelib.run' in sys.modules:
|
||||||
|
raise io.UnsupportedOperation(
|
||||||
|
'Stdin is not a terminal. Running from Idle is not supported.')
|
||||||
|
else:
|
||||||
|
raise io.UnsupportedOperation('Stdin is not a terminal.')
|
||||||
|
|
||||||
|
|
||||||
class UnstoppableEventLoop(EventLoop):
|
class UnstoppableEventLoop(EventLoop):
|
||||||
"""
|
"""
|
||||||
Partially fake event loop which cannot be stopped by CommandLineInterface
|
Partially fake event loop which cannot be stopped by CommandLineInterface
|
||||||
@ -190,12 +210,18 @@ class ShellConnection(TelnetConnection):
|
|||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def connected(self):
|
def connected(self):
|
||||||
|
# prompt_toolkit internally checks if it's on windows during output rendering but
|
||||||
|
# we need to force that we use Vt100_Output not Win32_Output
|
||||||
|
from prompt_toolkit import renderer
|
||||||
|
renderer.is_windows = lambda: False
|
||||||
|
|
||||||
def get_size():
|
def get_size():
|
||||||
return self._size
|
return self._size
|
||||||
|
|
||||||
self._cli = CommandLineInterface(
|
self._cli = CommandLineInterface(
|
||||||
application=create_prompt_application(self._shell.prompt),
|
application=create_prompt_application(self._shell.prompt),
|
||||||
eventloop=UnstoppableEventLoop(create_asyncio_eventloop(self._loop)),
|
eventloop=UnstoppableEventLoop(create_asyncio_eventloop(self._loop)),
|
||||||
|
input=PatchedStdinInput(sys.stdin),
|
||||||
output=Vt100_Output(self, get_size))
|
output=Vt100_Output(self, get_size))
|
||||||
|
|
||||||
self._cb = self._cli.create_eventloop_callbacks()
|
self._cb = self._cli.create_eventloop_callbacks()
|
||||||
|
Loading…
Reference in New Issue
Block a user