diff options
| author | eunhhu <[email protected]> | 2026-09-26 10:49:02 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-26 10:49:02 +0100 |
| commit | b55395802f4c7b929c45013efb572aab786a8b43 (patch) | |
| tree | ad57b9d3521521c6ce9ca04d6a7f151b05c824b2 /src/main.c | |
| parent | 2d7024ba01875a8fc7a2c99e78c62911bcc7fe3f (diff) | |
| download | vega-b55395802f4c7b929c45013efb572aab786a8b43.tar.gz vega-b55395802f4c7b929c45013efb572aab786a8b43.zip | |
Add vega check for conventions a spec misses
Surfaces read a view that misses a convention as something else without
a word: a number label makes a list a table, a text tone disappears, a
list never shows its other columns, X_focus without a table becomes a
field, a second text input has nowhere to type. vega check MODULE names
each such place (the view or input and what the surface does instead)
and exits 1; the rules sit next to the code that reads the screen.
The checks build a spec that misses eight conventions and expect exactly
its nine findings, and none in the examples.
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -11,6 +11,7 @@ #include <unistd.h> /* vega SURFACE MODULE [--store PATH]: one module, one screen, several surfaces. + * check what the module seems to mean but does not meet (exit 1) * tui interactive terminal * tui --dump WxH the terminal's frames as text, driven by a script * cli plain lines for pipes, driven by a script @@ -29,7 +30,7 @@ static char entry[VEGA_TEXT]; static size_t entry_length; static bool typing; -static bool load(const char *path, const char *store) { +static bool load_module(const char *path) { static unsigned char bytes[1 << 17]; FILE *file = fopen(path, "rb"); size_t size = file ? fread(bytes, 1, sizeof(bytes), file) : 0; @@ -41,6 +42,15 @@ static bool load(const char *path, const char *store) { fprintf(stderr, "vega: %s: %s\n", path, error); return false; } + return true; +} + +static void print_finding(void *path, const char *name, const char *message) { + printf("%s: %s: %s\n", (const char *)path, name, message); +} + +static bool load(const char *path, const char *store) { + if (!load_module(path)) return false; if (store && pure_store_init(store) != PURE_OK) { fprintf(stderr, "vega: cannot open store %s\n", store); return false; } PureResult started = pure_app_start(&app, &module, store ? pure_tree_data(store) : (PureData){0}); if (started != PURE_OK) { fprintf(stderr, "vega: cannot start (%d)\n", (int)started); return false; } @@ -376,11 +386,16 @@ int main(int argc, char **argv) { width <= 1000 && height <= 1000) dumped = true; else usage = true; } - if (usage || (dumped && strcmp(argv[1], "tui"))) { + if (usage || (dumped && strcmp(argv[1], "tui")) || (!strcmp(argv[1], "check") && argc != 3)) { fputs("vega tui|cli|say MODULE.pmod [--store PATH]\n" - "vega tui MODULE.pmod [--store PATH] --dump WIDTHxHEIGHT < script\n", stderr); + "vega tui MODULE.pmod [--store PATH] --dump WIDTHxHEIGHT < script\n" + "vega check MODULE.pmod\n", stderr); return 2; } + if (!strcmp(argv[1], "check")) { + if (!load_module(argv[2])) return 2; + return vega_check(&module, print_finding, argv[2]) ? 1 : 0; + } Surface surface = !strcmp(argv[1], "cli") ? SURFACE_CLI : !strcmp(argv[1], "say") ? SURFACE_SAY : !strcmp(argv[1], "tui") ? SURFACE_TUI : (Surface)-1; if ((int)surface < 0) { fprintf(stderr, "vega: unknown surface %s\n", argv[1]); return 2; } |
