Add help and colored banner
- (help ...) is a macro that quotes everything to be user-friendly - (help* ...) is the equivalent procedure - When the user types just `help` or `exit`, the REPL shows a hint that they are probably looking for `(help)` or `(exit)`.
This commit is contained in:
parent
4fef0b89b9
commit
78b663d41d
17
c/builtins.c
17
c/builtins.c
|
@ -489,6 +489,21 @@ MATH_FUNC_1ARG(asin)
|
|||
MATH_FUNC_1ARG(acos)
|
||||
MATH_FUNC_1ARG(atan)
|
||||
|
||||
static const char help_text[] =
|
||||
""
|
||||
"----------------------------------------------------------------------\n"
|
||||
"You are in Up Scheme.\n"
|
||||
"Type (exit) to exit.\n"
|
||||
"----------------------------------------------------------------------\n";
|
||||
|
||||
static value_t builtin_help_star(value_t *args, uint32_t nargs)
|
||||
{
|
||||
(void)args;
|
||||
(void)nargs;
|
||||
ios_puts(help_text, ios_stdout);
|
||||
return FL_T;
|
||||
}
|
||||
|
||||
extern void stringfuncs_init(void);
|
||||
extern void table_init(void);
|
||||
extern void iostream_init(void);
|
||||
|
@ -537,6 +552,8 @@ static struct builtinspec builtin_info[] = {
|
|||
|
||||
{ "os.getenv", builtin_get_environment_variable }, // TODO: remove
|
||||
|
||||
{ "help*", builtin_help_star },
|
||||
|
||||
{ "import-procedure", builtin_import },
|
||||
|
||||
{ NULL, NULL }
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -912,10 +912,6 @@
|
|||
(io.close F)
|
||||
(raise `(load-error ,filename ,e)))))))
|
||||
|
||||
(define *banner* (string.tail "
|
||||
Up Scheme
|
||||
" 1))
|
||||
|
||||
(define (sgr . ns)
|
||||
(let ((out (open-output-string)))
|
||||
(display "\x1b[" out)
|
||||
|
@ -952,17 +948,23 @@ Up Scheme
|
|||
(lambda (e) (begin (io.discardbuffer *input-stream*)
|
||||
(raise e))))))
|
||||
(and (not (io.eof? *input-stream*))
|
||||
(let ((V (load-process v)))
|
||||
(write V)
|
||||
(set! that V)
|
||||
#t))))
|
||||
(begin (trycatch (let ((V (load-process v)))
|
||||
(writeln V)
|
||||
(set! that V)
|
||||
#t)
|
||||
(lambda (e)
|
||||
(top-level-exception-handler e)
|
||||
#t))
|
||||
(when (or (eqv? 'help v) (eqv? 'exit v))
|
||||
(newline)
|
||||
(displayln "Type (help) for help or (exit) to exit."))
|
||||
#t))))
|
||||
(define (reploop)
|
||||
(when (trycatch (and (prompt) (newline))
|
||||
(when (trycatch (prompt)
|
||||
(lambda (e)
|
||||
(top-level-exception-handler e)
|
||||
#t))
|
||||
(begin (newline)
|
||||
(reploop))))
|
||||
(reploop)))
|
||||
(reploop)
|
||||
(newline))
|
||||
|
||||
|
@ -1096,6 +1098,12 @@ Up Scheme
|
|||
(symbol->string sym))))
|
||||
(apply apropos-list args)))
|
||||
|
||||
(define-macro (help . args)
|
||||
`(apply help* ',args))
|
||||
|
||||
(define (display-banner)
|
||||
(displayln (string-append (sgr (fg cyan)) "Up Scheme" (sgr))))
|
||||
|
||||
(define (system-image->buffer)
|
||||
(let ((out (buffer))
|
||||
(excludes '(*linefeed* *directory-separator* *argv* that
|
||||
|
@ -1142,6 +1150,6 @@ Up Scheme
|
|||
(__script (cadr argv)))
|
||||
(begin (set! *argv* argv)
|
||||
(set! *interactive* #t)
|
||||
(display *banner*)
|
||||
(display-banner)
|
||||
(repl)))
|
||||
(exit 0))
|
||||
|
|
Loading…
Reference in New Issue