add line wrapping support
This commit is contained in:
parent
db6017dccf
commit
81f5b527a0
1 changed files with 25 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||||
|
@ -148,7 +149,7 @@ func (c *showCommand) showAccount(gts *client.Client) error {
|
||||||
account.FollowersCount,
|
account.FollowersCount,
|
||||||
account.FollowingCount,
|
account.FollowingCount,
|
||||||
account.StatusCount,
|
account.StatusCount,
|
||||||
stripHTMLTags(account.Note),
|
wrapLine(stripHTMLTags(account.Note), "\n ", 80),
|
||||||
metadata,
|
metadata,
|
||||||
account.URL,
|
account.URL,
|
||||||
)
|
)
|
||||||
|
@ -171,3 +172,26 @@ func stripHTMLTags(text string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wrapLine(line, separator string, charLimit int) string {
|
||||||
|
if len(line) <= charLimit {
|
||||||
|
return line
|
||||||
|
}
|
||||||
|
|
||||||
|
leftcursor, rightcursor := 0, 0
|
||||||
|
|
||||||
|
var builder strings.Builder
|
||||||
|
|
||||||
|
for rightcursor < (len(line) - charLimit) {
|
||||||
|
rightcursor += charLimit
|
||||||
|
for !unicode.IsSpace(rune(line[rightcursor-1])) {
|
||||||
|
rightcursor--
|
||||||
|
}
|
||||||
|
builder.WriteString(line[leftcursor:rightcursor] + separator)
|
||||||
|
leftcursor = rightcursor
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.WriteString(line[rightcursor:])
|
||||||
|
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue