#!/bin/env luajit local themes = {} local current_theme = nil Dsl = {} Dsl.name = function (name) current_theme.name = name end Dsl.author = function (author) current_theme.author = author end Dsl.author_name = function (author_name) current_theme.author_name = author_name end Dsl.author_url = function (author_url) current_theme.author_url = author_url end Dsl.variant = function (variant) current_theme.variant = variant end Dsl.color = function (index) return function (color_code) current_theme.colors[index] = color_code end end Dsl.background = function (color_code) current_theme.background = color_code end Dsl.foreground = function (color_code) current_theme.foreground = color_code end Dsl.cursor = function (cursor) current_theme.cursor = cursor end local theme_listing = io.popen [[ls themes -N1]] for line in theme_listing:lines () do current_theme = { colors = {} } table.insert (themes, current_theme) local script, err = loadfile ("themes/" .. line, "t", Dsl) if not script then return print (err) end script () end local color_swatch = [[
%s
]] local named_swatch = [[
%s
%s
]] local color_to_html_swatch = function (color, border_color) return color_swatch :format (color, border_color, color) end local named_color_to_html_swatch = function (name, color, border_color) return named_swatch :format (color, border_color, color, name) end local theme_to_html_card = function (i, theme) local card = {} table.insert (card, ([[
]]) :format (theme.background, theme.foreground, theme.foreground)) table.insert (card, ([[

]]) :format (i)) table.insert (card, theme.name) table.insert (card, [[

]]) if theme.author_name ~= '' then if theme.author_url ~= '' then table.insert (card, ([[

by ]]) :format (theme.author_url)) table.insert (card, theme.author_name) table.insert (card, [[

]]) else table.insert (card, [[

by ]]) table.insert (card, theme.author_name) table.insert (card, [[

]]) end end table.insert (card, [[
]]) table.insert (card, "\n") table.insert (card, named_color_to_html_swatch ("background", theme.background, theme.foreground)) table.insert (card, named_color_to_html_swatch ("foreground", theme.foreground, theme.foreground)) table.insert (card, named_color_to_html_swatch ("cursor", theme.cursor, theme.foreground)) table.insert (card, [[
]]) table.insert (card, [[
]]) for i = 1, 8 do table.insert(card, color_to_html_swatch (theme.colors[i], theme.foreground)) end table.insert (card, [[
]]) table.insert (card, [[
]]) for i = 9, 16 do table.insert(card, color_to_html_swatch (theme.colors[i], theme.foreground)) end table.insert (card, [[
]]) table.insert (card, [[
]]) return table.concat (card) end local build_nav = function (themes) local nav = {} for i, theme in ipairs (themes) do table.insert (nav, ([[
  • %s
  • ]]) :format (i, theme.name)) end return table.concat (nav) end local themes_to_html_page = function (themes) local page = {} table.insert (page, [[Terminal Colors]]) table.insert (page, [[

    Terminal Color Schemes

    ]]) table.insert (page, [[]]) for i, theme in ipairs (themes) do table.insert (page, theme_to_html_card (i, theme)) end table.insert (page, [[]]) return table.concat (page) end print (themes_to_html_page (themes))