Last active
September 5, 2022 17:26
-
-
Save dtr2300/06fe9f5f804f30d8ef10c442a3cc8bac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## https://pypi.org/project/art/ | |
import art | |
## add extra headers | |
extra_headers = r""" | |
["default1"] = { | |
[[ __ ]], | |
[[ ___ ___ ___ __ __ /\_\ ___ ___ ]], | |
[[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]], | |
[[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]], | |
[[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]], | |
[[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]], | |
}, | |
["default2"] = { | |
[[ _______ ____ ____.__ ]], | |
[[ \ \ ____ ___\ \ / /|__| _____ ]], | |
[[ / | \_/ __ \/ _ \ Y / | |/ \ ]], | |
[[/ | \ ___( <_> ) / | | Y Y \]], | |
[[\____|__ /\___ >____/ \___/ |__|__|_| /]], | |
[[ \/ \/ \/ ]], | |
}, | |
""".rstrip() | |
## list of fontnames to exclude | |
exclude = [] | |
def text2art(text, fontname, compress=False): | |
data = [line for line in art.text2art(text, font=fontname).splitlines() if line.strip()] | |
spaces_left = min([(len(line) - len(line.lstrip())) for line in data]) | |
if spaces_left: | |
data = [line[spaces_left:] for line in data] | |
spaces_right = min([(len(line) - len(line.rstrip())) for line in data]) | |
if spaces_right: | |
data = [line[:(len(line) - spaces_right)] for line in data] | |
if compress: | |
data = ["".join(x) for x in zip(*data) if "".join(x).strip()] | |
data = ["".join(x) for x in zip(*data)] | |
return data | |
def create_nvim_headers(text="neovim", add=None, exclude=None, compress=False): | |
result = ["local headers = {"] | |
if add: | |
result.append(add) | |
for fontname in art.FONT_NAMES: | |
if fontname in art.NON_ASCII_FONTS: | |
continue | |
if exclude and fontname in exclude: | |
continue | |
result.append('\n ["' + fontname + '"] = {') | |
data = text2art(text, fontname, compress) | |
for line in data: | |
if "[" in line or "]" in line: | |
result.append(' "' + line.replace('"', "'").replace("\\", "\\\\") + '",') | |
else: | |
result.append(" [[" + line + "]],") | |
result.append(" },") | |
result.append("}") | |
result.append(""" | |
return setmetatable(headers, { | |
__index = function(t, key) | |
if key == "random" then | |
local keys = {} | |
for k, _ in pairs(headers) do | |
table.insert(keys, k) | |
end | |
return t[keys[math.random(#keys)]] | |
else | |
return t[key] | |
end | |
end, | |
}) | |
""") | |
return "\n".join(result) | |
if __name__ == "__main__": | |
print(create_nvim_headers(add=extra_headers, exclude=exclude)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment