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(acos)
|
||||||
MATH_FUNC_1ARG(atan)
|
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 stringfuncs_init(void);
|
||||||
extern void table_init(void);
|
extern void table_init(void);
|
||||||
extern void iostream_init(void);
|
extern void iostream_init(void);
|
||||||
|
@ -537,6 +552,8 @@ static struct builtinspec builtin_info[] = {
|
||||||
|
|
||||||
{ "os.getenv", builtin_get_environment_variable }, // TODO: remove
|
{ "os.getenv", builtin_get_environment_variable }, // TODO: remove
|
||||||
|
|
||||||
|
{ "help*", builtin_help_star },
|
||||||
|
|
||||||
{ "import-procedure", builtin_import },
|
{ "import-procedure", builtin_import },
|
||||||
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -912,10 +912,6 @@
|
||||||
(io.close F)
|
(io.close F)
|
||||||
(raise `(load-error ,filename ,e)))))))
|
(raise `(load-error ,filename ,e)))))))
|
||||||
|
|
||||||
(define *banner* (string.tail "
|
|
||||||
Up Scheme
|
|
||||||
" 1))
|
|
||||||
|
|
||||||
(define (sgr . ns)
|
(define (sgr . ns)
|
||||||
(let ((out (open-output-string)))
|
(let ((out (open-output-string)))
|
||||||
(display "\x1b[" out)
|
(display "\x1b[" out)
|
||||||
|
@ -952,17 +948,23 @@ Up Scheme
|
||||||
(lambda (e) (begin (io.discardbuffer *input-stream*)
|
(lambda (e) (begin (io.discardbuffer *input-stream*)
|
||||||
(raise e))))))
|
(raise e))))))
|
||||||
(and (not (io.eof? *input-stream*))
|
(and (not (io.eof? *input-stream*))
|
||||||
(let ((V (load-process v)))
|
(begin (trycatch (let ((V (load-process v)))
|
||||||
(write V)
|
(writeln V)
|
||||||
(set! that V)
|
(set! that V)
|
||||||
#t))))
|
#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)
|
(define (reploop)
|
||||||
(when (trycatch (and (prompt) (newline))
|
(when (trycatch (prompt)
|
||||||
(lambda (e)
|
(lambda (e)
|
||||||
(top-level-exception-handler e)
|
(top-level-exception-handler e)
|
||||||
#t))
|
#t))
|
||||||
(begin (newline)
|
(reploop)))
|
||||||
(reploop))))
|
|
||||||
(reploop)
|
(reploop)
|
||||||
(newline))
|
(newline))
|
||||||
|
|
||||||
|
@ -1096,6 +1098,12 @@ Up Scheme
|
||||||
(symbol->string sym))))
|
(symbol->string sym))))
|
||||||
(apply apropos-list args)))
|
(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)
|
(define (system-image->buffer)
|
||||||
(let ((out (buffer))
|
(let ((out (buffer))
|
||||||
(excludes '(*linefeed* *directory-separator* *argv* that
|
(excludes '(*linefeed* *directory-separator* *argv* that
|
||||||
|
@ -1142,6 +1150,6 @@ Up Scheme
|
||||||
(__script (cadr argv)))
|
(__script (cadr argv)))
|
||||||
(begin (set! *argv* argv)
|
(begin (set! *argv* argv)
|
||||||
(set! *interactive* #t)
|
(set! *interactive* #t)
|
||||||
(display *banner*)
|
(display-banner)
|
||||||
(repl)))
|
(repl)))
|
||||||
(exit 0))
|
(exit 0))
|
||||||
|
|
Loading…
Reference in New Issue