Allow ignoring lines containing a sentinel
This commit is contained in:
parent
e433b90297
commit
40a9ab8929
@ -311,6 +311,7 @@ type wrapper struct {
|
||||
current_word strings.Builder
|
||||
current_line line_builder
|
||||
lines []string
|
||||
ignore_lines_containing []string
|
||||
}
|
||||
|
||||
func (self *wrapper) newline_prefix() {
|
||||
@ -321,12 +322,21 @@ func (self *wrapper) newline_prefix() {
|
||||
self.current_line.add_escape_code(self.hyperlink.as_escape_codes(false))
|
||||
}
|
||||
|
||||
func (self *wrapper) append_line(line string) {
|
||||
for _, q := range self.ignore_lines_containing {
|
||||
if strings.Contains(line, q) {
|
||||
return
|
||||
}
|
||||
}
|
||||
self.lines = append(self.lines, line)
|
||||
}
|
||||
|
||||
func (self *wrapper) end_current_line() {
|
||||
line := self.current_line.reset()
|
||||
if strings.HasSuffix(line, self.indent) && wcswidth.Stringwidth(line) == self.indent_width {
|
||||
line = line[:len(line)-len(self.indent)]
|
||||
}
|
||||
self.lines = append(self.lines, line)
|
||||
self.append_line(line)
|
||||
self.newline_prefix()
|
||||
}
|
||||
|
||||
@ -386,7 +396,7 @@ func (self *wrapper) wrap_text(text string) string {
|
||||
if last_line == self.current_line.reset() {
|
||||
last_line = ""
|
||||
}
|
||||
self.lines = append(self.lines, last_line)
|
||||
self.append_line(last_line)
|
||||
return strings.Join(self.lines, "\n")
|
||||
}
|
||||
|
||||
@ -399,7 +409,8 @@ func new_wrapper(indent string, width int) *wrapper {
|
||||
return &ans
|
||||
}
|
||||
|
||||
func WrapText(text string, indent string, width int) string {
|
||||
func WrapText(text string, indent string, width int, ignore_lines_containing ...string) string {
|
||||
w := new_wrapper(indent, width)
|
||||
w.ignore_lines_containing = ignore_lines_containing
|
||||
return w.wrap_text(text)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user