tinymux/tools/ansify
Stephen Dennis 0a934a7d78 build(ragel): guard date_scan and strip #line from the remaining outputs (#2029)
Two remainders from #2025.

## date_scan.cpp was unguarded

hooks/pre-commit knew about four Ragel outputs; mux/lib/date_scan.cpp was
absent from GENERATED_GENS entirely, so it could be hand-edited and
committed without its .rl and nothing objected -- while being listed in
docs/generated-files.md and shipped via unix/TOC.patchable. Added to all
three parallel arrays, which now hold 27 each.

Verified by alignment rather than by count: equal lengths prove nothing
about correspondence, so the check confirms every ragel triple's basenames
match and its rule lives in the same directory as its output. Then
exercised: staging date_scan.cpp alone is now blocked, naming date_scan.rl
as its source.

## Six more outputs carried #line

#2025's scope was right for what the mux build regenerates and dounix.sh
ships, but these have live rules of their own and could still dirty a tree:

  testcases/tools/unformat.c    28    testcases/tools/Makefile  (%.c: %.rl)
  testcases/tools/reformat.c    23    same
  ragel/trigger_match.c         16    ragel/Makefile
  tools/ansify/ansify.c         19    tools/ansify/Makefile  (make regen)
  client/tf/src/script_lex.cpp  67    client/tf/CMakeLists.txt
  client/tf/src/input_lex.cpp   62    same

The issue reported "no rule found" for trigger_match.c and ansify.c. Both
were wrong: ragel/Makefile:25 generates trigger_match.c on dependency, and
tools/ansify/Makefile has an explicit `regen` target. Neither is inert --
ansify's is opt-in rather than implicit, which is why it reads as absent.

Each regenerated through its OWN rule rather than by running sed by hand,
so the rule is what is under test. All six are idempotent across a second
regeneration, and the diffs are 215 deletions, every one a #line, nothing
added.

ragel/color_ops.c is generated from the same ../mux/lib/color_ops.rl as the
shipped copy but is not tracked, so it could not dirty anything; its rule
gets the strip anyway, so the two generations of one source cannot disagree
if it is ever checked in.

client/tf could not be built here -- src/regex_utils.h needs pcre2.h, which
is not on that target's include path on macOS -- but that is a pre-existing
gap unrelated to this change. The Ragel custom commands themselves DID run
(cmake configure succeeds once NCURSESW_LIB is pointed at a macOS ncurses),
and both outputs came back stripped, so the CMake edit is exercised rather
than assumed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-04 00:59:11 -06:00
..
samples Add tools/ansify: MUX percent-color to ANSI (Ragel → C) 2026-08-01 17:12:16 -06:00
tests Add tools/ansify: MUX percent-color to ANSI (Ragel → C) 2026-08-01 17:12:16 -06:00
.gitignore Add tools/ansify: MUX percent-color to ANSI (Ragel → C) 2026-08-01 17:12:16 -06:00
ansify.c build(ragel): guard date_scan and strip #line from the remaining outputs (#2029) 2026-08-04 00:59:11 -06:00
ansify.rl Add tools/ansify: MUX percent-color to ANSI (Ragel → C) 2026-08-01 17:12:16 -06:00
Makefile build(ragel): guard date_scan and strip #line from the remaining outputs (#2029) 2026-08-04 00:59:11 -06:00
README.md Add tools/ansify: MUX percent-color to ANSI (Ragel → C) 2026-08-01 17:12:16 -06:00

ansify

Convert TinyMUX percent-color substitutions (%x / %c) into real ANSI escape sequences. Commonly used to “ansify” a connect screen or other MUX-style text for display outside the server.

This is the proper home for the old FTP contrib/ansify.l tool (Brazil@BrazilMUX). That version was a flex scanner; this one is a Ragel -G2 scanner (ansify.rlansify.c), same generator style as mux/muxescape and mux/lib/color_ops.

Build

cd tools/ansify
make          # compile checked-in ansify.c → ./ansify (no Ragel required)
make test

A C compiler is enough for a normal build. Generated ansify.c is checked in so nobody needs Ragel just to compile or run the tool.

After editing the scanner source (ansify.rl):

make regen    # ragel -G2 -C -o ansify.c ansify.rl
make test
# commit both ansify.rl and ansify.c

Do not hand-edit ansify.c. Not part of the top-level mux autotools build.

Usage

# stdin → stdout
./ansify < connect.mux > connect.txt

# files
./ansify samples/connect.mux

# strip codes instead of expanding
./ansify --strip < colored.txt > plain.txt

Codes

Prefix is %x or %c (case of the prefix is ignored).

Kind Letters
Attributes n normal, h hilite, u underline, f blink, i inverse
Foreground x/k black, r g y b m c w
Background X/K black, R G Y B M C W

Black uses x/X in current TinyMUX (aColors). The original ansify.l used k/K; both are accepted.

Extended forms:

Form Result
%x<#RRGGBB> / %x<#RGB> truecolor FG (ESC[38;2;…m)
%x<bg#RRGGBB> / %x<#RRGGBB;bg> truecolor BG
%x<N> xterm-256 FG (N = 0..255)
%x<bgN> xterm-256 BG
%% literal %

%c is accepted as an alias for %x in all of the above.

History

The FTP mirror once shipped contrib/ansify.l as a flex source with a tongue-in-cheek README. That tree was retired from the public FTP. The tool lives here as a Ragel machine so it stays consistent with the rest of TinyMUXs scanner tooling and can evolve with the servers color language.

License

Same as the TinyMUX repository.