Lumis.Theme (Lumis v0.10.4)

Copy Markdown View Source

A Neovim theme.

Contains the name, appearance, and a map of highlight Lumis.Theme.Style's.

Lumis bundles the most popular themes from the Neovim community, you can see the full list with Lumis.Theme.available/0 and then fetch one of the bundled themes with Lumis.Theme.get/1.

Or check out all the available themes.

Example

%Lumis.Theme{
   name: "github_light",
   appearance: :light,
   revision: "fe70a27afefa6e10db4a59262d31f259f702fd6a",
   highlights: %{
     "function.macro" => %Lumis.Theme.Style{
       fg: "#6639ba",
       bg: nil,
       bold: false,
       italic: false,
       text_decoration: %Lumis.Theme.TextDecoration{
         underline: :solid,
         strikethrough: false
       }
     },
     ...
   }
}

Summary

Types

t()

A Neovim theme with name, appearance (:light or :dark), revision, and highlight styles.

Functions

Returns every built-in theme's name and appearance, sorted by name.

Builds CSS for a Lumis theme.

Builds CSS for a Lumis theme, raising on errors.

Finds a readable built-in theme matching the supplied colors.

Load a theme from a JSON file.

Load a theme from a JSON string.

Get a theme by name.

Types

appearance()

@type appearance() :: :light | :dark

t()

@type t() :: %Lumis.Theme{
  appearance: appearance(),
  highlights: %{required(String.t()) => Lumis.Theme.Style.t()},
  name: String.t(),
  revision: String.t()
}

A Neovim theme with name, appearance (:light or :dark), revision, and highlight styles.

Functions

available()

@spec available() :: [Lumis.theme_info()]

Returns every built-in theme's name and appearance, sorted by name.

Use Lumis.Theme.get/2 to get the actual theme struct.

Example

iex> Lumis.Theme.available() |> Enum.find(&(&1.name == "github_light"))
%{name: "github_light", appearance: "light"}

build_css(theme, options \\ [])

@spec build_css(String.t() | t(), keyword()) :: {:ok, String.t()} | {:error, term()}

Builds CSS for a Lumis theme.

Accepts a bundled theme name or a Lumis.Theme struct. Use this with the :html_linked formatter when you need to embed CSS, scope selectors, or customize the container code block rule.

Pass layout: false to generate theme styles without the built-in line layout layer. Prebuilt CSS files always include layout.

Options

  • :layout (boolean/0) - Include the built-in line layout rules. Set to false when your stylesheet supplies its own layout. The default value is true.

  • :enable_italic (boolean/0) - Whether italic theme styles should be emitted. The default value is true.

  • :scope (String.t/0) - Parent selector prepended to every generated selector. The default value is "".

  • :container_selector (String.t/0) - Selector used for the container code block rule. Defaults to .lumis. The default value is ".lumis".

  • :container_style (list of tuple of String.t/0, String.t/0 values) - Extra {property, value} declarations for the container code block rule. A property that matches one that the theme already sets (color, background-color) replaces that value. The default value is [].

Examples

Lumis.Theme.build_css!("github_dark")

Produces CSS shaped like this:

/* github_dark
 * revision: ...
 */
.lumis {
  color: #e6edf3;
  background-color: #0d1117;
}
.l-keyword {
  color: #ff7b72;
}

Scope the generated stylesheet under a parent selector:

Lumis.Theme.build_css!("github_dark",
  scope: ~s(html[data-theme="dark"]),
  container_style: [
    {"background-color", "var(--code-background)"},
    {"border-radius", "0.375rem"}
  ]
)

That produces selectors like:

html[data-theme="dark"] .lumis {
  color: #e6edf3;
  background-color: var(--code-background);
  border-radius: 0.375rem;
}
html[data-theme="dark"] .l-keyword {
  color: #ff7b72;
}

build_css!(theme, options \\ [])

@spec build_css!(String.t() | t(), keyword()) :: String.t()

Builds CSS for a Lumis theme, raising on errors.

See build_css/2 for options.

closest(colors)

@spec closest(%{
  optional(:background) => String.t() | nil,
  optional(:foreground) => String.t() | nil,
  optional(:ansi) => [String.t() | nil] | nil
}) :: t() | nil

Finds a readable built-in theme matching the supplied colors.

Colors are six-digit RGB hex strings, with an optional #. Pass :background and optionally :foreground and :ansi, a list of 16 colors with nil for unknown entries. Foreground and ANSI accents break ties between similar backgrounds.

Returns nil without a background or a sufficiently close theme with at least 3:1 text contrast. Monochrome themes are excluded. Raises ArgumentError for invalid colors or an ANSI palette other than 16 entries.

Lumis.Theme.closest(%{background: "#000000"}).name
#=> "modus_vivendi"

from_file(path)

@spec from_file(String.t()) :: {:ok, t()} | {:error, term()}

Load a theme from a JSON file.

from_json(json_string)

@spec from_json(String.t()) :: {:ok, t()} | {:error, term()}

Load a theme from a JSON string.

get(name, default \\ nil)

@spec get(String.t(), any()) :: t() | nil

Get a theme by name.