mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
Adding '-verbose' will print out the allocation information for the deployment. This also changes the job run command so that it now blocks until deployment is complete and adds timestamps to the output so that it's more in line with the output of node drain. This uses glint to print in place in running in a tty. Because glint doesn't yet support cmd/powershell, Windows workflows use a different library to print in place, which results in slightly different formatting: 1) different margins, and 2) no spinner indicating deployment in progress.
84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
package wordwrap
|
|
|
|
import (
|
|
"bytes"
|
|
"unicode"
|
|
)
|
|
|
|
const nbsp = 0xA0
|
|
|
|
// WrapString wraps the given string within lim width in characters.
|
|
//
|
|
// Wrapping is currently naive and only happens at white-space. A future
|
|
// version of the library will implement smarter wrapping. This means that
|
|
// pathological cases can dramatically reach past the limit, such as a very
|
|
// long word.
|
|
func WrapString(s string, lim uint) string {
|
|
// Initialize a buffer with a slightly larger size to account for breaks
|
|
init := make([]byte, 0, len(s))
|
|
buf := bytes.NewBuffer(init)
|
|
|
|
var current uint
|
|
var wordBuf, spaceBuf bytes.Buffer
|
|
var wordBufLen, spaceBufLen uint
|
|
|
|
for _, char := range s {
|
|
if char == '\n' {
|
|
if wordBuf.Len() == 0 {
|
|
if current+spaceBufLen > lim {
|
|
current = 0
|
|
} else {
|
|
current += spaceBufLen
|
|
spaceBuf.WriteTo(buf)
|
|
}
|
|
spaceBuf.Reset()
|
|
spaceBufLen = 0
|
|
} else {
|
|
current += spaceBufLen + wordBufLen
|
|
spaceBuf.WriteTo(buf)
|
|
spaceBuf.Reset()
|
|
spaceBufLen = 0
|
|
wordBuf.WriteTo(buf)
|
|
wordBuf.Reset()
|
|
wordBufLen = 0
|
|
}
|
|
buf.WriteRune(char)
|
|
current = 0
|
|
} else if unicode.IsSpace(char) && char != nbsp {
|
|
if spaceBuf.Len() == 0 || wordBuf.Len() > 0 {
|
|
current += spaceBufLen + wordBufLen
|
|
spaceBuf.WriteTo(buf)
|
|
spaceBuf.Reset()
|
|
spaceBufLen = 0
|
|
wordBuf.WriteTo(buf)
|
|
wordBuf.Reset()
|
|
wordBufLen = 0
|
|
}
|
|
|
|
spaceBuf.WriteRune(char)
|
|
spaceBufLen++
|
|
} else {
|
|
wordBuf.WriteRune(char)
|
|
wordBufLen++
|
|
|
|
if current+wordBufLen+spaceBufLen > lim && wordBufLen < lim {
|
|
buf.WriteRune('\n')
|
|
current = 0
|
|
spaceBuf.Reset()
|
|
spaceBufLen = 0
|
|
}
|
|
}
|
|
}
|
|
|
|
if wordBuf.Len() == 0 {
|
|
if current+spaceBufLen <= lim {
|
|
spaceBuf.WriteTo(buf)
|
|
}
|
|
} else {
|
|
spaceBuf.WriteTo(buf)
|
|
wordBuf.WriteTo(buf)
|
|
}
|
|
|
|
return buf.String()
|
|
}
|