File: tabledata_from_separated_values.go

package info (click to toggle)
golang-github-pterm-pterm 0.12.79-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,640 kB
  • sloc: makefile: 4
file content (20 lines) | stat: -rw-r--r-- 474 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package putils

import (
	"strings"

	"github.com/pterm/pterm"
)

// TableDataFromSeparatedValues converts values, separated by separator, into pterm.TableData.
//
// Usage:
//
//	pterm.DefaultTable.WithData(putils.TableDataFromCSV(csv)).Render()
func TableDataFromSeparatedValues(text, valueSeparator, rowSeparator string) (td pterm.TableData) {
	for _, line := range strings.Split(text, rowSeparator) {
		td = append(td, strings.Split(line, valueSeparator))
	}

	return
}