コード例 #1
0
ファイル: terminal_writer.go プロジェクト: jayunit100/origin
func (w wordWrapWriter) Write(p []byte) (nn int, err error) {
	if w.limit == 0 {
		return w.writer.Write(p)
	}
	original := string(p)
	wrapped := wordwrap.WrapString(original, w.limit)
	return w.writer.Write([]byte(wrapped))
}
コード例 #2
0
func (w wordWrapWriter) Write(p []byte) (nn int, err error) {
	if w.limit == 0 {
		return w.writer.Write(p)
	}
	original := string(p)
	wrapped := wordwrap.WrapString(original, w.limit)
	l, e := w.writer.Write([]byte(wrapped))

	// This wrapped word writer could modify input in some cases such that
	// the length of output is not equal to the length of input and this
	// can cause ErrShortWrite error. So to avoid the error, make sure the
	// returned length of output bytes is equal to the length of input.
	// This returns length of original in non-erroneous cases, and in erroneous
	// cases min(len(original), l).
	if e == nil || l > len(original) {
		l = len(original)
	}

	return l, e
}