Resolves player confusion with the EvMore display, making it more clear that 'n/next' is used for continuing, makes 'look' repeat the display, and notifies them when they exit.

This commit is contained in:
Tehom 2016-10-01 18:04:32 -04:00 committed by Griatch
parent d407de4dc3
commit c5c3a9ef0a

View file

@ -74,7 +74,7 @@ class CmdMore(Command):
more.page_quit()
elif cmd in ("back", "b"):
more.page_back()
elif cmd in ("top", "t"):
elif cmd in ("top", "t", "look", "l"):
more.page_top()
elif cmd in ("end", "e"):
more.page_end()
@ -82,6 +82,25 @@ class CmdMore(Command):
# return or n, next
more.page_next()
class CmdMoreLook(Command):
"""
Override look to display window and prevent OOCLook from firing
"""
key = "look"
aliases = ["l"]
auto_help = False
def func(self):
"""
Implement the command
"""
more = self.caller.ndb._more
if not more and hasattr(self.caller, "player"):
more = self.caller.player.ndb._more
if not more:
self.caller.msg("Error in loading the pager. Contact an admin.")
return
more.display()
class CmdSetMore(CmdSet):
"""
@ -91,7 +110,8 @@ class CmdSetMore(CmdSet):
priority = 110
def at_cmdset_creation(self):
self.add(CmdMore)
self.add(CmdMore())
self.add(CmdMoreLook())
class EvMore(object):
@ -108,6 +128,11 @@ class EvMore(object):
always_page (bool, optional): If `False`, the
pager will only kick in if `text` is too big
to fit the screen.
session (Session, optional): If given, this session will be used
to determine the screen width and will receive all output.
justify_kwargs (dict, bool or None, optional): If given, this should
be valid keyword arguments to the utils.justify() function. If False,
no justification will be done.
kwargs (any, optional): These will be passed on
to the `caller.msg` method.
@ -117,6 +142,7 @@ class EvMore(object):
self._pages = []
self._npages = []
self._npos = []
self._exit_msg = "Exited |wmore|n pager."
if not session:
# if not supplied, use the first session to
# determine screen size
@ -127,17 +153,21 @@ class EvMore(object):
self._session = session
# set up individual pages for different sessions
height = session.protocol_flags.get("SCREENHEIGHT", {0:_SCREEN_HEIGHT})[0] - 2
height = max(4, session.protocol_flags.get("SCREENHEIGHT", {0:_SCREEN_HEIGHT})[0] - 4)
width = session.protocol_flags.get("SCREENWIDTH", {0:_SCREEN_WIDTH})[0]
# we must break very long lines into multiple ones
justify_kwargs = justify_kwargs or {}
width = justify_kwargs.get("width", width)
justify_kwargs["width"] = width
justify_kwargs["align"] = justify_kwargs.get("align", 'l')
justify_kwargs["indent"] = justify_kwargs.get("indent", 0)
if justify_kwargs is False:
# no justification. Simple division by line
lines = text.split("\n")
else:
# we must break very long lines into multiple ones
justify_kwargs = justify_kwargs or {}
width = justify_kwargs.get("width", width)
justify_kwargs["width"] = width
justify_kwargs["align"] = justify_kwargs.get("align", 'l')
justify_kwargs["indent"] = justify_kwargs.get("indent", 0)
lines = justify(text, **justify_kwargs).split("\n")
lines = justify(text, **justify_kwargs).split("\n")
# always limit number of chars to 10 000 per page
height = min(10000 // width, height)
@ -158,7 +188,7 @@ class EvMore(object):
# goto top of the text
self.page_top()
def _display(self):
def display(self):
"""
Pretty-print the page.
"""
@ -174,14 +204,14 @@ class EvMore(object):
Display the top page
"""
self._pos = 0
self._display()
self.display()
def page_end(self):
"""
Display the bottom page.
"""
self._pos = self._npages - 1
self._display()
self.display()
def page_next(self):
"""
@ -193,28 +223,42 @@ class EvMore(object):
self.page_quit()
else:
self._pos += 1
self._display()
self.display()
def page_back(self):
"""
Scroll the text back up, at the most to the top.
"""
self._pos = max(0, self._pos - 1)
self._display()
self.display()
def page_quit(self):
"""
Quit the pager
"""
del self._caller.ndb._more
self._caller.msg(text=self._exit_msg, **self._kwargs)
self._caller.cmdset.remove(CmdSetMore)
self._caller.msg("Exited |wmore|n pager.")
def msg(caller, text="", always_page=False, session=None, justify_kwargs=None, **kwargs):
"""
More-supported version of msg, mimicking the
normal msg method.
More-supported version of msg, mimicking the normal msg method.
Args:
caller (Object or Player): Entity reading the text.
text (str): The text to put under paging.
always_page (bool, optional): If `False`, the
pager will only kick in if `text` is too big
to fit the screen.
session (Session, optional): If given, this session will be used
to determine the screen width and will receive all output.
justify_kwargs (dict, bool or None, optional): If given, this should
be valid keyword arguments to the utils.justify() function. If False,
no justification will be done.
kwargs (any, optional): These will be passed on
to the `caller.msg` method.
"""
EvMore(caller, text, always_page=always_page, session=session,
justify_kwargs=justify_kwargs, **kwargs)