@@ -206,111 +206,6 @@ func highlightCodeForPath(code []string, path string, measure int, bg color.Colo
206206 return highlightCodeWithLexer (cachedLexerForPath (path ), code , measure , bg )
207207}
208208
209- // highlightShellCommand styles a one-line command for a tool-card heading.
210- // Command output is deliberately left untouched: it may be structured data,
211- // prose, or terminal control text rather than shell source.
212- func highlightShellCommand (command string ) (string , bool ) {
213- if command == "" {
214- return "" , false
215- }
216- lexer := cachedLexer ("bash" )
217- if lexer == nil {
218- return "" , false
219- }
220- iterator , err := lexer .Tokenise (nil , command )
221- if err != nil {
222- return "" , false
223- }
224- var builder strings.Builder
225- expectingCommand := true
226- for _ , token := range iterator .Tokens () {
227- if token .Type == chroma .Text || token .Type == chroma .TextWhitespace {
228- builder .WriteString (highlightShellText (token .Value , & expectingCommand ))
229- continue
230- }
231- builder .WriteString (tokenStyle (token .Type ).Render (token .Value ))
232- if token .Type .InCategory (chroma .Operator ) || (token .Type .InCategory (chroma .Punctuation ) && strings .ContainsAny (token .Value , ";|" )) {
233- expectingCommand = true
234- }
235- }
236- return builder .String (), true
237- }
238-
239- func highlightShellText (text string , expectingCommand * bool ) string {
240- var builder strings.Builder
241- for start := 0 ; start < len (text ); {
242- end := start
243- space := text [start ] == ' ' || text [start ] == '\t'
244- for end < len (text ) {
245- isSpace := text [end ] == ' ' || text [end ] == '\t'
246- if isSpace != space {
247- break
248- }
249- end ++
250- }
251- part := text [start :end ]
252- if space {
253- builder .WriteString (part )
254- start = end
255- continue
256- }
257-
258- clean := strings .Trim (part , "\" '" )
259- style := tokenStyle (chroma .Text )
260- switch {
261- case isShellControlOperator (clean ):
262- style = tokenStyle (chroma .Operator )
263- * expectingCommand = true
264- case * expectingCommand :
265- style = tokenStyle (chroma .NameFunction )
266- * expectingCommand = isShellCommandWrapper (clean )
267- case strings .HasPrefix (clean , "-" ):
268- style = tokenStyle (chroma .NameAttribute )
269- case isShellNumber (clean ):
270- style = tokenStyle (chroma .LiteralNumber )
271- case looksLikeShellPath (clean ):
272- style = tokenStyle (chroma .LiteralString )
273- }
274- builder .WriteString (style .Render (part ))
275- start = end
276- }
277- return builder .String ()
278- }
279-
280- func isShellControlOperator (value string ) bool {
281- switch value {
282- case "&&" , "||" , "|" , ";" :
283- return true
284- default :
285- return false
286- }
287- }
288-
289- func isShellCommandWrapper (value string ) bool {
290- switch value {
291- case "sudo" , "env" , "command" , "time" , "xargs" :
292- return true
293- default :
294- return false
295- }
296- }
297-
298- func isShellNumber (value string ) bool {
299- if value == "" {
300- return false
301- }
302- for _ , r := range value {
303- if r < '0' || r > '9' {
304- return false
305- }
306- }
307- return true
308- }
309-
310- func looksLikeShellPath (value string ) bool {
311- return strings .HasPrefix (value , "./" ) || strings .HasPrefix (value , "../" ) || strings .HasPrefix (value , "/" ) || strings .HasPrefix (value , "~/" ) || strings .Contains (value , "/" )
312- }
313-
314209// highlightSpan overlays a background on a rune range in one source line while
315210// retaining the lexer-selected foreground. Diff rendering uses it to keep the
316211// precise changed word visible inside a syntax-highlighted add/delete row.
@@ -320,10 +215,6 @@ type highlightSpan struct {
320215 background color.Color
321216}
322217
323- func highlightCodeForPathWithSpans (code []string , path string , measure int , bg color.Color , spans []highlightSpan ) ([]string , bool ) {
324- return highlightCodeWithLexerAndSpans (cachedLexerForPath (path ), code , measure , bg , spans )
325- }
326-
327218// highlightCodeForPathWithLineBackgrounds applies syntax highlighting to a
328219// single source unit while preserving a distinct background for every source
329220// line. The diff viewer uses one lexer pass per hunk so multiline syntax keeps
0 commit comments