260808.4.1 · 5ba030cac3c000feb2351ae65bb181ae3a294c1d
https://gitlab.com/saalen/highlight/-/work_items/224 added AnsiIndex theme attribute
Themes had no effect with --out-format=ansi, which emitted one hard coded sequence per element. A theme element may now carry AnsiIndex, a terminal palette index from 0 to 15, which is used for that element instead.
Elements without the attribute keep their previous sequence, so every shipped theme renders unchanged in this format. themes/terminal.theme shows the attribute in use.
reading declarations
@@ -383,9 +383,11 @@ Note: Using a plug-in script is the preferred way to enhance styling. ==== Terminal output: -As there are only a few colours defined for ANSI terminal output, there exists-only one hard coded colour theme with `--out-format=ansi`. You should therefore-use `--out-format=xterm256` to enable output in 256 colours. The 256 colour mode+ANSI terminal output is limited to the 16 colours of the terminal palette, so+themes are ignored with `--out-format=ansi` unless their elements define an+`AnsiIndex` attribute. Elements without one keep the hard coded default sequence,+and theme font attributes are not applied in this format.+Use `--out-format=xterm256` to enable output in 256 colours. The 256 colour mode is supported by recent releases of xterm, rxvt and Putty (amongst others). Recently published terminal emulators also support 16m colors, this mode is enabled with `--out-format=truecolor`.@@ -789,7 +791,7 @@ to use one of the included Base16 themes (located in {themes_base16}). ==== Format attributes ................................................................................-Attributes = {Colour, Bold?, Italic?, Underline?, Custom? }+Attributes = {Colour, Bold?, Italic?, Underline?, AnsiIndex?, Custom? } ................................................................................ [horizontal]@@ -797,6 +799,8 @@ Colour:: String, defines colour in HTML hex notation (`#rrggbb`) Bold:: Boolean, true if font should be bold (optional) Italic:: Boolean, true if font should be italic (optional) Underline:: Boolean, true if font should be underlined (optional)+AnsiIndex:: Number, terminal palette index 0-15, applied with+ `--out-format=ansi` only (optional) Custom:: Array, contains `Format` and `Style` for custom styles ==== Theme elements
@@ -379,9 +379,12 @@ Hinweis: Ein Plug-In Skript ist die bessere Methode das Styling anzupassen. ==== Terminal-Ausgabe: -Da es nur wenige Farben zur ANSI-Ausgabe im Terminal gibt, existiert nur ein-hartkodiertes Farbschema fuer `--out-format=ansi`. Daher sollte nach Moeglichkeit-`--out-format=xterm256` verwendet werden, um eine Ausgabe in 256 Farben zu erhalten.+Die ANSI-Ausgabe im Terminal ist auf die 16 Farben der Terminal-Palette begrenzt.+Themes werden mit `--out-format=ansi` daher ignoriert, sofern deren Elemente kein+`AnsiIndex`-Attribut definieren. Elemente ohne dieses Attribut behalten die+hartkodierte Standardsequenz, Font-Attribute des Themes werden in diesem Format+nicht angewendet.+Fuer eine Ausgabe in 256 Farben sollte `--out-format=xterm256` verwendet werden. Der 256 Farb-Modus wird z.B. von xterm, rxvt und Putty unterstuetzt. Neuere Terminal-Emulatoren unterstuetzen auch 16 Millionen Farben, dies wird mit `--out-format=truecolor` aktiviert.
@@ -377,9 +377,11 @@ Note : Un script plug-in est une meilleure méthode pour personnaliser le style. ==== Sortie Terminal : -Comme il n'y a que peu de couleurs disponibles pour la sortie ANSI dans le terminal,-il n'existe qu'un schéma de couleurs codé en dur pour `--out-format=ansi`. Par conséquent,-il est préférable d'utiliser `--out-format=xterm256` si possible pour obtenir une+La sortie ANSI dans le terminal est limitée aux 16 couleurs de la palette du terminal.+Les thèmes sont donc ignorés avec `--out-format=ansi`, sauf si leurs éléments définissent+un attribut `AnsiIndex`. Les éléments sans cet attribut conservent la séquence par défaut+codée en dur, et les attributs de police du thème ne sont pas appliqués dans ce format.+Il est préférable d'utiliser `--out-format=xterm256` si possible pour obtenir une sortie en 256 couleurs. Le mode 256 couleurs est pris en charge par exemple par xterm, rxvt et Putty. Les émulateurs de terminal plus récents prennent également en charge 16 millions de
@@ -31,6 +31,7 @@ along with Highlight. If not, see <http://www.gnu.org/licenses/>. using std::string; using std::string_view;+using std::to_string; namespace highlight {@@ -53,6 +54,15 @@ string AnsiGenerator::getOpenTag ( string_view font, } +string AnsiGenerator::getOpenTag ( const ElementStyle &elem,+ string_view font, string_view fgCol )+{+ int idx = elem.getAnsiIndex();+ if ( idx < 0 ) return getOpenTag ( font, fgCol );+ return getOpenTag ( font, to_string ( idx<8 ? 30+idx : 90+idx-8 ) );+}++ AnsiGenerator::AnsiGenerator() : CodeGenerator ( ESC_ANSI ) { newLineTag = "\n";@@ -62,19 +72,19 @@ AnsiGenerator::AnsiGenerator() : CodeGenerator ( ESC_ANSI ) void AnsiGenerator::initOutputTags() { openTags = {- getOpenTag ( "00", "39" ),- getOpenTag ( "00", "31" ), //str- getOpenTag ( "00", "34" ), //number- getOpenTag ( "00", "34" ), //sl comment- getOpenTag ( "00", "34" ), //ml comment- getOpenTag ( "00", "35" ), //escapeChar- getOpenTag ( "00", "35" ), //directive- getOpenTag ( "00", "31" ), //directive string- getOpenTag ( "00", "39" ), //linenum- getOpenTag ( "00", "39" ), //symbol- getOpenTag ( "00", "35" ), //interpolation- getOpenTag ( "01", "31" ), //error- getOpenTag ( "01", "31" ) //warning+ getOpenTag ( docStyle.getDefaultStyle(), "00", "39" ),+ getOpenTag ( docStyle.getStringStyle(), "00", "31" ), //str+ getOpenTag ( docStyle.getNumberStyle(), "00", "34" ), //number+ getOpenTag ( docStyle.getSingleLineCommentStyle(), "00", "34" ), //sl comment+ getOpenTag ( docStyle.getCommentStyle(), "00", "34" ), //ml comment+ getOpenTag ( docStyle.getEscapeCharStyle(), "00", "35" ), //escapeChar+ getOpenTag ( docStyle.getPreProcessorStyle(), "00", "35" ), //directive+ getOpenTag ( docStyle.getPreProcStringStyle(), "00", "31" ), //directive string+ getOpenTag ( docStyle.getLineStyle(), "00", "39" ), //linenum+ getOpenTag ( docStyle.getOperatorStyle(), "00", "39" ), //symbol+ getOpenTag ( docStyle.getInterpolationStyle(), "00", "35" ), //interpolation+ getOpenTag ( docStyle.getErrorStyle(), "01", "31" ), //error+ getOpenTag ( docStyle.getErrorMessageStyle(), "01", "31" ) //warning }; closeTags.assign ( NUMBER_BUILTIN_STATES, "\033[m" );@@ -103,7 +113,8 @@ string AnsiGenerator::maskCharacter ( unsigned char c ) string AnsiGenerator::getKeywordOpenTag ( unsigned int styleID ) {- return ( styleID ) ?getOpenTag ( "00", "32", "" ) :getOpenTag ( "00", "33" );+ return getOpenTag ( docStyle.getKeywordStyle ( currentSyntax->getKeywordClasses() [styleID] ),+ "00", ( styleID ) ?"32" :"33" ); } string AnsiGenerator::getKeywordCloseTag ( unsigned int styleID )
@@ -141,4 +141,12 @@ void ElementStyle::setCustomOverride(bool override) { customOverride = override; } +int ElementStyle::getAnsiIndex() const {+ return ansiIndex;+}++void ElementStyle::setAnsiIndex(int idx) {+ ansiIndex = idx;+}+ }
@@ -91,6 +91,7 @@ void ThemeReader::initStyle(ElementStyle& style, const Diluculum::LuaVariable& v string styleColor="#000000"; bool styleBold=false, styleItalic=false, styleUnderline=false;+ int styleAnsiIndex=-1; if (var["Colour"].value()!=Diluculum::Nil) { styleColor= var["Colour"].value().asString();@@ -112,10 +113,16 @@ void ThemeReader::initStyle(ElementStyle& style, const Diluculum::LuaVariable& v style.setCustomOverride(false); } + if (var["AnsiIndex"].value()!=Diluculum::Nil) {+ lua_Integer idx = var["AnsiIndex"].value().asInteger();+ if (idx>=0 && idx<=15) styleAnsiIndex=idx;+ }+ style.setColour(Colour(styleColor)); style.setBold(styleBold); style.setItalic(styleItalic); style.setUnderline(styleUnderline);+ style.setAnsiIndex(styleAnsiIndex); } bool ThemeReader::load ( const string &styleDefinitionPath , OutputType type, bool loadSemanticStyles)
@@ -74,6 +74,11 @@ private: std::string getOpenTag ( std::string_view font, std::string_view fgCol, std::string_view bgCol="" ); + /** \return ANSI formatting sequences of the element's terminal colour index,+ or the given default sequence if the element defines no index */+ std::string getOpenTag ( const ElementStyle &elem,+ std::string_view font, std::string_view fgCol );+ /** initialize tags in specific format according to colouring information provided in DocumentStyle */ void initOutputTags() override;
@@ -68,6 +68,7 @@ public: underline = other.isUnderline(); customOverride = other.getCustomOverride(); customAttribute = other.getCustomAttribute();+ ansiIndex = other.getAnsiIndex(); } /** operator overloading */@@ -79,6 +80,7 @@ public: underline = other.isUnderline(); customOverride = other.getCustomOverride(); customAttribute = other.getCustomAttribute();+ ansiIndex = other.getAnsiIndex(); return *this; }@@ -135,10 +137,17 @@ public: void setCustomOverride(bool override); + /** \return terminal colour index (0-15), or -1 if the element defines none */+ int getAnsiIndex() const;++ /** \param idx terminal colour index (0-15), or -1 to use the built-in default */+ void setAnsiIndex(int idx);+ private: Colour colour; bool bold, italic, underline, customOverride; std::string customAttribute;+ int ansiIndex{-1}; }; }
@@ -0,0 +1,43 @@+Description="Terminal palette (ANSI colour indices)"++Categories = {"dark"}++Default = { Colour="#c0c0c0", AnsiIndex=7 }+Canvas = { Colour="#000000" }+Number = { Colour="#00aaaa", AnsiIndex=6 }+Escape = { Colour="#aa00aa", AnsiIndex=5 }+String = { Colour="#00aa00", AnsiIndex=2 }+StringPreProc = { Colour="#55ff55", AnsiIndex=10 }+BlockComment = { Colour="#555555", AnsiIndex=8 }+PreProcessor = { Colour="#aa5500", AnsiIndex=3 }+LineNum = { Colour="#555555", AnsiIndex=8 }+Operator = { Colour="#c0c0c0", AnsiIndex=7 }+LineComment = BlockComment+Interpolation = { Colour="#55ffff", AnsiIndex=14 }++Keywords = {+ { Colour="#ffffff", AnsiIndex=15 },+ { Colour="#5555ff", AnsiIndex=12 },+ { Colour="#ff5555", AnsiIndex=9 },+ { Colour="#ff55ff", AnsiIndex=13 },+ { Colour="#ffff55", AnsiIndex=11 },+ { Colour="#55ffff", AnsiIndex=14 },+}++-- new LSP based elements:++SemanticTokenTypes = {+ { Type = 'type', Style = Keywords[2] },+ { Type = 'class', Style = Keywords[1] },+ { Type = 'struct', Style = Keywords[4] },+ { Type = 'interface', Style = Keywords[1] },+ { Type = 'parameter', Style = Keywords[6] },+ { Type = 'variable', Style = Keywords[5] },+ { Type = 'enumMember', Style = Keywords[5] },+ { Type = 'function', Style = Keywords[4] },+ { Type = 'method', Style = Keywords[4] },+ { Type = 'keyword', Style = Keywords[1] },+ { Type = 'number', Style = Number },+ { Type = 'regexp', Style = String },+ { Type = 'operator', Style = Operator },+}