From 4ae33deebddfd10d542040cf7d6c2c9f78f06068 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 12 Jan 2018 17:24:20 -0500 Subject: [PATCH 01/14] add handler for qute://bindings --- qutebrowser/browser/qutescheme.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 8bcb7ff37..09ddba850 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -37,7 +37,7 @@ from PyQt5.QtCore import QUrlQuery, QUrl import qutebrowser from qutebrowser.config import config, configdata, configexc, configdiff from qutebrowser.utils import (version, utils, jinja, log, message, docutils, - objreg, urlutils) + objreg, urlutils, usertypes) from qutebrowser.misc import objects @@ -423,6 +423,20 @@ def _qute_settings_set(url): return 'text/html', b'error: ' + str(e).encode('utf-8') +@add_handler('bindings') +def qute_bindings(url): + """Handler for qute://bindings View qute bindings.""" + + bindings = {} + html = '' + for mode in "normal hint command insert passthrough".split(): + bindings[mode] = config.key_instance.get_bindings_for(mode) + + html = jinja.render('bindings.html', title='bindings', + bindings=bindings) + return 'text/html', html + + @add_handler('settings') def qute_settings(url): """Handler for qute://settings. View/change qute configuration.""" From 8940e05baf210bdeb9e24c7c0125d0e5b12a3e36 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 12 Jan 2018 17:27:44 -0500 Subject: [PATCH 02/14] bind without agruments shows current bindings --- qutebrowser/config/configcommands.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/configcommands.py b/qutebrowser/config/configcommands.py index 7d9adb475..8b6c3ce3f 100644 --- a/qutebrowser/config/configcommands.py +++ b/qutebrowser/config/configcommands.py @@ -96,7 +96,8 @@ class ConfigCommands: @cmdutils.register(instance='config-commands', maxsplit=1, no_cmd_split=True, no_replace_variables=True) @cmdutils.argument('command', completion=configmodel.bind) - def bind(self, key, command=None, *, mode='normal', default=False): + @cmdutils.argument('win_id', win_id=True) + def bind(self, win_id, key=None, command=None, *, mode='normal', default=False): """Bind a key to a command. Args: @@ -108,6 +109,13 @@ class ConfigCommands: available modes. default: If given, restore a default binding. """ + + if key is None: + tabbed_browser = objreg.get('tabbed-browser', scope='window', + window=win_id) + tabbed_browser.openurl(QUrl('qute://bindings'), newtab=True) + return + if command is None: if default: # :bind --default: Restore default From 3a7ac51a0018afbd5e6c8cf1def2799d013e17cb Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 12 Jan 2018 17:28:56 -0500 Subject: [PATCH 03/14] html template to render qute://bindings --- qutebrowser/html/bindings.html | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 qutebrowser/html/bindings.html diff --git a/qutebrowser/html/bindings.html b/qutebrowser/html/bindings.html new file mode 100644 index 000000000..29c3f1883 --- /dev/null +++ b/qutebrowser/html/bindings.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} + +{% block style %} +html { margin:20px; } +table { width:100%; border: 1px solid grey; border-collapse: collapse; margin:10px; } +tr,td,p { margin:0; padding: 1px; } +th, td { border: 1px solid grey; } +th { background: lightgrey; } +th pre { color: grey; text-align: left; } +.key { width: 25%; } +.command { width: 75% } +{% endblock %} + +{% block content %} +

{{ title }}

+{% for mode, binding in bindings.items() %} +

Mode = {{ mode }}

+ + + + + + {% for key,command in binding.items() %} + + + + + {% endfor %} +
KeyCommand
+

{{ key }}

+
+

{{ command }}

