diff --git a/evennia/utils/eveditor.py b/evennia/utils/eveditor.py index d91bc3227a..55ba2f16d5 100644 --- a/evennia/utils/eveditor.py +++ b/evennia/utils/eveditor.py @@ -44,7 +44,7 @@ import re from django.conf import settings from evennia import Command, CmdSet -from evennia.utils import is_iter, fill, dedent, logger +from evennia.utils import is_iter, fill, dedent, logger, justify from evennia.commands import cmdhandler # we use cmdhandler instead of evennia.syscmdkeys to @@ -93,9 +93,10 @@ _HELP_TEXT = \ :s - search/replace word or regex in buffer or on line - :f - flood-fill entire buffer or line - :fi - indent entire buffer or line - :fd - de-indent entire buffer or line + :j - justify buffer or line . is f, c, l or r. Default f (full) + :f - flood-fill entire buffer or line : Equivalent to :j left + :fi - indent entire buffer or line + :fd - de-indent entire buffer or line :echo - turn echoing of the input on/off (helpful for some clients) @@ -370,7 +371,7 @@ class CmdEditorGroup(CmdEditorBase): """ key = ":editor_command_group" aliases = [":","::", ":::", ":h", ":w", ":wq", ":q", ":q!", ":u", ":uu", ":UU", - ":dd", ":dw", ":DD", ":y", ":x", ":p", ":i", + ":dd", ":dw", ":DD", ":y", ":x", ":p", ":i", ":j", ":r", ":I", ":A", ":s", ":S", ":f", ":fi", ":fd", ":echo"] arg_regex = r"\s.*?|$" @@ -423,7 +424,7 @@ class CmdEditorGroup(CmdEditorBase): # quit. If not saved, will ask if self.editor._unsaved: caller.cmdset.add(SaveYesNoCmdSet) - caller.msg("Save before quitting? {lcyes{lt[Y]{le/{lcno{ltN{le") + caller.msg("Save before quitting? |lcyes|lt[Y]|le/|lcno|ltN|le") else: editor.quit() elif cmd == ":q!": @@ -552,6 +553,27 @@ class CmdEditorGroup(CmdEditorBase): fbuf = fill(fbuf, width=width) buf = linebuffer[:lstart] + fbuf.split("\n") + linebuffer[lend:] editor.update_buffer(buf) + elif cmd == ":j": + # :f justify buffer of with as align (one of + # f(ull), c(enter), r(ight) or l(left). Default is full. + align_map = {"full": "f", "f": "f", "center": "c", "c": "c", + "right": "r", "r": "r", "left": "l", "l": "l"} + align_name = {"f": "Full", "c": "Center", "l": "Left", "r": "Right"} + width = _DEFAULT_WIDTH + if self.arg1 and self.arg1.lower() not in align_map: + self.caller.msg("Valid justifications are [f]ull (default), [c]enter, [r]right or [l]eft") + return + align = align_map[self.arg1.lower()] if self.arg1 else 'f' + if not self.linerange: + lstart = 0 + lend = self.cline + 1 + self.caller.msg("%s-justified lines %i-%i." % (align_name[align], lstart + 1, lend)) + else: + self.caller.msg("%s-justified %s." % (align_name[align], self.lstr)) + jbuf = "\n".join(linebuffer[lstart:lend]) + jbuf = justify(jbuf, width=width, align=align) + buf = linebuffer[:lstart] + jbuf.split("\n") + linebuffer[lend:] + editor.update_buffer(buf) elif cmd == ":fi": # :fi indent buffer or lines of buffer. indent = " " * 4