|
19 | 19 | from prompt_toolkit.interface import CommandLineInterface, Application, AcceptAction |
20 | 20 | from prompt_toolkit.key_binding.manager import KeyBindingManager |
21 | 21 | from prompt_toolkit.layout.lexers import PygmentsLexer |
| 22 | +from prompt_toolkit.shortcuts import create_output |
22 | 23 | from prompt_toolkit.styles import DynamicStyle |
23 | 24 | from prompt_toolkit.utils import Callback, is_windows |
24 | 25 | from prompt_toolkit.validation import ConditionalValidator |
@@ -120,7 +121,7 @@ class PythonInput(object): |
120 | 121 |
|
121 | 122 | python_input = PythonInput(...) |
122 | 123 | application = python_input.create_application() |
123 | | - cli = CommandLineInterface(application=application) |
| 124 | + cli = PythonCommandLineInterface(application=application) |
124 | 125 | python_code = cli.run() |
125 | 126 | """ |
126 | 127 | def __init__(self, |
@@ -210,6 +211,7 @@ def __init__(self, |
210 | 211 | self._current_code_style_name = 'win32' |
211 | 212 |
|
212 | 213 | self._current_style = self._generate_style() |
| 214 | + self.true_color = False |
213 | 215 |
|
214 | 216 | # Options to be configurable from the sidebar. |
215 | 217 | self.options = self._create_options() |
@@ -479,6 +481,9 @@ def get_values(): |
479 | 481 | get_values=lambda: dict( |
480 | 482 | (name, partial(self.use_ui_colorscheme, name)) for name in self.ui_styles) |
481 | 483 | ), |
| 484 | + simple_option(title='True color (24 bit)', |
| 485 | + description='Use 24 bit colors instead of 265 colors', |
| 486 | + field_name='true_color'), |
482 | 487 | ]), |
483 | 488 | ] |
484 | 489 |
|
@@ -613,8 +618,15 @@ def on_reset(self, cli): |
613 | 618 |
|
614 | 619 |
|
615 | 620 | class PythonCommandLineInterface(CommandLineInterface): |
616 | | - def __init__(self, eventloop=None, input=None, output=None): |
617 | | - python_input = PythonInput() |
| 621 | + def __init__(self, eventloop=None, python_input=None, input=None, output=None): |
| 622 | + assert python_input is None or isinstance(python_input, PythonInput) |
| 623 | + |
| 624 | + python_input = python_input or PythonInput() |
| 625 | + |
| 626 | + # Make sure that the prompt_toolkit 'renderer' knows about the |
| 627 | + # 'true_color' property of PythonInput. |
| 628 | + if output is None: |
| 629 | + output=create_output(true_color=Condition(lambda: python_input.true_color)) |
618 | 630 |
|
619 | 631 | super(PythonCommandLineInterface, self).__init__( |
620 | 632 | application=python_input.create_application(), |
|
0 commit comments