Artifact 2ae0c2425677af1175d1f971720054daac0e2aa44adcb01b4ba519b20a41fa50:
- File
src/help.c
— part of check-in
[c8bc1bfa6d]
at
2026-11-23 11:40:21
on branch ux-models
— Model choice says why and recovers from a refused key
With no saved default, pic starts on a provider whose key worked and passes over one that was refused, out of credit or limited; OpenRouter, Moonshot and DeepSeek start on inexpensive general models. The first screen (and stderr for ask and -p) names the model and why; with no key it says how to get one. The picker shows prices and key marks, lists keyless models once typed, ranks exact and prefix matches first, says what it saved and when the thinking level changes. After a refused key, Alt+P picks another model and the message returns to the editor for it. pic sessions shows each conversation's model and marks failed ones; pic models --json carries key; pic --version; pic help start opens with the user path. (user: dmestas, size: 2757) [annotate] [blame] [check-ins using] [more...]
/* pic help; see help.h. */ #include "help.h" #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { const char *name, *title; int reference; const char *const *chunks; /* the file's text, NULL-terminated */ } pic_help_topic; #include "manual.inc" #define NTOPICS (sizeof help_topics / sizeof help_topics[0]) const char *const pic_changelog[] = { #include "changelog.inc" }; void pic_version(char *out, size_t cap) { (void)snprintf(out, cap, "unknown"); for (size_t i = 0; pic_changelog[i]; i++) { const char *at = strstr(pic_changelog[i], "\n## "); if (at) { (void)snprintf(out, cap, "%.10s", at + 4); return; } } } size_t pic_help_count(void) { return NTOPICS; } const char *pic_help_name(size_t i) { return i < NTOPICS ? help_topics[i].name : NULL; } const char *pic_help_title(size_t i) { return i < NTOPICS ? help_topics[i].title : NULL; } int pic_help_is_reference(size_t i) { return i < NTOPICS && help_topics[i].reference; } static const pic_help_topic *find(const char *name) { for (size_t i = 0; name && i < NTOPICS; i++) { if (strcmp(help_topics[i].name, name) == 0) { return &help_topics[i]; } } return NULL; } char *pic_help_text(const char *name) { const pic_help_topic *t = find(name); size_t len = 0; char *out; if (!t) { return NULL; } for (const char *const *c = t->chunks; *c; c++) { len += strlen(*c); } if (!(out = malloc(len + 1))) { return NULL; } len = 0; for (const char *const *c = t->chunks; *c; c++) { size_t n = strlen(*c); memcpy(out + len, *c, n); len += n; } out[len] = '\0'; return out; } void pic_help_index(FILE *out) { fputs("pic help TOPIC shows a topic; /help TOPIC does in the terminal interface.\n", out); for (int ref = 0; ref <= 1; ref++) { fputs(ref ? "\nReference:\n" : "\nManual:\n", out); for (size_t i = 0; i < NTOPICS; i++) { if (help_topics[i].reference == ref) { fprintf(out, " %-20s %s\n", help_topics[i].name, help_topics[i].title); } } } } int pic_help_command(int argc, char **argv) { const pic_help_topic *t; if (argc == 0) { pic_help_index(stdout); return 0; } if (argc > 1 || !(t = find(argv[0]))) { if (argc > 1) { fputs("pic help: one topic at a time\n", stderr); } else { fprintf(stderr, "pic help: no topic named %s\n", argv[0]); } pic_help_index(stderr); return 1; } for (const char *const *c = t->chunks; *c; c++) { fputs(*c, stdout); } return 0; }