MCPcopy
hub / github.com/go-task/task / String

Method String

taskfile/snippet.go:140–179  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

138}
139
140func (s *Snippet) String() string {
141 buf := &bytes.Buffer{}
142
143 maxLineNumberDigits := digits(s.end)
144 lineNumberFormat := fmt.Sprintf("%%%dd", maxLineNumberDigits)
145 lineNumberSpacer := strings.Repeat(" ", maxLineNumberDigits)
146 lineIndicatorSpacer := strings.Repeat(" ", len(lineIndicator))
147 columnSpacer := strings.Repeat(" ", max(s.column-1, 0))
148
149 // Loop over each line in the snippet
150 for i, lineHighlighted := range s.linesHighlighted {
151 if i > 0 {
152 fmt.Fprintln(buf)
153 }
154
155 currentLine := s.start + i
156 lineNumber := fmt.Sprintf(lineNumberFormat, currentLine)
157
158 // If this is a padding line or indicators are disabled, print it as normal
159 if currentLine != s.line || s.noIndicators {
160 fmt.Fprintf(buf, "%s %s | %s", lineIndicatorSpacer, lineNumber, lineHighlighted)
161 continue
162 }
163
164 // Otherwise, print the line with indicators
165 fmt.Fprintf(buf, "%s %s | %s", color.RedString(lineIndicator), lineNumber, lineHighlighted)
166
167 // Only print the column indicator if the column is in bounds
168 if s.column > 0 && s.column <= len(s.linesRaw[i]) {
169 fmt.Fprintf(buf, "\n%s %s | %s%s", lineIndicatorSpacer, lineNumberSpacer, columnSpacer, color.RedString(columnIndicator))
170 }
171 }
172
173 // If there are lines, but no line is selected, print the column indicator under all the lines
174 if len(s.linesHighlighted) > 0 && s.line == 0 && s.column > 0 {
175 fmt.Fprintf(buf, "\n%s %s | %s%s", lineIndicatorSpacer, lineNumberSpacer, columnSpacer, color.RedString(columnIndicator))
176 }
177
178 return buf.String()
179}
180
181func digits(number int) int {
182 count := 0

Callers 15

TestSnippetStringFunction · 0.95
readNodeMethod · 0.95
doVersionChecksMethod · 0.45
TestFileWatchFunction · 0.45
TestGeneratesFunction · 0.45
TestStatusChecksumFunction · 0.45
TestStatusTimestampFunction · 0.45
TestStatusVariablesFunction · 0.45
TestCmdsVariablesFunction · 0.45
TestExpandFunction · 0.45
TestDryFunction · 0.45

Calls 1

digitsFunction · 0.85

Tested by 15

TestSnippetStringFunction · 0.76
TestFileWatchFunction · 0.36
TestGeneratesFunction · 0.36
TestStatusChecksumFunction · 0.36
TestStatusTimestampFunction · 0.36
TestStatusVariablesFunction · 0.36
TestCmdsVariablesFunction · 0.36
TestExpandFunction · 0.36
TestDryFunction · 0.36
TestIncludesRemoteFunction · 0.36
TestIncludesHttpFunction · 0.36