From 94d49b480102577714cd20ac09c6fc7599d8d71f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 20 Apr 2015 18:32:15 +0200 Subject: [PATCH] Add :message-{info,error,warning} commands. --- CHANGELOG.asciidoc | 5 +++++ doc/help/commands.asciidoc | 30 ++++++++++++++++++++++++++++++ qutebrowser/misc/utilcmds.py | 32 +++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index c9797bfe7..e467898a1 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -17,6 +17,11 @@ This project adheres to http://semver.org/[Semantic Versioning]. v0.3.0 (unreleased) ------------------- +Added +~~~~~ + +- New commands `:message-info`, `:message-error` and `:message-warning` to show messages in the statusbar, e.g. from an userscript. + Changed ~~~~~~~ diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 5a62f8508..344db3e55 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -689,6 +689,9 @@ How many steps to zoom out. |<>|Enter a key mode. |<>|Follow the currently selected hint. |<>|Leave the mode we're currently in. +|<>|Show an error message in the statusbar. +|<>|Show an info message in the statusbar. +|<>|Show a warning message in the statusbar. |<>|Open an external editor with the currently selected form field. |<>|Accept the current prompt. |<>|Answer no to a yes/no prompt. @@ -749,6 +752,33 @@ Follow the currently selected hint. === leave-mode Leave the mode we're currently in. +[[message-error]] +=== message-error +Syntax: +:message-error 'text'+ + +Show an error message in the statusbar. + +==== positional arguments +* +'text'+: The text to show. + +[[message-info]] +=== message-info +Syntax: +:message-info 'text'+ + +Show an info message in the statusbar. + +==== positional arguments +* +'text'+: The text to show. + +[[message-warning]] +=== message-warning +Syntax: +:message-warning 'text'+ + +Show a warning message in the statusbar. + +==== positional arguments +* +'text'+: The text to show. + [[open-editor]] === open-editor Open an external editor with the currently selected form field. diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index 9d4295da2..816b1ed80 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -28,7 +28,7 @@ try: except ImportError: hunter = None -from qutebrowser.utils import log, objreg, usertypes +from qutebrowser.utils import log, objreg, usertypes, message from qutebrowser.commands import cmdutils, runners, cmdexc from qutebrowser.config import style from qutebrowser.misc import consolewidget @@ -78,6 +78,36 @@ def repeat(times: {'type': int}, command, win_id: {'special': 'win_id'}): commandrunner.run_safely(command) +@cmdutils.register(hide=True) +def message_error(win_id: {'special': 'win_id'}, text): + """Show an error message in the statusbar. + + Args: + text: The text to show. + """ + message.error(win_id, text) + + +@cmdutils.register(hide=True) +def message_info(win_id: {'special': 'win_id'}, text): + """Show an info message in the statusbar. + + Args: + text: The text to show. + """ + message.info(win_id, text) + + +@cmdutils.register(hide=True) +def message_warning(win_id: {'special': 'win_id'}, text): + """Show a warning message in the statusbar. + + Args: + text: The text to show. + """ + message.warning(win_id, text) + + @cmdutils.register(debug=True) def debug_crash(typ: {'type': ('exception', 'segfault')}='exception'): """Crash for debugging purposes.