+
+{% endfor %} + +{% endblock %} From 1e8694f3cc043179bac84b27d01c2d3537ce65aa Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 12 Jan 2018 17:35:04 -0500 Subject: [PATCH 04/14] remove unused module --- qutebrowser/browser/qutescheme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 09ddba850..3d80c7b37 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -37,7 +37,7 @@ from PyQt5.QtCore import QUrlQuery, QUrl import qutebrowser from qutebrowser.config import config, configdata, configexc, configdiff from qutebrowser.utils import (version, utils, jinja, log, message, docutils, - objreg, urlutils, usertypes) + objreg, urlutils) from qutebrowser.misc import objects From 4848182204c234f082e3e508588bc852873c78da Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sat, 13 Jan 2018 01:39:05 -0500 Subject: [PATCH 05/14] code cleanup - move qute_bindings block AFTER qute_settings block - remove unnecessary variable declaration --- qutebrowser/browser/qutescheme.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 3d80c7b37..231af90bf 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -423,20 +423,6 @@ def _qute_settings_set(url): return 'text/html', b'error: ' + str(e).encode('utf-8') -@add_handler('bindings') -def qute_bindings(url): - """Handler for qute://bindings View qute bindings.""" - - bindings = {} - html = '' - for mode in "normal hint command insert passthrough".split(): - bindings[mode] = config.key_instance.get_bindings_for(mode) - - html = jinja.render('bindings.html', title='bindings', - bindings=bindings) - return 'text/html', html - - @add_handler('settings') def qute_settings(url): """Handler for qute://settings. View/change qute configuration.""" @@ -449,6 +435,19 @@ def qute_settings(url): return 'text/html', html +@add_handler('bindings') +def qute_bindings(url): + """Handler for qute://bindings View qute bindings.""" + + bindings = {} + for mode in "normal hint command insert passthrough".split(): + bindings[mode] = config.key_instance.get_bindings_for(mode) + + html = jinja.render('bindings.html', title='bindings', + bindings=bindings) + return 'text/html', html + + @add_handler('back') def qute_back(url): """Handler for qute://back. From 48b6c160f5ac5a1db2e30e5f3ba58109e180aa39 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sat, 13 Jan 2018 15:52:49 -0500 Subject: [PATCH 06/14] improve styling as suggested by @jgkamat --- qutebrowser/browser/qutescheme.py | 2 +- qutebrowser/html/bindings.html | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 3d80c7b37..487982c51 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -432,7 +432,7 @@ def qute_bindings(url): for mode in "normal hint command insert passthrough".split(): bindings[mode] = config.key_instance.get_bindings_for(mode) - html = jinja.render('bindings.html', title='bindings', + html = jinja.render('bindings.html', title='Bindings', bindings=bindings) return 'text/html', html diff --git a/qutebrowser/html/bindings.html b/qutebrowser/html/bindings.html index 29c3f1883..ef52e538f 100644 --- a/qutebrowser/html/bindings.html +++ b/qutebrowser/html/bindings.html @@ -1,12 +1,7 @@ -{% extends "base.html" %} +{% extends "styled.html" %} {% block style %} -html { margin:20px; } -table { width:100%; border: 1px solid grey; border-collapse: collapse; margin:10px; } -tr,td,p { margin:0; padding: 1px; } -th, td { border: 1px solid grey; } -th { background: lightgrey; } -th pre { color: grey; text-align: left; } +th { text-align:left; } .key { width: 25%; } .command { width: 75% } {% endblock %} From f6cfb0c529436cd3fee53325a91b9e3df7e33049 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 15:44:21 -0500 Subject: [PATCH 07/14] add missing super() call --- qutebrowser/html/bindings.html | 1 + 1 file changed, 1 insertion(+) diff --git a/qutebrowser/html/bindings.html b/qutebrowser/html/bindings.html index ef52e538f..28bbb2baf 100644 --- a/qutebrowser/html/bindings.html +++ b/qutebrowser/html/bindings.html @@ -1,6 +1,7 @@ {% extends "styled.html" %} {% block style %} +{{ super() }} th { text-align:left; } .key { width: 25%; } .command { width: 75% } From 9b473093b1c5e17ea2ae5c4b8a7d8fddb703b30c Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 15:45:29 -0500 Subject: [PATCH 08/14] silence pylint warning --- qutebrowser/browser/qutescheme.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index bae9a16dd..e1b6c390a 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -439,6 +439,7 @@ def qute_settings(url): def qute_bindings(url): """Handler for qute://bindings View qute bindings.""" + _url = url bindings = {} for mode in "normal hint command insert passthrough".split(): bindings[mode] = config.key_instance.get_bindings_for(mode) From 528b48dab6639f98afe19ea0231c263dba8faa78 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 15:51:14 -0500 Subject: [PATCH 09/14] fix line too --- qutebrowser/config/configcommands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/configcommands.py b/qutebrowser/config/configcommands.py index 8b6c3ce3f..014235bf7 100644 --- a/qutebrowser/config/configcommands.py +++ b/qutebrowser/config/configcommands.py @@ -97,7 +97,8 @@ class ConfigCommands: no_cmd_split=True, no_replace_variables=True) @cmdutils.argument('command', completion=configmodel.bind) @cmdutils.argument('win_id', win_id=True) - def bind(self, win_id, key=None, command=None, *, mode='normal', default=False): + def bind(self, win_id, key=None, command=None, *, mode='normal', + default=False): """Bind a key to a command. Args: From 2a274f0d8bfde14869e2922a29dc810c92c9ab8a Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 15:52:15 -0500 Subject: [PATCH 10/14] add test for bind without args and fix other tests to include win_id --- tests/unit/config/test_configcommands.py | 28 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index 4c0c833a1..92796e8e5 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -429,6 +429,16 @@ class TestBind: """Get a dict with no bindings.""" return {'normal': {}} + def test_bind_no_args(self, commands, config_stub, no_bindings, + tabbed_browser_stubs): + """Run ':bind'. + + Should open qute://bindings.""" + config_stub.val.bindings.default = no_bindings + config_stub.val.bindings.commands = no_bindings + commands.bind(win_id=0) + assert tabbed_browser_stubs[0].opened_url == QUrl('qute://bindings') + @pytest.mark.parametrize('command', ['nop', 'nope']) def test_bind(self, commands, config_stub, no_bindings, key_config_stub, command): @@ -437,7 +447,7 @@ class TestBind: config_stub.val.bindings.default = no_bindings config_stub.val.bindings.commands = no_bindings - commands.bind('a', command) + commands.bind(0, 'a', command) assert key_config_stub.get_command('a', 'normal') == command yaml_bindings = config_stub._yaml['bindings.commands']['normal'] assert yaml_bindings['a'] == command @@ -474,7 +484,7 @@ class TestBind: 'normal': {'c': 'message-info c'} } - commands.bind(key, mode=mode) + commands.bind(0, key, mode=mode) msg = message_mock.getmsg(usertypes.MessageLevel.info) assert msg.text == expected @@ -486,7 +496,7 @@ class TestBind: """ with pytest.raises(cmdexc.CommandError, match='Invalid mode wrongmode!'): - commands.bind('a', 'nop', mode='wrongmode') + commands.bind(0, 'a', 'nop', mode='wrongmode') def test_bind_print_invalid_mode(self, commands): """Run ':bind --mode=wrongmode a'. @@ -495,7 +505,7 @@ class TestBind: """ with pytest.raises(cmdexc.CommandError, match='Invalid mode wrongmode!'): - commands.bind('a', mode='wrongmode') + commands.bind(0, 'a', mode='wrongmode') @pytest.mark.parametrize('key', ['a', 'b', '']) def test_bind_duplicate(self, commands, config_stub, key_config_stub, key): @@ -510,12 +520,12 @@ class TestBind: 'normal': {'b': 'nop'}, } - commands.bind(key, 'message-info foo', mode='normal') + commands.bind(0, key, 'message-info foo', mode='normal') assert key_config_stub.get_command(key, 'normal') == 'message-info foo' def test_bind_none(self, commands, config_stub): config_stub.val.bindings.commands = None - commands.bind(',x', 'nop') + commands.bind(0, ',x', 'nop') def test_bind_default(self, commands, key_config_stub, config_stub): """Bind a key to its default.""" @@ -525,7 +535,7 @@ class TestBind: config_stub.val.bindings.commands = {'normal': {'a': bound_cmd}} assert key_config_stub.get_command('a', mode='normal') == bound_cmd - commands.bind('a', mode='normal', default=True) + commands.bind(0, 'a', mode='normal', default=True) assert key_config_stub.get_command('a', mode='normal') == default_cmd @@ -539,7 +549,7 @@ class TestBind: Should show an error. """ with pytest.raises(cmdexc.CommandError, match=expected): - commands.bind(key, mode=mode, default=True) + commands.bind(0, key, mode=mode, default=True) def test_unbind_none(self, commands, config_stub): config_stub.val.bindings.commands = None @@ -563,7 +573,7 @@ class TestBind: } if key == 'c': # Test :bind and :unbind - commands.bind(key, 'nop') + commands.bind(0, key, 'nop') commands.unbind(key) assert key_config_stub.get_command(key, 'normal') is None From fb0a418d0a0abba10bff7256bd265efdcfa2054d Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 16:03:22 -0500 Subject: [PATCH 11/14] use url even if we do not need it --- qutebrowser/browser/qutescheme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index e1b6c390a..b15c2133b 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -438,8 +438,8 @@ def qute_settings(url): @add_handler('bindings') def qute_bindings(url): """Handler for qute://bindings View qute bindings.""" + assert url - _url = url bindings = {} for mode in "normal hint command insert passthrough".split(): bindings[mode] = config.key_instance.get_bindings_for(mode) From e25a33790fc3f68f024dd9eae8eccf0dba3102d5 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 20:44:56 -0500 Subject: [PATCH 12/14] remove blank line to satisfy flake8 --- qutebrowser/config/configcommands.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qutebrowser/config/configcommands.py b/qutebrowser/config/configcommands.py index 014235bf7..cc3eae514 100644 --- a/qutebrowser/config/configcommands.py +++ b/qutebrowser/config/configcommands.py @@ -110,7 +110,6 @@ class ConfigCommands: available modes. default: If given, restore a default binding. """ - if key is None: tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) From 5db44936678024e83ba6dabdf53753039991c57b Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Wed, 17 Jan 2018 10:11:32 -0500 Subject: [PATCH 13/14] @The-Compiler requested changes addressed. --- qutebrowser/browser/qutescheme.py | 10 +++++----- qutebrowser/html/bindings.html | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index b15c2133b..c252c82b8 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -436,12 +436,12 @@ def qute_settings(url): @add_handler('bindings') -def qute_bindings(url): - """Handler for qute://bindings View qute bindings.""" - assert url - +def qute_bindings(_url): + """Handler for qute://bindings. View keybindings.""" bindings = {} - for mode in "normal hint command insert passthrough".split(): + defaults = config.val.bindings.default + modes = set(defaults.keys()).union(config.val.bindings.commands) + for mode in modes: bindings[mode] = config.key_instance.get_bindings_for(mode) html = jinja.render('bindings.html', title='Bindings', diff --git a/qutebrowser/html/bindings.html b/qutebrowser/html/bindings.html index 28bbb2baf..fe6913402 100644 --- a/qutebrowser/html/bindings.html +++ b/qutebrowser/html/bindings.html @@ -10,7 +10,7 @@ th { text-align:left; } {% block content %}

{{ title }}

{% for mode, binding in bindings.items() %} -

Mode = {{ mode }}

+

{{ mode | capitalize }} mode

From 72c97ca846d4f742af211f4f07a651e20d37c25c Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Wed, 17 Jan 2018 14:25:07 -0500 Subject: [PATCH 14/14] sort modes, "normal" mode first --- qutebrowser/browser/qutescheme.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index c252c82b8..08122958a 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -441,6 +441,8 @@ def qute_bindings(_url): bindings = {} defaults = config.val.bindings.default modes = set(defaults.keys()).union(config.val.bindings.commands) + modes.remove('normal') + modes = ['normal'] + sorted(list(modes)) for mode in modes: bindings[mode] = config.key_instance.get_bindings_for(mode)
Key