MCPcopy
hub / github.com/pterm/pterm / Srender

Method Srender

bulletlist_printer.go:102–139  ·  view source on GitHub ↗

Srender renders the list as a string.

()

Source from the content-addressed store, hash-verified

100
101// Srender renders the list as a string.
102func (l BulletListPrinter) Srender() (string, error) {
103 var ret strings.Builder
104 for _, item := range l.Items {
105 if item.TextStyle == nil {
106 if l.TextStyle == nil {
107 item.TextStyle = &ThemeDefault.BulletListTextStyle
108 } else {
109 item.TextStyle = l.TextStyle
110 }
111 }
112 if item.BulletStyle == nil {
113 if l.BulletStyle == nil {
114 item.BulletStyle = &ThemeDefault.BulletListBulletStyle
115 } else {
116 item.BulletStyle = l.BulletStyle
117 }
118 }
119
120 split := strings.Split(item.Text, "\n")
121 for i, line := range split {
122 ret.WriteString(strings.Repeat(" ", item.Level))
123 if i == 0 {
124 if item.Bullet == "" {
125 ret.WriteString(item.BulletStyle.Sprint(l.Bullet))
126 } else {
127 ret.WriteString(item.BulletStyle.Sprint(item.Bullet))
128 }
129 ret.WriteByte(' ')
130 } else {
131 ret.WriteString(strings.Repeat(" ", len(item.Bullet)))
132 ret.WriteString(" ")
133 }
134 ret.WriteString(item.TextStyle.Sprint(line))
135 ret.WriteByte('\n')
136 }
137 }
138 return ret.String(), nil
139}

Callers 1

RenderMethod · 0.95

Calls 2

SprintMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected