MCPcopy
hub / github.com/mathaou/termdbms / GetFormattedTextBuffer

Function GetFormattedTextBuffer

viewer/ui.go:144–183  ·  view source on GitHub ↗
(m *TuiModel)

Source from the content-addressed store, hash-verified

142}
143
144func GetFormattedTextBuffer(m *TuiModel) []string {
145 v := m.Data().EditTextBuffer
146
147 lines := SplitLines(v)
148 FormatModeOffset = len(strconv.Itoa(len(lines))) + 1 // number of characters in the numeric string
149
150 var ret []string
151 m.Format.RunningOffsets = []int{}
152
153 total := 0
154 strlen := 0
155 for i, v := range lines {
156 xOffset := len(strconv.Itoa(i))
157 totalOffset := Max(FormatModeOffset-xOffset, 0)
158 //wrap := wordwrap.String(v, m.Viewport.Width-totalOffset)
159
160 right := tuiutil.Indent(
161 v,
162 fmt.Sprintf("%d%s", i, strings.Repeat(" ", totalOffset)),
163 false)
164 ret = append(ret, right)
165 m.Format.RunningOffsets = append(m.Format.RunningOffsets, total)
166
167 strlen = len(v)
168
169 total += strlen + 1
170 }
171
172 lineLength := len(ret)
173 // need to add this so that the last line can be edited
174 m.Format.RunningOffsets = append(m.Format.RunningOffsets,
175 m.Format.RunningOffsets[lineLength-1]+
176 len(ret[len(ret)-1][FormatModeOffset:]))
177
178 for i := len(ret); i < m.Viewport.Height; i++ {
179 ret = append(ret, "")
180 }
181
182 return ret
183}
184
185func DisplayFormatText(m *TuiModel) string {
186 cpy := make([]string, len(m.Format.EditSlices))

Callers 6

initFunction · 0.85
InsertCharacterFunction · 0.85
HandleFormatInputFunction · 0.85
CreateEmptyBufferFunction · 0.85
CreatePopulatedBufferFunction · 0.85
EditEnterFunction · 0.85

Calls 4

IndentFunction · 0.92
SplitLinesFunction · 0.85
MaxFunction · 0.85
DataMethod · 0.80

Tested by

no test coverage detected