diff options
Diffstat (limited to 'internal/ascii')
| -rw-r--r-- | internal/ascii/fonts.go | 439 | ||||
| -rw-r--r-- | internal/ascii/render.go | 47 |
2 files changed, 486 insertions, 0 deletions
diff --git a/internal/ascii/fonts.go b/internal/ascii/fonts.go new file mode 100644 index 0000000..daea4bb --- /dev/null +++ b/internal/ascii/fonts.go @@ -0,0 +1,439 @@ +// Package ascii provides ASCII art fonts for timer display. +// This code is adapted from https://github.com/Bahaaio/pomo +// Copyright (c) 2025 Bahaa El Deen Mohamed +// Licensed under the MIT License +package ascii + +type Font [11]string + +const ( + Mono12 = "mono12" + Rebel = "rebel" + Ansi = "ansi" + AnsiShadow = "ansiShadow" + Doom = "doom" // figlet doom font + DefaultFont = Mono12 +) + +// AllFonts returns a list of all available font names. +// This includes both ASCII art fonts and the figlet doom font. +var AllFonts = []string{Doom, Mono12, Rebel, Ansi, AnsiShadow} + +var fonts = map[string]Font{ + Mono12: { + ` + ▄▄▄▄ + ██▀▀██ + ██ ██ + ██ ██ ██ + ██ ██ + ██▄▄██ + ▀▀▀▀ +`, + ` + ▄▄▄ + █▀██ + ██ + ██ + ██ + ▄▄▄██▄▄▄ + ▀▀▀▀▀▀▀▀ +`, + ` + ▄▄▄▄▄ + █▀▀▀▀██▄ + ██ + ▄█▀ + ▄█▀ + ▄██▄▄▄▄▄ + ▀▀▀▀▀▀▀▀ +`, + ` + ▄▄▄▄▄ + █▀▀▀▀██▄ + ▄██ + █████ + ▀██ + █▄▄▄▄██▀ + ▀▀▀▀▀ +`, + ` + ▄▄▄ + ▄███ + █▀ ██ + ▄█▀ ██ + ████████ + ██ + ▀▀ +`, + ` + ▄▄▄▄▄▄▄ + ██▀▀▀▀▀ + ██▄▄▄▄ + █▀▀▀▀██▄ + ██ + █▄▄▄▄██▀ + ▀▀▀▀▀ +`, + ` + ▄▄▄▄ + ██▀▀▀█ + ██ ▄▄▄ + ███▀▀██▄ + ██ ██ + ▀██▄▄██▀ + ▀▀▀▀ +`, + ` + ▄▄▄▄▄▄▄▄ + ▀▀▀▀▀███ + ▄██ + ██ + ██ + ██ + ▀▀ +`, + ` + ▄▄▄▄ + ▄██▀▀██▄ + ██▄ ▄██ + ██████ + ██▀ ▀██ + ▀██▄▄██▀ + ▀▀▀▀ +`, + ` + ▄▄▄▄ + ▄██▀▀██▄ + ██ ██ + ▀██▄▄███ + ▀▀▀ ██ + █▄▄▄██ + ▀▀▀▀ +`, + ` + + ▄▄ + ██ + + ██ + ▀▀ + +`, + }, + + Rebel: { + ` + █████ + ███▒▒▒███ + ███ ▒▒███ +▒███ ▒███ +▒███ ▒███ +▒▒███ ███ + ▒▒▒█████▒ + ▒▒▒▒▒▒ +`, + + ` + ████ +▒▒███ + ▒███ + ▒███ + ▒███ + ▒███ + █████ +▒▒▒▒▒ +`, + + ` + ████████ + ███▒▒▒▒███ +▒▒▒ ▒███ + ███████ + ███▒▒▒▒ + ███ █ +▒██████████ +▒▒▒▒▒▒▒▒▒▒ +`, + + ` + ████████ + ███▒▒▒▒███ +▒▒▒ ▒███ + ██████▒ + ▒▒▒▒▒▒███ + ███ ▒███ +▒▒████████ + ▒▒▒▒▒▒▒▒ +`, + + ` + █████ █████ +▒▒███ ▒▒███ + ▒███ ▒███ █ + ▒███████████ + ▒▒▒▒▒▒▒███▒█ + ▒███▒ + █████ + ▒▒▒▒▒ +`, + + ` + ██████████ +▒███▒▒▒▒▒▒█ +▒███ ▒ +▒█████████ +▒▒▒▒▒▒▒▒███ + ███ ▒███ +▒▒████████ + ▒▒▒▒▒▒▒▒ +`, + + ` + ████████ + ███▒▒▒▒███ +▒███ ▒▒▒ +▒█████████ +▒███▒▒▒▒███ +▒███ ▒███ +▒▒████████ + ▒▒▒▒▒▒▒▒ +`, + + ` + ██████████ +▒███▒▒▒▒███ +▒▒▒ ███ + ███ + ███ + ███ + ███ + ▒▒▒ +`, + + ` + ████████ + ███▒▒▒▒███ +▒███ ▒███ +▒▒████████ + ███▒▒▒▒███ +▒███ ▒███ +▒▒████████ + ▒▒▒▒▒▒▒▒ +`, + + ` + ████████ + ███▒▒▒▒███ +▒███ ▒███ +▒▒█████████ + ▒▒▒▒▒▒▒███ + ███ ▒███ +▒▒████████ + ▒▒▒▒▒▒▒▒ +`, + + ` + + ██ + ▒▒ + + + ██ + ▒▒ + + +`, + }, + + Ansi: { + ` + ██████ +██ ████ +██ ██ ██ +████ ██ + ██████ +`, + + ` + ██ +███ + ██ + ██ + ██ +`, + + ` +██████ + ██ + █████ +██ +███████ +`, + + ` +██████ + ██ + █████ + ██ +██████ +`, + + ` +██ ██ +██ ██ +███████ + ██ + ██ +`, + + ` +███████ +██ +███████ + ██ +███████ +`, + + ` + ██████ +██ +███████ +██ ██ + ██████ +`, + + ` +███████ + ██ + ██ + ██ + ██ +`, + + ` + █████ +██ ██ + █████ +██ ██ + █████ +`, + + ` + █████ +██ ██ + ██████ + ██ + █████ +`, + + ` + + ██ + + ██ + +`, + }, + + AnsiShadow: { + ` + ██████╗ +██╔═████╗ +██║██╔██║ +████╔╝██║ +╚██████╔╝ + ╚═════╝ +`, + + ` + ██╗ +███║ +╚██║ + ██║ + ██║ + ╚═╝ +`, + + ` +██████╗ +╚════██╗ + █████╔╝ +██╔═══╝ +███████╗ +╚══════╝ +`, + + ` +██████╗ +╚════██╗ + █████╔╝ + ╚═══██╗ +██████╔╝ +╚═════╝ +`, + + ` +██╗ ██╗ +██║ ██║ +███████║ +╚════██║ + ██║ + ╚═╝ +`, + + ` +███████╗ +██╔════╝ +███████╗ +╚════██║ +███████║ +╚══════╝ +`, + + ` + ██████╗ +██╔════╝ +███████╗ +██╔═══██╗ +╚██████╔╝ + ╚═════╝ +`, + + ` +███████╗ +╚════██║ + ██╔╝ + ██╔╝ + ██║ + ╚═╝ +`, + + ` + █████╗ +██╔══██╗ +╚█████╔╝ +██╔══██╗ +╚█████╔╝ + ╚════╝ +`, + + ` + █████╗ +██╔══██╗ +╚██████║ + ╚═══██║ + █████╔╝ + ╚════╝ +`, + + ` + + ██╗ + ╚═╝ + ██╗ + ╚═╝ + +`, + }, +} diff --git a/internal/ascii/render.go b/internal/ascii/render.go new file mode 100644 index 0000000..eb41dd1 --- /dev/null +++ b/internal/ascii/render.go @@ -0,0 +1,47 @@ +// Package ascii provides ASCII art rendering for timer display. +// This code is adapted from https://github.com/Bahaaio/pomo +// Copyright (c) 2025 Bahaa El Deen Mohamed +// Licensed under the MIT License +package ascii + +import ( + "github.com/charmbracelet/lipgloss" +) + +// RenderNumber renders a string of digits as ASCII art using the specified font. +// The number parameter should contain only digits (0-9) and colons (:). +// Returns the ASCII art representation as a single string with properly aligned characters. +func RenderNumber(number string, font Font) string { + digits := make([]string, 0, len(number)) + + for _, digit := range number { + digits = append(digits, renderDigit(digit, font)) + } + + asciiDigits := lipgloss.JoinHorizontal(lipgloss.Top, digits...) + return asciiDigits +} + +// GetFont returns the font with the given name. +// If the font doesn't exist, it returns the default font. +func GetFont(fontName string) Font { + if font, exists := fonts[fontName]; exists { + return font + } + + return fonts[DefaultFont] +} + +// renderDigit converts a single digit character to its ASCII art representation. +// Supports digits 0-9 and colon (:). Returns empty string for unsupported characters. +func renderDigit(digit rune, font Font) string { + if digit == ':' { + return font[len(font)-1] + } + + if digit < '0' || digit > '9' { + return "" + } + + return font[digit-'0'] +} |
