From 57e2d407ceb016f273effb8841beefd8d3c1a015 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 13 Dec 2017 17:03:59 -0500 Subject: [PATCH 1/3] Support different colors per completion column. Now colors.completion.fg may be set to a list to specify a different color for each completion column. For example: :set colors.completion.fg [black,blue,white] will use black text for the first column, blue for the second, and white for the third. Setting to a single value still works and behaves as before. The default is unchanged from 'white'. Resolves #1794. --- qutebrowser/completion/completiondelegate.py | 8 +++++--- qutebrowser/config/configdata.yml | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/qutebrowser/completion/completiondelegate.py b/qutebrowser/completion/completiondelegate.py index 6688a2dfa..b4f9c5a33 100644 --- a/qutebrowser/completion/completiondelegate.py +++ b/qutebrowser/completion/completiondelegate.py @@ -138,10 +138,10 @@ class CompletionItemDelegate(QStyledItemDelegate): self._painter.translate(text_rect.left(), text_rect.top()) self._get_textdoc(index) - self._draw_textdoc(text_rect) + self._draw_textdoc(text_rect, index.column()) self._painter.restore() - def _draw_textdoc(self, rect): + def _draw_textdoc(self, rect, col): """Draw the QTextDocument of an item. Args: @@ -156,7 +156,9 @@ class CompletionItemDelegate(QStyledItemDelegate): elif not self._opt.state & QStyle.State_Enabled: color = config.val.colors.completion.category.fg else: - color = config.val.colors.completion.fg + colors = config.val.colors.completion.fg + # if multiple colors are set, use different colors per column + color = colors[col % len(colors)] self._painter.setPen(color) ctx = QAbstractTextDocumentLayout.PaintContext() diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 15be675ae..6d8812c25 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1541,8 +1541,14 @@ zoom.text_only: colors.completion.fg: default: white - type: QtColor - desc: Text color of the completion widget. + type: + name: ListOrValue + valtype: QtColor + desc: >- + Text color of the completion widget. + + May be a single value to specify the color for all columns, or a list + specifying a different color for each column. colors.completion.odd.bg: default: '#444444' From 31c29886932fb007fb704aa9183e8d75f7cfe5b9 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sun, 17 Dec 2017 13:28:00 -0500 Subject: [PATCH 2/3] Fix test_config.test_get for updated config. colors.completion.fg is now a list instead of a QColor. As this test specifically wanted to test a QColor, I just changed it to a different config option. --- tests/unit/config/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 32a7a8119..93686e600 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -385,7 +385,7 @@ class TestConfig: def test_get(self, conf): """Test conf.get() with a QColor (where get/get_obj is different).""" - assert conf.get('colors.completion.fg') == QColor('white') + assert conf.get('colors.completion.category.fg') == QColor('white') @pytest.mark.parametrize('value', [{}, {'normal': {'a': 'nop'}}]) def test_get_bindings(self, config_stub, conf, value): From ef2de8201a7f06c2f5ca8079af40beeb1fa8951f Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Mon, 18 Dec 2017 07:58:26 -0500 Subject: [PATCH 3/3] Fix colors.completion.fg default and description. Update the description to mention the number of columns and change the default to ["white", "white", "white"] to make it more obvious that multiple colors can be specified. This also satisfies the config test that expects the default value for ListOrValue types to be a list. One other test had to be tweaked to use a config option that is still just a QtColor rather than a ListOrValue. While it is possible to provide just two colors, it is "undefined behavior". It will use the first color as the third color, but that is an artifact of the implementation and therefore not documented (though also not an error, as it is harmless). --- qutebrowser/config/configdata.yml | 6 +++--- tests/unit/config/test_config.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 6d8812c25..aca0311fd 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1540,15 +1540,15 @@ zoom.text_only: ## colors colors.completion.fg: - default: white + default: ["white", "white", "white"] type: name: ListOrValue valtype: QtColor desc: >- Text color of the completion widget. - May be a single value to specify the color for all columns, or a list - specifying a different color for each column. + May be a single color to use for all columns or a list of three colors, + one for each column. colors.completion.odd.bg: default: '#444444' diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 93686e600..d8bf73700 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -400,7 +400,7 @@ class TestConfig: assert not conf._mutables def test_get_obj_simple(self, conf): - assert conf.get_obj('colors.completion.fg') == 'white' + assert conf.get_obj('colors.completion.category.fg') == 'white' @pytest.mark.parametrize('option', ['content.headers.custom', 'keyhint.blacklist',