MCPcopy Index your code
hub / github.com/cloudfoundry/cli / printCellValue

Method printCellValue

cf/terminal/table.go:259–300  ·  view source on GitHub ↗

printCellValue pads the specified string to the width of the given column, adds the spacing between columns, and returns the result.

(result io.Writer, transformer rowTransformer, col, last int, value string)

Source from the content-addressed store, hash-verified

257// printCellValue pads the specified string to the width of the given
258// column, adds the spacing between columns, and returns the result.
259func (t *Table) printCellValue(result io.Writer, transformer rowTransformer, col, last int, value string) error {
260 value = trim(transformer.Transform(col, trim(value)))
261 fmt.Fprint(result, value)
262
263 // Pad all columns, but the last in this row (with the size of
264 // the header row limiting this). This ensures that most of
265 // the irrelevant spacing is not printed. At the moment
266 // irrelevant spacing can only occur when printing a row with
267 // multi-line cells, introducing a physical short line for a
268 // long logical row. Getting rid of that requires fixing in
269 // printRow.
270 //
271 // Note how the inter-column spacing is also irrelevant for
272 // that last column.
273
274 if col < last {
275 // (**) See also 'calculateMaxSize' (cMS). Here and
276 // there we have to apply identical transformations to
277 // the cell value to get matching cell width
278 // information. If they do not match then we may here
279 // compute a cell width larger than the max width
280 // found by cMS, derive a negative padding length from
281 // that, and subsequently return an error. What was
282 // further missing is trimming before entering the
283 // user-transform. Especially with color transforms
284 // any trailing space going in will not be removable
285 // for print.
286 //
287 // This happened for
288 // https://www.pivotaltracker.com/n/projects/892938/stories/117404629
289
290 decolorizedLength, err := visibleSize(trim(Decolorize(value)))
291 if err != nil {
292 return err
293 }
294 padlen := t.columnWidth[col] - decolorizedLength
295 padding := strings.Repeat(" ", padlen)
296 fmt.Fprint(result, padding)
297 fmt.Fprint(result, t.colSpacing)
298 }
299 return nil
300}
301
302// rowTransformer is an interface behind which we can specify how to
303// transform the strings of an entire row on a column-by-column basis.

Callers 1

printRowMethod · 0.95

Calls 4

trimFunction · 0.85
visibleSizeFunction · 0.85
DecolorizeFunction · 0.85
TransformMethod · 0.65

Tested by

no test coverage detected