@@ -14,12 +14,13 @@ import (
1414func main () {
1515 // Define command line options
1616 output := flag .String ("o" , "generated_code.png" , "Output file name" )
17+ theme := flag .String ("theme" , "dark" , "Theme: dark or light" )
1718 flag .Parse ()
1819
1920 // Get remaining arguments (non-optional)
2021 args := flag .Args ()
2122 if len (args ) < 1 {
22- fmt .Println ("Usage: snapcode [-o output.png] '<code string>'" )
23+ fmt .Println ("Usage: snapcode [-o output.png] [-theme dark|light] '<code string>'" )
2324 os .Exit (1 )
2425 }
2526
@@ -31,7 +32,7 @@ func main() {
3132 defer browser .MustClose ()
3233
3334 // Dynamically generate HTML from code Browser startup
34- htmlContent := generateHTML (code )
35+ htmlContent := generateHTML (code , * theme )
3536
3637 // Convert HTML to Data URL and open
3738 dataURL := "data:text/html;base64," + base64 .StdEncoding .EncodeToString ([]byte (htmlContent ))
@@ -48,19 +49,25 @@ func main() {
4849}
4950
5051// Generate an HTML template from the given code string
51- func generateHTML (code string ) string {
52+ func generateHTML (code string , theme string ) string {
53+ darkCSS := `
54+ body { background: #1e1e1e;color: #61dafb; }
55+ pre { background: #282c34; color: #61dafb; }
56+ `
57+ lightCSS := `
58+ body { background: #ffffff; color: #333; }
59+ pre { background: #f6f8fa; color: #111; }
60+ `
61+ css := darkCSS
62+ if theme == "light" {
63+ css = lightCSS
64+ }
65+
5266 return fmt .Sprintf (`
53- <!DOCTYPE html>
54- <html lang="en">
55- <head><meta charset="UTF-8"><title>SnapCode</title>
56- <style>
57- body { background: #1e1e1e; display:flex;justify-content:center;align-items:center;height:100vh;margin:0; }
58- pre { background:#282c34;color:#61dafb;padding:16px;border-radius:8px;font-size:16px;overflow:auto; }
59- </style>
60- </head>
61- <body>
62- <pre><code>%s</code></pre>
63- </body>
64- </html>
65- ` , code )
67+ <!DOCTYPE html><html><head><meta charset="utf-8">
68+ <title>SnapCode</title><style>%s
69+ pre{padding:16px;border-radius:8px;font-size:16px;max-width:90%%;overflow:auto;}
70+ body,html{display:flex;justify-content:center;align-items:center;height:100vh;margin:0;}
71+ </style></head><body><pre><code>%s</code></pre></body></html>
72+ ` , css , code )
6673}
0 commit comments