OSDN Git Service

Fixes #40358 Help output could be better.
authorSimon Forman <sforman@hushmail.com>
Sat, 25 Apr 2020 22:08:58 +0000 (15:08 -0700)
committerSimon Forman <sforman@hushmail.com>
Sat, 25 Apr 2020 22:08:58 +0000 (15:08 -0700)
For now.  Add a header and footer.  Later on when I have per-function docs
it can look those up and print them (or open a viewer in the GUI.)

joy/gui/world.py
joy/library.py

index e2f59d3..945bea2 100644 (file)
@@ -27,6 +27,7 @@ import os, pickle, sys
 from inspect import getdoc
 
 from joy.joy import run
+from joy.library import HELP_TEMPLATE
 from joy.parser import Symbol
 from joy.utils.stack import stack_to_string
 from joy.utils.types import type_check
@@ -59,14 +60,15 @@ class World(object):
 
        def do_opendoc(self, name):
                if is_numerical(name):
-                       print('The number', name)
+                       doc = 'The number ' + str(name)
                else:
                        try:
                                word = self.dictionary[name]
                        except KeyError:
-                               print(repr(name), '???')
+                               doc = 'Unknown: ' + repr(name)
                        else:
-                               print(getdoc(word))
+                               doc = getdoc(word)
+               print(HELP_TEMPLATE % (name, doc, name))
                self.print_stack()
 
        def pop(self):
index 65f3cf8..8e53a66 100644 (file)
@@ -72,6 +72,16 @@ from .utils.types import (
        )
 
 
+HELP_TEMPLATE = '''\
+
+==== Help on %s ====
+
+%s
+
+---- end (%s)
+'''
+
+
 _SYM_NUMS = lambda c=count(): next(c)
 _COMB_NUMS = lambda c=count(): next(c)
 
@@ -890,7 +900,7 @@ def help_(S, expression, dictionary):
        '''Accepts a quoted symbol on the top of the stack and prints its docs.'''
        ((symbol, _), stack) = S
        word = dictionary[symbol]
-       print(getdoc(word))
+       print(HELP_TEMPLATE % (symbol, getdoc(word), symbol))
        return stack, expression, dictionary