SLAdvantageEmitter.sleela
lib/advantage/output/SLAdvantageEmitter.sleela · 150 line(s) · sleela
<< lib/advantage/output/SLAdvantageEmitter.sleela
SLeeLa Standard Library Definition.
Definition: The emitter -- the output API advantage modules call to report
themselves, routed through a sink and optionally formatted via CommonRails. >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< Modules used to be silent (only the demos printed). The emitter gives any >
< module a small output API that works the same regardless of destination: >
< line(text) -- emit a raw line >
< state(label, msg) -- emit a labelled status line >
< report(subject, body) -- emit "subject: body" >
< When the sink's target is COMMONRAILS, state(...) is formatted through the >
< toolchain's PrintRail (naming PrintRail auto-resolves lib/common-rails), so >
< advantage output shares the one professional-printing surface. For other >
< targets the plain text is routed as-is. The sink decides terminal vs socket >
< vs silent; the emitter decides formatting. >
class SLAdvantageEmitter {
< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
<< Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
or catalog can read and (where appropriate) override this record.
Values are faithful to the subject's real origin where publicly known. >>
String metaVersion = "1.0.0";
int metaId = 10561;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-11-08";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-11-08";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 8;
< metaNationalSchedule: a real, citable instrument or "none" >
String metaNationalSchedule = "none";
String getMetaVersion() { return metaVersion; }
void setMetaVersion(String v) { metaVersion = v; }
int getMetaId() { return metaId; }
void setMetaId(int v) { metaId = v; }
String getAuthor() { return metaAuthor; }
void setAuthor(String v) { metaAuthor = v; }
String getDate() { return metaDate; }
void setDate(String v) { metaDate = v; }
String getCopyright() { return metaCopyright; }
void setCopyright(String v) { metaCopyright = v; }
String getTrademark() { return metaTrademark; }
void setTrademark(String v) { metaTrademark = v; }
String getCorporation() { return metaCorporation; }
void setCorporation(String v) { metaCorporation = v; }
String getOrigin() { return metaOrigin; }
void setOrigin(String v) { metaOrigin = v; }
String getBirthDate() { return metaBirthDate; }
void setBirthDate(String v) { metaBirthDate = v; }
int getScienceRating() { return metaScienceRating; }
void setScienceRating(int v) { metaScienceRating = v; }
String getNationalSchedule() { return metaNationalSchedule; }
void setNationalSchedule(String v) { metaNationalSchedule = v; }
SLAdvantageSink sink;
< reused CommonRails renderer for the commonrails target >
PrintRail rail;
void configure(SLAdvantageSink s) {
sink = s;
rail = new PrintRail();
}
SLAdvantageSink getSink() { return sink; }
< Emit a raw line to the sink's target, with its byte length for the socket >
< wire account. >
void line(String text, int textChars) {
sink.emit(text, textChars);
}
<< Emit the Advantage(TM) product brand line in the customary red (ANSI SGR
31, red + classic), matching how SLeeLa and Sleelvac render their identity.
This is OPT-IN and presentation-only: call it when writing to an
interactive terminal. It is NOT part of the validated demo output paths,
because raw ANSI would corrupt captured/piped text and exact-match checks
(there is no TTY probe on the SLeeLa surface). The escape is \033 (ESC),
the trademark is \u2122. Byte count is passed as 0 (decoration only). >>
void brandAdvantage() {
sink.emit("\033[31mAdvantage\u2122\033[0m", 0);
}
<< Emit a labelled status line. For the COMMONRAILS target this is rendered
by PrintRail.stateLineText, which -- like all of CommonRails -- needs
explicit character counts because Core has no string-length primitive;
the caller passes labelChars and messageChars. For every other target the
plain "[LABEL] message" is routed. The byte count handed to the sink is
the plain "[label] message" length (label + 2 brackets + 1 space + msg). >>
void state(String label, int labelChars, String message, int messageChars) {
int plainBytes = labelChars + 3 + messageChars;
if (sink.getTarget() == 1) {
String rendered = rail.stateLineText(label, labelChars, message, messageChars);
sink.emit(rendered, plainBytes);
} else {
sink.emit("[" + label + "] " + message, plainBytes);
}
}
< Convenience state() when CommonRails formatting is not needed: no counts. >
void status(String label, String message) {
sink.emit("[" + label + "] " + message, 0);
}
< Emit "subject: body". >
void report(String subject, String body) {
sink.emit(subject + ": " + body, 0);
}
<< A field/value pair rendered as a single CommonRails table row for the
COMMONRAILS target (a bordered "| field | value |" cell), or plain
"field: value" otherwise. Column widths w0/w1 size the bordered cells. >>
void pair(String field, int fieldChars, String value, int valueChars,
int w0, int w1) {
int plainBytes = fieldChars + 2 + valueChars;
if (sink.getTarget() == 1) {
String row = rail.tableRowText(field, fieldChars, w0, value, valueChars, w1, true);
sink.emit(row, plainBytes);
} else {
sink.emit(field + ": " + value, plainBytes);
}
}
<< A producer "component" line for the COMMONRAILS target -- the professional
component surface (object id, date sequence, name, message) -- or a plain
"name #oid: message" otherwise. >>
void component(String name, int nameChars, int oid, int dateSeq,
String message, int messageChars) {
if (sink.getTarget() == 1) {
String comp = rail.componentLine(name, nameChars, oid, dateSeq, message);
sink.emit(comp, nameChars + messageChars + 8);
} else {
sink.emit(name + " #" + oid + ": " + message, nameChars + messageChars + 4);
}
}
< Emit a module rating line, e.g. "GRADE integration -> S10". Char counts >
< are supplied so the commonrails target aligns correctly. >
void grade(String moduleName, int moduleChars, String rating, int ratingChars) {
state("GRADE", 5, moduleName + " -> " + rating, moduleChars + 4 + ratingChars);
}
}