Skip to content

Commit d89130a

Browse files
Added an option for swapping between dark/light colors.
1 parent 35303d6 commit d89130a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

ptpython/python_input.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from prompt_toolkit.lexers import PygmentsLexer, DynamicLexer, SimpleLexer
2121
from prompt_toolkit.output import ColorDepth
2222
from prompt_toolkit.output.defaults import create_output
23-
from prompt_toolkit.styles import DynamicStyle
23+
from prompt_toolkit.styles import DynamicStyle, SwapLightAndDarkStyleTransformation, ConditionalStyleTransformation
2424
from prompt_toolkit.utils import is_windows
2525
from prompt_toolkit.validation import ConditionalValidator
2626

@@ -191,6 +191,7 @@ def __init__(self,
191191
# with the current input.
192192

193193
self.enable_syntax_highlighting = True
194+
self.swap_light_and_dark = False
194195
self.highlight_matching_parenthesis = False
195196
self.show_sidebar = False # Currently show the sidebar.
196197
self.show_sidebar_help = True # When the sidebar is visible, also show the help text.
@@ -228,6 +229,7 @@ def __init__(self,
228229
self._current_code_style_name = 'win32'
229230

230231
self._current_style = self._generate_style()
232+
self.color_depth = color_depth or ColorDepth.default()
231233

232234
# Options to be configurable from the sidebar.
233235
self.options = self._create_options()
@@ -246,7 +248,7 @@ def __init__(self,
246248
self.output = output or create_output()
247249
self.input = input or create_input(sys.stdin)
248250

249-
self.app = self._create_application(color_depth)
251+
self.app = self._create_application()
250252

251253
if vi_mode:
252254
self.app.editing_mode = EditingMode.VI
@@ -339,7 +341,7 @@ def use_ui_colorscheme(self, name):
339341
self._current_style = self._generate_style()
340342

341343
def _use_color_depth(self, depth):
342-
get_app()._color_depth = depth
344+
self.color_depth = depth
343345

344346
def _generate_style(self):
345347
"""
@@ -479,6 +481,9 @@ def get_values():
479481
simple_option(title='Syntax highlighting',
480482
description='Use colors for syntax highligthing',
481483
field_name='enable_syntax_highlighting'),
484+
simple_option(title='Swap light/dark colors',
485+
description='Swap light and dark colors.',
486+
field_name='swap_light_and_dark'),
482487
Option(title='Code',
483488
description='Color scheme to use for the Python code.',
484489
get_current_value=lambda: self._current_code_style_name,
@@ -493,14 +498,14 @@ def get_values():
493498
),
494499
Option(title='Color depth',
495500
description='Monochrome (1 bit), 16 ANSI colors (4 bit),\n256 colors (8 bit), or 24 bit.',
496-
get_current_value=lambda: COLOR_DEPTHS[get_app().color_depth],
501+
get_current_value=lambda: COLOR_DEPTHS[self.color_depth],
497502
get_values=lambda: dict(
498503
(name, partial(self._use_color_depth, depth)) for depth, name in COLOR_DEPTHS.items())
499504
),
500505
]),
501506
]
502507

503-
def _create_application(self, color_depth):
508+
def _create_application(self):
504509
"""
505510
Create an `Application` instance.
506511
"""
@@ -524,10 +529,13 @@ def _create_application(self, color_depth):
524529
self.extra_key_bindings,
525530
Condition(lambda: not self.show_sidebar))
526531
]),
527-
color_depth=color_depth,
532+
color_depth=lambda: self.color_depth,
528533
paste_mode=Condition(lambda: self.paste_mode),
529534
mouse_support=Condition(lambda: self.enable_mouse_support),
530535
style=DynamicStyle(lambda: self._current_style),
536+
style_transformation=ConditionalStyleTransformation(
537+
SwapLightAndDarkStyleTransformation(),
538+
filter=Condition(lambda: self.swap_light_and_dark)),
531539
include_default_pygments_style=False,
532540
reverse_vi_search_direction=True)
533541

0 commit comments

Comments
 (0)