raz / commit 1af2d2ec

commit
1af2d2eca21f841a42e3d1f8d2fd89d5a4699966
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
9ae09cbd
PROPOSALS: Opt's spelling, -h for a program, an optional value, number with no top; Out.lines; Buf.cut met again

patch · log

1 file changed, +69 -0

PROPOSALS.md modified +69 -0

@@ -656,3 +656,72 @@
656656 Met in rrem's `replace`, which adds each match's replacement to the
657657 caller's buffer and, when a search stops with `TooCostly` or `NoRoom`,
658658 leaves the buffer as it was.
659+Met again in rre's reading window, which drops the lines it has
660+searched by shortening the buffer.
661+
662+## The spelling of the option just read
663+
664+`Opt.Parser` keeps how the option just read was written (`spelt`, no
665+dashes) to word its own messages, `--budget wants a number from ...`,
666+but keeps it private, so a program that refuses a value with
667+`Opt.fail` must name the option again itself:
668+
669+```
670+| keyInclude:
671+ if not addGlob(p.value) then
672+ Opt.fail(ADR(p), "--include wants a glob, not ...");
673+ end;
674+```
675+
676+The name is then in two places, the table and the message, which
677+`Opt` was made to keep apart; and the message says `--include` even
678+when the program has a letter for it and the user wrote that. The
679+proposal: `spelt*` exported, read only, beside `letter`, `value` and
680+`long`; or `Opt.refuse*(p: ^Parser; wants: []U8)`, which writes
681+`{-x or --long} wants {wants}, not '{value}'` as `number` does. It
682+breaks no program.
683+
684+Met in rre's `--include` and `--exclude`, whose globs Rwglob checks.
685+
686+## `-h` for a program that wants it
687+
688+`Opt` takes `-h` and `--help` for itself, and a table that names
689+either is the program's mistake ("-h and --help are Opt's"). grep's
690+`-h`, no file names, can't be written: rre, which follows grep, has
691+`--no-filename` without a letter. The proposal: a table may give `-h`
692+to an option of its own, and then help is `--help` only, as it is for
693+grep. It breaks no program, since no table names `-h` now.
694+
695+## An option whose value may be left out
696+
697+An option takes a value always or never. grep's `--color` is
698+`--color[=WHEN]`: bare, it means `auto`. In `Opt`, rre's `--color`
699+must have its value, and `rre --color x` reads `x` as the value, not
700+the pattern. The proposal: a row's `value` written `[WHEN]` makes the
701+value optional, given only as `--color=WHEN` (never as the next
702+argument, as getopt's `::` has it), `""` when left out; for a letter,
703+only joined, `-cWHEN`. It breaks no program.
704+
705+## `Opt.number` with no top
706+
707+`Opt.number(p, lo, hi)` refuses a value past `hi` and says so; a
708+number that has no top is given `hi` as `I64`'s largest, and the
709+message reads `--budget wants a number from 0 to
710+9223372036854775807`. The proposal: the message says `a number from
711+0 up` when `hi` is the largest `I64`; nothing else changes.
712+
713+## `Out` a line at a time through a pipe
714+
715+`Out` writes at each line feed only when standard output is a
716+terminal; through a pipe it waits for 4 KB. A command that filters a
717+stream that comes slowly, `tail -f log | rre error | less`, shows
718+nothing until 4 KB of matches have come. grep has `--line-buffered`
719+for this. The proposal, in `Out`:
720+
721+```
722+proc lines*(on: BOOL); (* write at each line feed, whatever standard output is *)
723+```
724+
725+It breaks no program. Met in rre, which doesn't yet offer
726+`--line-buffered` for want of it (or of an `Out.flush` after every
727+line, which costs a write per line always).