From e79913399714f31513a96bbc445103322a71a6d1 Mon Sep 17 00:00:00 2001 From: James <101812526+WoodchuckXL@users.noreply.github.com> Date: Thu, 20 Aug 2026 13:38:30 -0400 Subject: [PATCH] Added cli hint display functionality --- README.md | 1 + src/cli.c | 14 ++++++++++++++ src/cli.h | 2 ++ src/main.c | 8 ++++++++ 4 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 23f9f0b..a6234e3 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ into a terminal. The terminal app takes a number of optional arguments: | `-O`, `--optimize` | Enable optimizations | | `-profile`, `--profile` | Enable profiling | | `--no-color` | Disable syntax highlighting | +| `--no-hints` | Disable hint output | | `-w`, `--workers ` | Set number of worker threads | If no file is specified, morpho enters interactive mode. If stdin is piped or redirected, morpho reads and executes from stdin. Any options after the file name are passed to the morpho program and are available from the `System` class: diff --git a/src/cli.c b/src/cli.c index c129dcf..9fa1fdf 100644 --- a/src/cli.c +++ b/src/cli.c @@ -56,6 +56,10 @@ bool cli_usecolor(void) { return inline_checksupported(); } +bool cli_showhints(void) { + return !(s_cli_activeopt & CLI_NOHINTS); +} + #define CLI_BUFFERSIZE 4096 #define RESET "\x1B[0m" @@ -120,6 +124,14 @@ void cli_reporterror(error *err, vm *v) { cli_displaywithstyle(CLI_ERRORCOLOR, CLI_NOEMPHASIS, 3, ": ", err->msg, "\n"); } +#ifdef MORPHO_INCLUDE_HINT + if (err->hnt) { // Display the hint attached to the error + if (cli_showhints()) { + cli_displaywithstyle(CLI_HINTCOLOR, CLI_NOEMPHASIS, 3, "Hint: ", err->hnt->msg, "\n"); + } + hint_free(&err->hnt); + } +#endif } } @@ -331,6 +343,7 @@ bool cli_syntaxcolorfn(const char *in, void *ref, size_t offset, inline_colorspa } if (tok.type==TOKEN_EOF) lex_clear(l); + error_clear(&err); return success; } @@ -788,6 +801,7 @@ void cli_helpquery(const char *query, clioptions opt) { char *q = query ? (char *) query : (char *) ""; if (!cli_help(edit, q, &err, help)) cli_setexitcode(EXIT_FAILURE); hlp_finalize(); + error_clear(&err); inline_free(edit); } diff --git a/src/cli.h b/src/cli.h index c0ea5a1..6b5aa4a 100644 --- a/src/cli.h +++ b/src/cli.h @@ -17,6 +17,7 @@ #define CLI_DEFAULTCOLOR -1 #define CLI_ERRORCOLOR INLINE_RED #define CLI_WARNINGCOLOR INLINE_YELLOW +#define CLI_HINTCOLOR 8 // This should be an inline color macro 'INLINE_BRIGHTBLACK' but that is yet to exist atm #define CLI_NOEMPHASIS -1 #define CLI_BOLD 0 @@ -37,6 +38,7 @@ #define CLI_PROFILE (1<<5) #define CLI_INTERACTIVE (1<<6) #define CLI_NOCOLOR (1<<7) +#define CLI_NOHINTS (1<<8) typedef unsigned int clioptions; diff --git a/src/main.c b/src/main.c index e29103b..d488b49 100644 --- a/src/main.c +++ b/src/main.c @@ -64,6 +64,7 @@ static bool opt_help(const char *opt, const char *arg, clioptions *flags, opt_ct printf(" -O, --optimize Enable optimizations\n"); printf(" -profile, --profile Enable profiling\n"); printf(" --no-color Disable syntax highlighting\n"); + printf(" --no-hints Disable hint output\n"); printf(" -w, --workers Set number of worker threads\n"); printf("\nIf no file is specified, morpho enters interactive REPL mode.\n"); printf("If stdin is piped or redirected, morpho reads and executes from stdin.\n"); @@ -127,6 +128,12 @@ static bool opt_nocolor(const char *opt, const char *arg, clioptions *flags, opt return true; } +static bool opt_nohints(const char *opt, const char *arg, clioptions *flags, opt_ctx *ctx) { + (void)opt; (void)arg; (void)ctx; + *flags |= CLI_NOHINTS; + return true; +} + static bool opt_check(const char *opt, const char *arg, clioptions *flags, opt_ctx *ctx) { (void)opt; (void)arg; (void)ctx; *flags &= ~CLI_RUN; /* Clear RUN flag - compile only, don't execute */ @@ -191,6 +198,7 @@ static const option_t opt_table[] = { { "-O", "--optimize", false, opt_optimize }, { "-profile", "--profile", false, opt_profile }, { NULL, "--no-color", false, opt_nocolor }, + { NULL, "--no-hints", false, opt_nohints }, { "-v", "--version", false, opt_version }, { "-w", "--workers", true, opt_workers }, { NULL, NULL, false, NULL },