You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<H4 class="md-title-1">Customizing ANSI Themes</H4><H4 class="md-title-2">Overview</H4><p class="md-phrase">Nuts provides a powerful theming system for ANSI/NTF (Nuts Text Format) output. Themes determine the actual colors used for semantic tokens such as <mark class="md-code md-code-ac1">primary1</mark>, <mark class="md-code md-code-ac1">error</mark>, <mark class="md-code md-code-ac1">warn</mark>, etc. You can switch between built‑in themes or create your own.</p><H4 class="md-title-2">Switching Themes at Runtime</H4><pre><code class="language-java">import net.thevpc.nuts.text.NTextTheme;
2175
-
2176
-
// Load a theme by its name (e.g., "dark", "light", "horizon")
</code></pre>You can also set the theme via a configuration property or environment variable:<ul class="md-ul"><li class="md-uli"><p class="md-phrase"><b class="md-bold">Configuration property</b>: <code class="md-code md-code-ac1">nuts.text.theme = dark</code></p></li><li class="md-uli"><p class="md-phrase"><b class="md-bold">Environment variable</b>: <code class="md-code md-code-ac1">NUTS_TEXT_THEME=dark</code></p></li></ul><H4 class="md-title-2">Defining Your Own Theme</H4><p class="md-phrase">Create a <code class="md-code md-code-ac1">.ntf-theme</code> file in any location accessible to your application. The file format is a simple <code class="md-code md-code-ac1">key=value</code> list where keys are semantic token names and values are color specifications.</p><pre><code class="language-properties"># example.ntf-theme
2181
-
primary1 = #1e90ff
2182
-
secondary5 = #ffdead
2183
-
error = #ff5555
2184
-
warn = #ffb86c
2185
-
info = #8be9fd
2186
-
</code></pre><p class="md-phrase">Place your custom theme file on the classpath (e.g., <code class="md-code md-code-ac1">src/main/resources/META-INF/ntf-themes/</code>) or load it explicitly:</p><pre><code class="language-java">NTextTheme custom = NTextTheme.load("classpath:/my-theme.ntf-theme");
2187
-
Nuts.textTheme().setTheme(custom);
2188
-
</code></pre><H4 class="md-title-2">Built‑in Theme Examples</H4>The repository ships a few example themes you can use as a starting point:<ul class="md-ul"><li class="md-uli"><p class="md-phrase"><b class="md-bold">example.ntf-theme</b> – a balanced default theme.</p></li><li class="md-uli"><p class="md-phrase"><b class="md-bold">horizon.ntf-theme</b> – a dark blue horizon style.</p></li><li class="md-uli"><p class="md-phrase"><b class="md-bold">min.ntf-theme</b> – a minimalistic light theme.</p></li></ul><p class="md-phrase">You can find these files under <code class="md-code md-code-ac1">src/resources/theme-examples/</code>.</p><H4 class="md-title-2">Applying Themes to Specific Output</H4><p class="md-phrase">If you need to render a message with a non‑global theme, use the <mark class="md-code md-code-ac1">NText</mark> API directly:</p><pre><code class="language-java">NText themed = NText.of("Hello World").withTheme(custom);
<H4 class="md-title-1">Customizing ANSI Themes</H4><H4 class="md-title-2">Overview</H4><p class="md-phrase">Nuts provides a powerful theming system for ANSI and NTF (Nuts Text Format) formatted output. Themes map semantic text styles (such as <mark class="md-code md-code-ac1">PRIMARY</mark>, <mark class="md-code md-code-ac1">KEYWORD</mark>, <mark class="md-code md-code-ac1">ERROR</mark>, <mark class="md-code md-code-ac1">WARN</mark>, <mark class="md-code md-code-ac1">INFO</mark>, <mark class="md-code md-code-ac1">PATH</mark>, etc.) to specific terminal colors, supporting 16-color ANSI, 256-color palettes, and 24-bit RGB true-colors.</p><p class="md-phrase">The <mark class="md-code md-code-ac1">--theme</mark> option and the <mark class="md-code md-code-ac1">NTextTheme</mark> API support specifying theme parameters by <b class="md-bold">theme name</b> (for built-in or cached themes) or by <b class="md-bold">file path / URL</b> (for custom <code class="md-code md-code-ac1">.ntf-theme</code> files).</p><H4 class="md-title-2">Built-in Themes & Default Names</H4><p class="md-phrase">Nuts includes several built-in themes available on the classpath (<code class="md-code md-code-ac1">META-INF/ntf-themes/</code>). You can reference them directly by name:</p><ul class="md-ul"><li class="md-uli"><p class="md-phrase"><b class="md-bold"><mark class="md-code md-code-ac1">default</mark></b> – OS-dependent default theme (<mark class="md-code md-code-ac1">grass</mark> on Windows, standard theme on Unix/Linux).</p></li><li class="md-uli"><p class="md-phrase"><b class="md-bold"><mark class="md-code md-code-ac1">ansi</mark></b> – Basic 16-color ANSI palette theme.</p></li><li class="md-uli"><p class="md-phrase"><b class="md-bold"><mark class="md-code md-code-ac1">grass</mark></b> – Green/nature-toned palette, optimized for Windows terminals.</p></li><li class="md-uli"><p class="md-phrase"><b class="md-bold"><mark class="md-code md-code-ac1">horizon</mark></b> – Dark blue horizon theme, default on Unix/Linux.</p></li><li class="md-uli"><p class="md-phrase"><b class="md-bold"><mark class="md-code md-code-ac1">whiteboard</mark></b> – Light background theme using 24-bit true colors.</p></li></ul><p class="md-phrase">When no theme name or path is provided (or when set to <mark class="md-code md-code-ac1">default</mark>), Nuts automatically selects the appropriate default theme for the running operating system environment.</p><H4 class="md-title-2">Setting Themes at Boot or Runtime</H4><H4 class="md-title-3"><p class="md-phrase">Via Command Line Option (<mark class="md-code md-code-ac1">--theme</mark>)</p></H4><p class="md-phrase">The <mark class="md-code md-code-ac1">--theme</mark> CLI option accepts either a built-in theme name or a file path/URL to a custom theme file.</p><H4 class="md-title-4">1. By Theme Name</H4><p class="md-phrase">Pass one of the default theme names (<mark class="md-code md-code-ac1">default</mark>, <mark class="md-code md-code-ac1">ansi</mark>, <mark class="md-code md-code-ac1">grass</mark>, <mark class="md-code md-code-ac1">horizon</mark>, <mark class="md-code md-code-ac1">whiteboard</mark>):</p><pre><code class="language-sh">nuts --theme=horizon
2175
+
</code></pre><H4 class="md-title-4">2. By File Path or URL</H4><p class="md-phrase">Pass a file path (relative or absolute) or URL to a <code class="md-code md-code-ac1">.ntf-theme</code> file:</p><pre><code class="language-sh">nuts --theme=/path/to/my-theme.ntf-theme
2176
+
</code></pre><H4 class="md-title-3">Via Java API</H4><p class="md-phrase">The <code class="md-code md-code-ac1">NTextTheme.of(String nameOrPath)</code> factory method resolves themes seamlessly:</p><ul class="md-ul"><li class="md-uli"><p class="md-phrase"><b class="md-bold">Simple Name</b>: Loads built-in theme resources from <code class="md-code md-code-ac1">classpath:/META-INF/ntf-themes/<name>.ntf-theme</code> or user themes from <code class="md-code md-code-ac1">~/.config/nuts/.../themes/<name></code>. Themes loaded by name are cached.</p></li><li class="md-uli"><p class="md-phrase"><b class="md-bold">File Path or URL</b>: Loads the theme from the specified filesystem path or URL via <mark class="md-code md-code-ac1">NPath</mark>.</p></li><li class="md-uli"><p class="md-phrase"><b class="md-bold">Null or Blank</b>: Loads the default theme configured for the workspace/OS environment.</p></li></ul><H4 class="md-title-4">Example Usage</H4><pre><code class="language-java">import net.thevpc.nuts.text.NTextTheme;
0 commit comments