Add the /edit switch to the @help command
This commit is contained in:
parent
4d14625504
commit
3998ed1069
1 changed files with 34 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ from evennia.utils.utils import fill, dedent
|
||||||
from evennia.commands.command import Command
|
from evennia.commands.command import Command
|
||||||
from evennia.help.models import HelpEntry
|
from evennia.help.models import HelpEntry
|
||||||
from evennia.utils import create, evmore
|
from evennia.utils import create, evmore
|
||||||
|
from evennia.utils.eveditor import EvEditor
|
||||||
from evennia.utils.utils import string_suggestions, class_from_module
|
from evennia.utils.utils import string_suggestions, class_from_module
|
||||||
|
|
||||||
COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS)
|
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))
|
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):
|
class CmdSetHelp(COMMAND_DEFAULT_CLASS):
|
||||||
"""
|
"""
|
||||||
edit the help database
|
Edit the help database.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
@help[/switches] <topic>[[;alias;alias][,category[,locks]] = <text>
|
@help[/switches] <topic>[[;alias;alias][,category[,locks]] = <text>
|
||||||
|
|
||||||
Switches:
|
Switches:
|
||||||
|
edit - open a line editor to edit the topic's help text.
|
||||||
replace - overwrite existing help topic.
|
replace - overwrite existing help topic.
|
||||||
append - add text to the end of existing topic with a newline between.
|
append - add text to the end of existing topic with a newline between.
|
||||||
extend - as append, but don't add a newline.
|
extend - as append, but don't add a newline.
|
||||||
|
|
@ -325,6 +347,17 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS):
|
||||||
old_entry.aliases.add(aliases)
|
old_entry.aliases.add(aliases)
|
||||||
self.msg("Entry updated:\n%s%s" % (old_entry.entrytext, aliastxt))
|
self.msg("Entry updated:\n%s%s" % (old_entry.entrytext, aliastxt))
|
||||||
return
|
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:
|
if 'delete' in switches or 'del' in switches:
|
||||||
# delete the help entry
|
# delete the help entry
|
||||||
if not old_entry:
|
if not old_entry:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue