rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
text_hl.h File Reference

Syntax highlighting of one line of text: the spans of a line and the class of each, for the viewer to colour. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  text_hl_words_t
 The verdict words, one list per class. Any list may be empty. More...
struct  text_hl_unit_t
 A unit of the table and the class of a number in it. More...
struct  text_hl_span_t
 A span of a line. More...

Macros

#define TEXT_HL_LABEL_CELLS   24u
 Cells from column 0 a label's ":" or "=" stands in at most.
#define TEXT_HL_CLASS_ROWS(X)
 Every class of a span, one row each: X(name, css, role).
#define TEXT_HL_CLASS_ENUM(name, css, role)
 Expands a row of TEXT_HL_CLASS_ROWS to its enum entry.
#define TEXT_HL_UNIT_COUNT   20u
 Rows of text_hl_units.

Enumerations

enum  text_hl_class_t { TEXT_HL_CLASSES }
 The class of a span, in the order of TEXT_HL_CLASS_ROWS. More...
enum  text_hl_kind_t { TEXT_HL_KIND_TEXT = 0 , TEXT_HL_KIND_JSON = 1 , TEXT_HL_KIND_CSV = 2 , TEXT_HL_KIND_PLAIN = 3 }
 How a file's lines are classed. The numbers are stable. More...

Functions

size_t text_hl_line (const char *line, size_t len, size_t line_no, text_hl_kind_t kind, const text_hl_words_t *words, text_hl_span_t *out, size_t cap)
 The spans of one line.
text_hl_kind_t text_hl_kind_of (const char *name)
 How a file is classed, by its name: ".json" JSON, ".csv" CSV, ".txt" TEXT, in any case, a ".NEW" behind any of them taken off first; PLAIN for any other name.
const char * text_hl_word_core (const char *s, size_t *len)
 The word a writer's string gives: spaces taken off both ends, a "Label:" and the spaces after it taken off the front, then one pair of parentheses around it and a full stop behind it.
const char * text_hl_class_css (text_hl_class_t cls)
 The style sheet's name of a class (TEXT_HL_CLASS_ROWS).
text_hl_class_t text_hl_unit_class (const char *unit, size_t len)
 The class of a unit of the table.

Variables

const text_hl_unit_t text_hl_units [TEXT_HL_UNIT_COUNT]
 The units a number may carry, case as written: V mV A mA W rpm Hz us ms s /s deg Grad % mOhm B kB MB mΩ Ω; mOhm for the reports of 0.22 and older. test_text_hl holds it to every unit the report formats of ui_text.def put behind a number.

Detailed Description

Syntax highlighting of one line of text: the spans of a line and the class of each, for the viewer to colour.

A line is classed when it is drawn; nothing is stored. The spans cover the line from its first byte to its last, in order, without a gap; two neighbours never have the same class. A span starts and ends at an ASCII byte or at the line's ends, so it never splits a UTF-8 sequence.

Kinds, by the file's extension (text_hl_kind_of()):

TEXT every .TXT: the rules below, in this order:

  • hex: the whole line, for "NN: XX XX ..." (a KST register line), "checksum XXXXXXXX", and "key=hexdigits" (the KST programmer's journal: journal=, target=, port=, pin=, check=);
  • heading: the whole line, for line 1, and for a line without a label whose first character is an upper-case letter and whose text before the first "(" holds no lower-case letter: "SETTINGS IN FORCE", "ENDS (the search before programming)", "AKTIVE EINSTELLUNGEN"; at least 3 characters;
  • label: from column 0 up to and with the first ":" or "=" in the first TEXT_HL_LABEL_CELLS cells, when the line starts with no space and a space, a tab or the line's end follows it;
  • then, along the rest: a comment from a "#" at the start or after a space or tab to the line's end; a verdict word; a number with a unit of the unit table; anything else is TEXT. JSON .json: keys, strings, numbers, true / false / null, and the marks { } [ ] , : as punctuation. CSV .csv: line 1 is the header; the delimiters are punctuation: ";" on a line that holds one, "," on a line that does not. PLAIN any other file: one TEXT span.

Verdict words are the caller's: three lists of strings, one per class, which the screen builds from the report writers' text IDs in every language, so a report written in German on a panel showing English is classed the same, and a changed word in ui_text.def changes the classes with it. A word matches whole and in its case: "PASS" is no verdict in "PASSED" or as "pass". Where words overlap, the longest one at a place wins ("NICHT BESTANDEN" over "BESTANDEN"). Each string is matched by its core (text_hl_word_core()), so a writer's string with a label in front, parentheses around or a full stop behind gives the word itself.

Numbers: an optional sign, digits, and a "." with digits, at a place no letter, digit or "." is in front of, and ending at a place no "." with a digit follows. With a unit of the table behind, joined ("6.00V", "100mΩ") or after one space, number and unit are one span of the unit's class; a number without one is TEXT. A unit ends at a space, a punctuation mark or the line's end. A joined word that is no unit of the table ("6.00Volt", "5x") makes the whole no number: TEXT.

Pure C: no ui, no gfx, no text table.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ TEXT_HL_CLASS_ENUM

#define TEXT_HL_CLASS_ENUM ( name,
css,
role )
Value:
TEXT_HL_##name,

Expands a row of TEXT_HL_CLASS_ROWS to its enum entry.

◆ TEXT_HL_CLASS_ROWS

#define TEXT_HL_CLASS_ROWS ( X)
Value:
X(TEXT, "tx", UI_C_TEXT) \
X(HEADING, "hd", UI_C_ACCENT) \
X(LABEL, "lb", UI_C_TEXT_DIM) \
X(OK, "ok", UI_C_OK) \
X(FAIL, "fl", UI_C_DANGER) \
X(WARN, "wn", UI_C_WARN) \
X(VOLT, "vo", UI_C_VOLT) \
X(CURR, "cu", UI_C_CURR) \
X(POWER, "pw", UI_C_POWER) \
X(RATE, "rt", UI_C_RPM) \
X(UNIT, "un", UI_C_TEAL) \
X(COMMENT, "cm", UI_C_TEXT_FAINT) \
X(HEX, "hx", UI_C_TEXT_DIM) \
X(KEY, "ky", UI_C_TEXT_DIM) \
X(NUMBER, "nm", UI_C_TEAL) \
X(LITERAL, "lt", UI_C_LILAC) \
X(PUNCT, "pu", UI_C_TEXT_FAINT) \
X(CSV_HEAD, "ch", UI_C_ACCENT)
#define FAIL(d,...)
The first reason stands.
Definition esc_json.c:60

Every class of a span, one row each: X(name, css, role).

name is the class's enum name after TEXT_HL_; css a short name for the Wi-Fi page's style sheet; role the theme's colour role (ui_theme.h's ui_color_id_t) the screen and the page draw the class in. The rows' order gives the enum's numbers, which are stable: a new class goes at the end. This file and text_hl.c expand the first two columns only, so shared/files includes nothing of ui; a reader that expands role includes ui_theme.h. Light and dark palettes both hold every role.

Parameters
XThe row macro.

Enumeration Type Documentation

◆ text_hl_class_t

The class of a span, in the order of TEXT_HL_CLASS_ROWS.

Enumerator
TEXT_HL_CLASSES 

the count of classes

◆ text_hl_kind_t

How a file's lines are classed. The numbers are stable.

Enumerator
TEXT_HL_KIND_TEXT 

the rules of a bench text

TEXT_HL_KIND_JSON 

JSON

TEXT_HL_KIND_CSV 

CSV

TEXT_HL_KIND_PLAIN 

no classes

Function Documentation

◆ text_hl_class_css()

const char * text_hl_class_css ( text_hl_class_t cls)

The style sheet's name of a class (TEXT_HL_CLASS_ROWS).

Parameters
clsThe class.
Returns
Its short name; "tx" for a value out of range.

◆ text_hl_kind_of()

text_hl_kind_t text_hl_kind_of ( const char * name)

How a file is classed, by its name: ".json" JSON, ".csv" CSV, ".txt" TEXT, in any case, a ".NEW" behind any of them taken off first; PLAIN for any other name.

Parameters
nameThe file name; NULL is PLAIN.
Returns
The kind.

◆ text_hl_line()

size_t text_hl_line ( const char * line,
size_t len,
size_t line_no,
text_hl_kind_t kind,
const text_hl_words_t * words,
text_hl_span_t * out,
size_t cap )

The spans of one line.

With room for fewer spans than the line has, the last span the room holds is TEXT and reaches to the line's end.

Parameters
lineThe line's bytes, without its line end.
lenTheir count.
line_noThe line's index in the file, from 0.
kindHow the file is classed.
wordsThe verdict words; NULL for none.
outOut: the spans.
capRoom in out.
Returns
Spans written; 0 for an empty line, a NULL or cap 0.

◆ text_hl_unit_class()

text_hl_class_t text_hl_unit_class ( const char * unit,
size_t len )

The class of a unit of the table.

Parameters
unitThe unit's bytes.
lenTheir count.
Returns
TEXT_HL_VOLT, TEXT_HL_CURR, TEXT_HL_POWER, TEXT_HL_RATE or TEXT_HL_UNIT; TEXT_HL_TEXT for a word that is no unit.

◆ text_hl_word_core()

const char * text_hl_word_core ( const char * s,
size_t * len )

The word a writer's string gives: spaces taken off both ends, a "Label:" and the spaces after it taken off the front, then one pair of parentheses around it and a full stop behind it.

"Brown-out: not run" gives "not run", " (cut short)" "cut short", "Not run." "Not run".

Parameters
sThe string; NULL gives an empty word.
lenOut: bytes of the word.
Returns
Its first byte, inside s.