style(tools): unify console output with [I/W/E] [Module] color-coded format

- Add ANSI color coding: [I]=green, [W]=yellow, [E]=red
- Format: [Level] [Module] message with 4-char indent for data rows
- Error detail lines use |-> tree connector
- Remove extra blank lines between outputs (except list)
- Modules: CLI, Preview, Builder, Server, Watcher

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
KenanZhuandClaude Opus 4.8 committed 2026-06-05 14:21:25 +08:00
1 parent d46f702664
commit da8bb2e1a2
8 files changed
+46 -40

No files matched your search

+2 -2
View File
@@ -49,7 +49,7 @@ func runCreate(c *cli.Context) error {
if info, err := os.Stat(styleDir); err == nil {
if info.IsDir() {
fmt.Printf(" [skip] '%s' already exists\n", styleName)
fmt.Printf("\033[32m[I]\033[0m [CLI] '%s' already exists, skipped\n", styleName)
continue
}
return fmt.Errorf("'%s' exists but is not a directory", styleName)
@@ -79,7 +79,7 @@ func runCreate(c *cli.Context) error {
created++
}
fmt.Printf(" Created style '%s' with %d template files\n", styleName, created)
fmt.Printf("\033[32m[I]\033[0m [CLI] Created style '%s' with %d template files\n", styleName, created)
}
return nil
+2 -2
View File
@@ -37,14 +37,14 @@ func runDelete(c *cli.Context) error {
styleDir := filepath.Join(folder, styleName)
if _, err := os.Stat(styleDir); os.IsNotExist(err) {
fmt.Printf(" [skip] '%s' does not exist\n", styleName)
fmt.Printf("\033[33m[W]\033[0m [CLI] '%s' does not exist, skipped\n", styleName)
continue
}
if err := os.RemoveAll(styleDir); err != nil {
return fmt.Errorf("cannot delete %s: %w", styleDir, err)
}
fmt.Printf(" Deleted style '%s'\n", styleName)
fmt.Printf("\033[32m[I]\033[0m [CLI] Deleted style '%s'\n", styleName)
}
return nil
+5 -5
View File
@@ -48,7 +48,7 @@ func runDev(c *cli.Context) error {
// Verify node_modules are installed
if _, err := os.Stat(filepath.Join(serverDir, "node_modules")); os.IsNotExist(err) {
fmt.Println("Installing Node.js dependencies...")
fmt.Println("\033[32m[I]\033[0m [Builder] Installing Node.js dependencies...")
cmd := exec.Command("npm", "install")
cmd.Dir = serverDir
cmd.Stdout = os.Stdout
@@ -64,7 +64,7 @@ func runDev(c *cli.Context) error {
initCmd.Stdout = os.Stdout
initCmd.Stderr = os.Stderr
if err := initCmd.Run(); err != nil {
fmt.Println("Warning: initial preview generation failed, starting anyway...")
fmt.Println("\033[33m[W]\033[0m [Builder] Initial preview generation failed, starting anyway")
}
// Start the Node.js dev server
@@ -78,8 +78,8 @@ func runDev(c *cli.Context) error {
return fmt.Errorf("failed to start dev server: %w", err)
}
fmt.Printf("\nDev server running at http://localhost:%d\n", port)
fmt.Print("Press Ctrl+C to stop.\n\n")
fmt.Printf("\033[32m[I]\033[0m [Server] Dev server running at http://localhost:%d\n", port)
fmt.Print("\033[32m[I]\033[0m [Server] Press Ctrl+C to stop\n")
// Handle graceful shutdown
sigCh := make(chan os.Signal, 1)
@@ -87,7 +87,7 @@ func runDev(c *cli.Context) error {
go func() {
<-sigCh
fmt.Println("\nShutting down...")
fmt.Println("\033[32m[I]\033[0m [Server] Shutting down")
if err := serverCmd.Process.Signal(os.Interrupt); err != nil {
serverCmd.Process.Kill()
}
+2 -2
View File
@@ -37,7 +37,7 @@ func runList(c *cli.Context) error {
}
absDir, _ := filepath.Abs(folder)
fmt.Printf("Available styles in '%s' (%d):\n", filepath.Base(absDir), len(themes))
fmt.Printf("\033[32m[I]\033[0m [Preview] Available styles in '%s' (%d):\n", filepath.Base(absDir), len(themes))
sort.Strings(themes)
for _, t := range themes {
@@ -51,7 +51,7 @@ func runList(c *cli.Context) error {
}
return nil
})
fmt.Printf(" %-16s (%d .tmpl files)\n", t, count)
fmt.Printf("\033[32m[I]\033[0m [Preview] %-16s (%d .tmpl files)\n", t, count)
}
return nil
}
+1 -2
View File
@@ -2,7 +2,6 @@ package cli
import (
"fmt"
"log"
"path/filepath"
"github.com/urfave/cli/v2"
@@ -78,7 +77,7 @@ func runPreview(c *cli.Context) error {
preview.PrintDetailedSummary(result, folder, cfg)
log.Printf("Wrote %d themes x %d templates to %s",
fmt.Printf("\033[32m[I]\033[0m [Preview] Wrote %d themes x %d templates to %s\n",
len(result.Summaries), len(cfg.Templates), outputPath)
return nil