summaryrefslogtreecommitdiff
path: root/internal/ascii/render.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-01-02 22:39:11 +0200
committerPaul Buetow <paul@buetow.org>2026-01-02 22:40:19 +0200
commit96f92ddd8ea1554766b358333e911f607c3e5d6c (patch)
treeafc26a32d4c42c752165e4975ab74b597ac4c09f /internal/ascii/render.go
parent7afe4c2c1afe9d8f4ba8887758523999fde12b7b (diff)
add large ASCII fonts and font cycling to live modev0.3.0main
- Add 4 new ASCII art fonts (mono12, rebel, ansi, ansiShadow) adapted from pomo project - Implement random font selection on startup when no font is specified - Add 'f' hotkey in live mode to cycle through fonts - Update LICENSE with MIT attribution for pomo fonts - Update README with comprehensive font documentation - Bump version to v0.3.0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/ascii/render.go')
-rw-r--r--internal/ascii/render.go47
1 files changed, 47 insertions, 0 deletions
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']
+}