mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Merge pull request #3497 from chiizujin/editor_justify
Add width argument to editor's :j and :f commands
This commit is contained in:
commit
4ce456b46f
1 changed files with 25 additions and 5 deletions
|
|
@ -67,7 +67,7 @@ _DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
|
|||
# -------------------------------------------------------------
|
||||
|
||||
_HELP_TEXT = _(
|
||||
"""
|
||||
f"""
|
||||
<txt> - any non-command is appended to the end of the buffer.
|
||||
: <l> - view buffer or only line(s) <l>
|
||||
:: <l> - raw-view buffer or only line(s) <l>
|
||||
|
|
@ -97,8 +97,11 @@ _HELP_TEXT = _(
|
|||
|
||||
:s <l> <w> <txt> - search/replace word or regex <w> in buffer or on line <l>
|
||||
|
||||
:j <l> <w> - justify buffer or line <l>. <w> is f, c, l or r. Default f (full)
|
||||
:f <l> - flood-fill entire buffer or line <l>. Equivalent to :j <l> l
|
||||
:j <l> <a> = <w> - justify buffer or line <l>. <a> is f, c, l or r. <w> is
|
||||
width. <a> and <w> are optional and default to l (left)
|
||||
and {_DEFAULT_WIDTH} respectively
|
||||
:f <l> = <w> - flood-fill entire buffer or line <l> to width <w>.
|
||||
Equivalent to :j <l> l. <w> is optional, as for :j
|
||||
:fi <l> - indent entire buffer or line <l>
|
||||
:fd <l> - de-indent entire buffer or line <l>
|
||||
|
||||
|
|
@ -686,7 +689,14 @@ class CmdEditorGroup(CmdEditorBase):
|
|||
editor.update_buffer(buf)
|
||||
elif cmd == ":f":
|
||||
# :f <l> flood-fill buffer or <l> lines of buffer.
|
||||
# :f <l> =<w> flood-fill buffer or <l> lines of buffer to width <w>.
|
||||
width = _DEFAULT_WIDTH
|
||||
if self.arg1:
|
||||
value = self.arg1.lstrip("=")
|
||||
if not value.isdigit():
|
||||
self.caller.msg("Width must be a number.")
|
||||
return
|
||||
width = int(value)
|
||||
if not self.linerange:
|
||||
lstart = 0
|
||||
lend = self.cline + 1
|
||||
|
|
@ -698,7 +708,7 @@ class CmdEditorGroup(CmdEditorBase):
|
|||
buf = linebuffer[:lstart] + fbuf.split("\n") + linebuffer[lend:]
|
||||
editor.update_buffer(buf)
|
||||
elif cmd == ":j":
|
||||
# :f <l> <w> justify buffer of <l> with <w> as align (one of
|
||||
# :j <l> <a> =<w> justify buffer of <l> to width <w> with <a> as align (one of
|
||||
# f(ull), c(enter), r(ight) or l(left). Default is full.
|
||||
align_map = {
|
||||
"full": "f",
|
||||
|
|
@ -711,7 +721,10 @@ class CmdEditorGroup(CmdEditorBase):
|
|||
"l": "l",
|
||||
}
|
||||
align_name = {"f": "Full", "c": "Center", "l": "Left", "r": "Right"}
|
||||
width = _DEFAULT_WIDTH
|
||||
# shift width arg right if no alignment specified
|
||||
if self.arg1.startswith('='):
|
||||
self.arg2 = self.arg1
|
||||
self.arg1 = None
|
||||
if self.arg1 and self.arg1.lower() not in align_map:
|
||||
self.caller.msg(
|
||||
_("Valid justifications are")
|
||||
|
|
@ -719,6 +732,13 @@ class CmdEditorGroup(CmdEditorBase):
|
|||
)
|
||||
return
|
||||
align = align_map[self.arg1.lower()] if self.arg1 else "f"
|
||||
width = _DEFAULT_WIDTH
|
||||
if self.arg2:
|
||||
value = self.arg2.lstrip("=")
|
||||
if not value.isdigit():
|
||||
self.caller.msg("Width must be a number.")
|
||||
return
|
||||
width = int(value)
|
||||
if not self.linerange:
|
||||
lstart = 0
|
||||
lend = self.cline + 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue