Repository: spyder-ide/spyder

Issue:
Change color of matched parens in the IPython console
Hi, is there a way to change the color of matched parenthesis automatic selection in the IPython console? 
I'm using a dark theme, and the white selection that the console is using along with the almost white text that my theme has is making me very difficult to recognize where my cursor is when I'm calling a procedure. Here you can see some screenshots: 
![screenshot from 2017-07-24 17-32-50](https://user-images.githubusercontent.com/4089035/28548091-b4d7eaf6-7097-11e7-81f9-7317a198eb33.png)
![screenshot from 2017-07-24 17-33-15](https://user-images.githubusercontent.com/4089035/28548095-b9c9cd68-7097-11e7-9e72-c21115af0330.png)
It would be nice if the new feature of color scheme matching in the ipython console could cover matched parenthesis and selection text as well.
If there's a way by editing some config file, please let me know. It's kinda frustrating to guess if my cursor is already inside parenthesis or outside.
Or if I could disable matched parens in the ipython console would be nice too.
I'm using:
Spyder 3.2.0
IPython 6.1.0
Python 3.5.2
Ubuntu 16.04


Discussion:
I think that color is hard-coded in qtconsole, the package that we depend on to provide our IPython console. So we'd need to change things there.

We'll see what we can do about this in a future release of qtconsole.
@ccordoba12 I can look into this if you want since it is affecting me as well.
I was hoping for you to say that! Thanks!

Since this is a new feature, please remember to do your PR against master.

El 25/07/17 a las 08:35, Jean-Sébastien Gosselin escribió:
>
> @ccordoba12 <https://github.com/ccordoba12> I can look into this if 
> you want since it is affecting me as well.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub 
> <https://github.com/spyder-ide/spyder/issues/4806#issuecomment-317739037>, 
> or mute the thread 
> <https://github.com/notifications/unsubscribe-auth/AAWS7W775g08uBoDIjuBDYl015ld636lks5sRe8RgaJpZM4Oh1yA>.
>


@ccordoba12 
Firstly, while working on this, I've discovered that unlike the rest of the Spyder application, the colour for highlighting the text is hard coded to light gray with a style sheet in the IPython console. It would be possible to simply remove everything related to `selection_background_color` in [create_qss_style](https://github.com/spyder-ide/spyder/blob/master/spyder/utils/ipython/style.py#L21), so that the highlighting is the same in the IPython console as for the rest of the application.

Secondly, it is possible to set the _matched bracket color_ in the IPython console to the color specified in the preferences directly in the [ShellWidget](https://github.com/spyder-ide/spyder/blob/master/spyder/widgets/ipythonconsole/shell.py#L26) since this property is exposed in the [BracketMatcher ](https://github.com/jupyter/qtconsole/blob/master/qtconsole/bracket_matcher.py#L30) of the `qtconsole`. There is no need to change anything in the qtconsole, only in the ShellWidget. 

That being said, the `BracketMatcher` of the `qtconsole` does not have the ability to highlight _unmatched bracket_ with a different colour like it is done in the editor. To add this functionality, then we would have to add it to the `BracketMatcher`. I think this would not be too complicated since all the logic is already in the [Editor](https://github.com/spyder-ide/spyder/blob/master/spyder/widgets/sourcecode/base.py#L461).

Resolving patch:
diff --git a/spyder/utils/ipython/style.py b/spyder/utils/ipython/style.py
--- a/spyder/utils/ipython/style.py
+++ b/spyder/utils/ipython/style.py
@@ -49,7 +49,6 @@ def give_font_style(is_italic):
         in_prompt_color = 'lime'
         out_prompt_color = 'red'
     background_color = color_scheme['background']
-    selection_background_color = '#ccc'
     error_color = 'red'
     in_prompt_number_font_weight = 'bold'
     out_prompt_number_font_weight = 'bold'
@@ -59,7 +58,6 @@ def give_font_style(is_italic):
     sheet = """QPlainTextEdit, QTextEdit, ControlWidget {{
                                           color: {} ;
                                           background-color: {};
-                                          selection-background-color: {}
                                          }}
               .error {{ color: {}; }}
               .in-prompt {{ color: {}; }}
@@ -70,7 +68,6 @@ def give_font_style(is_italic):
               """
 
     sheet_formatted = sheet.format(font_color, background_color,
-                                   selection_background_color,
                                    error_color,
                                    in_prompt_color, in_prompt_color,
                                    in_prompt_number_font_weight,
diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py
--- a/spyder/widgets/ipythonconsole/shell.py
+++ b/spyder/widgets/ipythonconsole/shell.py
@@ -17,6 +17,7 @@
 from spyder.config.gui import config_shortcut
 from spyder.py3compat import to_text_string
 from spyder.utils import programs
+from spyder.utils import syntaxhighlighters as sh
 from spyder.utils.ipython.style import create_qss_style, create_style_class
 from spyder.widgets.ipythonconsole import (ControlWidget, DebuggingWidget,
                                            HelpWidget, NamepaceBrowserWidget,
@@ -70,6 +71,11 @@ def __init__(self, ipyclient, additional_options, interpreter_versions,
         # To save kernel replies in silent execution
         self._kernel_reply = None
 
+        # Set the color of the matched parentheses here since the qtconsole
+        # uses a hard-coded value that is not modified when the color scheme is
+        # set in the qtconsole constructor. See issue #4806.   
+        self.set_bracket_matcher_color_scheme(self.syntax_style)
+                
     #---- Public API ----------------------------------------------------------
     def set_exit_callback(self):
         """Set exit callback for this shell."""
@@ -110,9 +116,16 @@ def get_cwd(self):
             return
         else:
             self.silent_exec_method(code)
+            
+    def set_bracket_matcher_color_scheme(self, color_scheme):
+        """Set color scheme for matched parentheses."""
+        bsh = sh.BaseSH(parent=self, color_scheme=color_scheme)
+        mpcolor = bsh.get_matched_p_color()
+        self._bracket_matcher.format.setBackground(mpcolor)
 
     def set_color_scheme(self, color_scheme):
         """Set color scheme of the shell."""
+        self.set_bracket_matcher_color_scheme(color_scheme)
         self.style_sheet, dark_color = create_qss_style(color_scheme)
         self.syntax_style = color_scheme
         self._style_sheet_changed()


Test patch: