Пример #1
0
func (w *TcellWindow) printString(text string, pair ColorPair, a Attr) {
	t := text
	lx := 0

	var style tcell.Style
	if w.color {
		style = pair.style().
			Reverse(a&Attr(tcell.AttrReverse) != 0).
			Underline(a&Attr(tcell.AttrUnderline) != 0)
	} else {
		style = ColDefault.style().
			Reverse(a&Attr(tcell.AttrReverse) != 0 || pair == ColCurrent || pair == ColCurrentMatch).
			Underline(a&Attr(tcell.AttrUnderline) != 0 || pair == ColMatch || pair == ColCurrentMatch)
	}
	style = style.
		Blink(a&Attr(tcell.AttrBlink) != 0).
		Bold(a&Attr(tcell.AttrBold) != 0).
		Dim(a&Attr(tcell.AttrDim) != 0)

	for {
		if len(t) == 0 {
			break
		}
		r, size := utf8.DecodeRuneInString(t)
		t = t[size:]

		if r < rune(' ') { // ignore control characters
			continue
		}

		if r == '\n' {
			w.lastY++
			lx = 0
		} else {

			if r == '\u000D' { // skip carriage return
				continue
			}

			var xPos = w.left + w.lastX + lx
			var yPos = w.top + w.lastY
			if xPos < (w.left+w.width) && yPos < (w.top+w.height) {
				_screen.SetContent(xPos, yPos, r, nil, style)
			}
			lx += runewidth.RuneWidth(r)
		}
	}
	w.lastX += lx
}
Пример #2
0
func (w *TcellWindow) fillString(text string, pair ColorPair, a Attr) FillReturn {
	lx := 0

	var style tcell.Style
	if w.color {
		style = pair.style()
	} else {
		style = ColDefault.style()
	}
	style = style.
		Blink(a&Attr(tcell.AttrBlink) != 0).
		Bold(a&Attr(tcell.AttrBold) != 0).
		Dim(a&Attr(tcell.AttrDim) != 0).
		Reverse(a&Attr(tcell.AttrReverse) != 0).
		Underline(a&Attr(tcell.AttrUnderline) != 0)

	for _, r := range text {
		if r == '\n' {
			w.lastY++
			w.lastX = 0
			lx = 0
		} else {
			var xPos = w.left + w.lastX + lx

			// word wrap:
			if xPos >= (w.left + w.width) {
				w.lastY++
				w.lastX = 0
				lx = 0
				xPos = w.left
			}
			var yPos = w.top + w.lastY

			if yPos >= (w.top + w.height) {
				return FillSuspend
			}

			_screen.SetContent(xPos, yPos, r, nil, style)
			lx += runewidth.RuneWidth(r)
		}
	}
	w.lastX += lx

	return FillContinue
}
Пример #3
0
func (w *Window) FillString(text string, pair ColorPair, a Attr) bool {
	lx := 0

	var style tcell.Style
	if _color {
		style = pair.style()
	} else {
		style = ColDefault.style()
	}
	style = style.
		Blink(a&Attr(tcell.AttrBlink) != 0).
		Bold(a&Attr(tcell.AttrBold) != 0).
		Dim(a&Attr(tcell.AttrDim) != 0).
		Reverse(a&Attr(tcell.AttrReverse) != 0).
		Underline(a&Attr(tcell.AttrUnderline) != 0)

	for _, r := range text {
		if r == '\n' {
			w.win().LastY++
			w.win().LastX = 0
			lx = 0
		} else {
			var xPos = w.Left + w.win().LastX + lx

			// word wrap:
			if xPos > (w.Left + w.Width) {
				w.win().LastY++
				w.win().LastX = 0
				lx = 0
				xPos = w.Left
			}
			var yPos = w.Top + w.win().LastY

			if yPos >= (w.Top + w.Height) {
				return false
			}

			_screen.SetContent(xPos, yPos, r, nil, style)
			lx += runewidth.RuneWidth(r)
		}
	}
	w.win().LastX += lx

	return true
}