8c4370c22ed3fc3ac8777ccee53f5bc0d4d363c5

Author
Toby Padilla <toby@charm.sh>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

Use -c/--color for syntax highlighting and -l/--lineno/--linenumber for
line numbers

Diff

 1diff --git a/server/middleware.go b/server/middleware.go
 2index d94fe6b3b49d85947f82c30d8aee8d6bbaa6b906..53f85162513dd0394cc016ba49d53354eaee3b55 100644
 3--- a/server/middleware.go
 4+++ b/server/middleware.go
 5@@ -26,7 +26,7 @@ func softServeMiddleware(ac *appCfg.Config) wish.Middleware {
 6 			cmds := s.Command()
 7 			if !active && len(cmds) > 0 {
 8 				func() {
 9-					formatting := false
10+					color := false
11 					lineno := false
12 					fp := filepath.Clean(cmds[0])
13 					ps := strings.Split(fp, "/")
14@@ -47,9 +47,9 @@ func softServeMiddleware(ac *appCfg.Config) wish.Middleware {
15 						return
16 					}
17 					for _, op := range cmds[1:] {
18-						if op == "formatting" {
19-							formatting = true
20-						} else if op == "lineno" || op == "linenumber" {
21+						if op == "-c" || op == "--color" {
22+							color = true
23+						} else if op == "-l" || op == "--lineno" || op == "--linenumber" {
24 							lineno = true
25 						}
26 					}
27@@ -65,7 +65,7 @@ func softServeMiddleware(ac *appCfg.Config) wish.Middleware {
28 						_ = s.Exit(1)
29 						return
30 					}
31-					if formatting {
32+					if color {
33 						ffc, err := withFormatting(fp, fc)
34 						if err != nil {
35 							s.Write([]byte(err.Error()))
36@@ -75,7 +75,7 @@ func softServeMiddleware(ac *appCfg.Config) wish.Middleware {
37 						fc = ffc
38 					}
39 					if lineno {
40-						fc = withLineNumber(fc, formatting)
41+						fc = withLineNumber(fc, color)
42 					}
43 					s.Write([]byte(fc))
44 				}()
45@@ -105,13 +105,13 @@ func readFile(r *gg.Repository, fp string) (string, error) {
46 	return fc, nil
47 }
48 
49-func withLineNumber(s string, formatting bool) string {
50+func withLineNumber(s string, color bool) string {
51 	st := lipgloss.NewStyle().Foreground(lipgloss.Color("15"))
52 	lines := strings.Split(s, "\n")
53 	mll := fmt.Sprintf("%d", len(fmt.Sprintf("%d", len(lines))))
54 	for i, l := range lines {
55 		lines[i] = fmt.Sprintf("%-"+mll+"d │ %s", i+1, l)
56-		if formatting {
57+		if color {
58 			lines[i] = st.Render(lines[i])
59 		}
60 	}