From 3998ed10695ca1c53a81cbb1004753eb3b742f98 Mon Sep 17 00:00:00 2001 From: Vincent Le Goff Date: Sat, 4 Feb 2017 16:51:56 -0800 Subject: [PATCH] Add the /edit switch to the @help command --- evennia/commands/default/help.py | 35 +++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/evennia/commands/default/help.py b/evennia/commands/default/help.py index a4ebc03e3..cbc3dc270 100644 --- a/evennia/commands/default/help.py +++ b/evennia/commands/default/help.py @@ -12,6 +12,7 @@ from evennia.utils.utils import fill, dedent from evennia.commands.command import Command from evennia.help.models import HelpEntry from evennia.utils import create, evmore +from evennia.utils.eveditor import EvEditor from evennia.utils.utils import string_suggestions, class_from_module COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS) @@ -246,14 +247,35 @@ class CmdHelp(Command): self.msg(self.format_help_entry("", "No help entry found for '%s'" % query, None, suggested=suggestions)) +def loadhelp(caller): + """Load the help entry to edit.""" + entry = caller.db._editing_help + if entry: + return entry.entrytext + else: + return "" + +def savehelp(caller, buffer): + """Save the help entry.""" + entry = caller.db._editing_help + if entry: + entry.entrytext = buffer + + +def quithelp(caller): + """Quit the help editor.""" + caller.msg("Closing the editor.") + del caller.db._editing_help + class CmdSetHelp(COMMAND_DEFAULT_CLASS): """ - edit the help database + Edit the help database. Usage: @help[/switches] [[;alias;alias][,category[,locks]] = Switches: + edit - open a line editor to edit the topic's help text. replace - overwrite existing help topic. append - add text to the end of existing topic with a newline between. extend - as append, but don't add a newline. @@ -325,6 +347,17 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS): old_entry.aliases.add(aliases) self.msg("Entry updated:\n%s%s" % (old_entry.entrytext, aliastxt)) return + if 'edit' in switches: + # open the line editor to edit the helptext + if not old_entry: + self.msg("Could not find topic '%s'%s." % (topicstr, aliastxt)) + return + + self.caller.db._editing_help = old_entry + EvEditor(self.caller, loadfunc=loadhelp, savefunc=savehelp, + quitfunc=quithelp, key="topic {}".format(old_entry.key), + persistent=True) + return if 'delete' in switches or 'del' in switches: # delete the help entry if not old_entry: