Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <n>` | 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:
Expand Down
14 changes: 14 additions & 0 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

2 changes: 2 additions & 0 deletions src/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <n> 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");
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 },
Expand Down