20
20
from prompt_toolkit .lexers import PygmentsLexer , DynamicLexer , SimpleLexer
21
21
from prompt_toolkit .output import ColorDepth
22
22
from prompt_toolkit .output .defaults import create_output
23
- from prompt_toolkit .styles import DynamicStyle
23
+ from prompt_toolkit .styles import DynamicStyle , SwapLightAndDarkStyleTransformation , ConditionalStyleTransformation
24
24
from prompt_toolkit .utils import is_windows
25
25
from prompt_toolkit .validation import ConditionalValidator
26
26
@@ -191,6 +191,7 @@ def __init__(self,
191
191
# with the current input.
192
192
193
193
self .enable_syntax_highlighting = True
194
+ self .swap_light_and_dark = False
194
195
self .highlight_matching_parenthesis = False
195
196
self .show_sidebar = False # Currently show the sidebar.
196
197
self .show_sidebar_help = True # When the sidebar is visible, also show the help text.
@@ -228,6 +229,7 @@ def __init__(self,
228
229
self ._current_code_style_name = 'win32'
229
230
230
231
self ._current_style = self ._generate_style ()
232
+ self .color_depth = color_depth or ColorDepth .default ()
231
233
232
234
# Options to be configurable from the sidebar.
233
235
self .options = self ._create_options ()
@@ -246,7 +248,7 @@ def __init__(self,
246
248
self .output = output or create_output ()
247
249
self .input = input or create_input (sys .stdin )
248
250
249
- self .app = self ._create_application (color_depth )
251
+ self .app = self ._create_application ()
250
252
251
253
if vi_mode :
252
254
self .app .editing_mode = EditingMode .VI
@@ -339,7 +341,7 @@ def use_ui_colorscheme(self, name):
339
341
self ._current_style = self ._generate_style ()
340
342
341
343
def _use_color_depth (self , depth ):
342
- get_app (). _color_depth = depth
344
+ self . color_depth = depth
343
345
344
346
def _generate_style (self ):
345
347
"""
@@ -479,6 +481,9 @@ def get_values():
479
481
simple_option (title = 'Syntax highlighting' ,
480
482
description = 'Use colors for syntax highligthing' ,
481
483
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' ),
482
487
Option (title = 'Code' ,
483
488
description = 'Color scheme to use for the Python code.' ,
484
489
get_current_value = lambda : self ._current_code_style_name ,
@@ -493,14 +498,14 @@ def get_values():
493
498
),
494
499
Option (title = 'Color depth' ,
495
500
description = 'Monochrome (1 bit), 16 ANSI colors (4 bit),\n 256 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 ],
497
502
get_values = lambda : dict (
498
503
(name , partial (self ._use_color_depth , depth )) for depth , name in COLOR_DEPTHS .items ())
499
504
),
500
505
]),
501
506
]
502
507
503
- def _create_application (self , color_depth ):
508
+ def _create_application (self ):
504
509
"""
505
510
Create an `Application` instance.
506
511
"""
@@ -524,10 +529,13 @@ def _create_application(self, color_depth):
524
529
self .extra_key_bindings ,
525
530
Condition (lambda : not self .show_sidebar ))
526
531
]),
527
- color_depth = color_depth ,
532
+ color_depth = lambda : self . color_depth ,
528
533
paste_mode = Condition (lambda : self .paste_mode ),
529
534
mouse_support = Condition (lambda : self .enable_mouse_support ),
530
535
style = DynamicStyle (lambda : self ._current_style ),
536
+ style_transformation = ConditionalStyleTransformation (
537
+ SwapLightAndDarkStyleTransformation (),
538
+ filter = Condition (lambda : self .swap_light_and_dark )),
531
539
include_default_pygments_style = False ,
532
540
reverse_vi_search_direction = True )
533
541
0 commit comments