forked from sloum/bombadillo
Merge branch 'incorrect_line_wrapping_endash' of asdf/bombadillo into master
This commit is contained in:
commit
4ea753561f
16
cui/cui.go
16
cui/cui.go
|
@ -81,21 +81,25 @@ func Clear(dir string) {
|
|||
|
||||
}
|
||||
|
||||
// takes the document content (as a slice) and modifies any lines that are longer
|
||||
// than the specified console width, splitting them over two lines. returns the
|
||||
// amended document content as a slice.
|
||||
// word wrapping uses a "greedy" algorithm
|
||||
// Takes the document content (as a slice of strings) and wraps any lines that
|
||||
// are longer than the specified console width. returns the amended document
|
||||
// content as a slice of strings.
|
||||
// Word wrapping uses a "greedy" algorithm, where long lines are split in to
|
||||
// words, and then rebuilt word by word to fill the available space. any
|
||||
// leftover words overflow to the next line.
|
||||
// To offer some support for unicode, some lengths are calculated using a slice
|
||||
// of runes in the following way: len([]rune(string))
|
||||
func wrapLines(s []string, consolewidth int) []string {
|
||||
out := []string{}
|
||||
for _, ln := range s {
|
||||
if len(ln) <= consolewidth {
|
||||
if len([]rune(ln)) <= consolewidth {
|
||||
out = append(out, ln)
|
||||
} else {
|
||||
words := strings.SplitAfter(ln, " ")
|
||||
var subout bytes.Buffer
|
||||
for i, wd := range words {
|
||||
sublen := subout.Len()
|
||||
wdlen := len(wd)
|
||||
wdlen := len([]rune(wd))
|
||||
if sublen+wdlen <= consolewidth {
|
||||
subout.WriteString(wd)
|
||||
if i == len(words)-1 {
|
||||
|
|
Loading…
Reference in New Issue