Allow ignoring lines containing a sentinel
This commit is contained in:
parent
e433b90297
commit
40a9ab8929
@ -306,11 +306,12 @@ type wrapper struct {
|
|||||||
indent string
|
indent string
|
||||||
width, indent_width int
|
width, indent_width int
|
||||||
|
|
||||||
sgr sgr_state
|
sgr sgr_state
|
||||||
hyperlink hyperlink_state
|
hyperlink hyperlink_state
|
||||||
current_word strings.Builder
|
current_word strings.Builder
|
||||||
current_line line_builder
|
current_line line_builder
|
||||||
lines []string
|
lines []string
|
||||||
|
ignore_lines_containing []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *wrapper) newline_prefix() {
|
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))
|
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() {
|
func (self *wrapper) end_current_line() {
|
||||||
line := self.current_line.reset()
|
line := self.current_line.reset()
|
||||||
if strings.HasSuffix(line, self.indent) && wcswidth.Stringwidth(line) == self.indent_width {
|
if strings.HasSuffix(line, self.indent) && wcswidth.Stringwidth(line) == self.indent_width {
|
||||||
line = line[:len(line)-len(self.indent)]
|
line = line[:len(line)-len(self.indent)]
|
||||||
}
|
}
|
||||||
self.lines = append(self.lines, line)
|
self.append_line(line)
|
||||||
self.newline_prefix()
|
self.newline_prefix()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +396,7 @@ func (self *wrapper) wrap_text(text string) string {
|
|||||||
if last_line == self.current_line.reset() {
|
if last_line == self.current_line.reset() {
|
||||||
last_line = ""
|
last_line = ""
|
||||||
}
|
}
|
||||||
self.lines = append(self.lines, last_line)
|
self.append_line(last_line)
|
||||||
return strings.Join(self.lines, "\n")
|
return strings.Join(self.lines, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +409,8 @@ func new_wrapper(indent string, width int) *wrapper {
|
|||||||
return &ans
|
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 := new_wrapper(indent, width)
|
||||||
|
w.ignore_lines_containing = ignore_lines_containing
|
||||||
return w.wrap_text(text)
|
return w.wrap_text(text)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user