From bedb9979a9b65dad9d72dcbdb3174508d3714f36 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 23 May 2018 00:44:08 +0300 Subject: Update some dependencies --- vendor/maunium.net/go/tview/textview.go | 106 +++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 36 deletions(-) (limited to 'vendor/maunium.net/go/tview/textview.go') diff --git a/vendor/maunium.net/go/tview/textview.go b/vendor/maunium.net/go/tview/textview.go index 16b9dfb..44aeb1e 100644 --- a/vendor/maunium.net/go/tview/textview.go +++ b/vendor/maunium.net/go/tview/textview.go @@ -769,10 +769,60 @@ func (t *TextView) Draw(screen tcell.Screen) { } // Print the line. - var currentTag, currentRegion, currentEscapeTag, skipped int + var currentTag, currentRegion, currentEscapeTag, skipped, runeSeqWidth int + runeSequence := make([]rune, 0, 10) + flush := func() { + if len(runeSequence) == 0 { + return + } + + // Mix the existing style with the new style. + _, _, existingStyle, _ := screen.GetContent(x+posX, y+line-t.lineOffset) + _, background, _ := existingStyle.Decompose() + style := overlayStyle(background, defaultStyle, foregroundColor, backgroundColor, attributes) + + // Do we highlight this character? + var highlighted bool + if len(regionID) > 0 { + if _, ok := t.highlights[regionID]; ok { + highlighted = true + } + } + if highlighted { + fg, bg, _ := style.Decompose() + if bg == tcell.ColorDefault { + r, g, b := fg.RGB() + c := colorful.Color{R: float64(r) / 255, G: float64(g) / 255, B: float64(b) / 255} + _, _, li := c.Hcl() + if li < .5 { + bg = tcell.ColorWhite + } else { + bg = tcell.ColorBlack + } + } + style = style.Background(fg).Foreground(bg) + } + + // Draw the character. + var comb []rune + if len(runeSequence) > 1 { + // Allocate space for the combining characters only when necessary. + comb = make([]rune, len(runeSequence)-1) + copy(comb, runeSequence[1:]) + } + for offset := 0; offset < runeSeqWidth; offset++ { + screen.SetContent(x+posX+offset, y+line-t.lineOffset, runeSequence[0], comb, style) + } + + // Advance. + posX += runeSeqWidth + runeSequence = runeSequence[:0] + runeSeqWidth = 0 + } for pos, ch := range text { // Get the color. if currentTag < len(colorTags) && pos >= colorTagIndices[currentTag][0] && pos < colorTagIndices[currentTag][1] { + flush() if pos == colorTagIndices[currentTag][1]-1 { foregroundColor, backgroundColor, attributes = styleFromTag(foregroundColor, backgroundColor, attributes, colorTags[currentTag]) currentTag++ @@ -782,6 +832,7 @@ func (t *TextView) Draw(screen tcell.Screen) { // Get the region. if currentRegion < len(regionIndices) && pos >= regionIndices[currentRegion][0] && pos < regionIndices[currentRegion][1] { + flush() if pos == regionIndices[currentRegion][1]-1 { regionID = regions[currentRegion][1] currentRegion++ @@ -791,6 +842,7 @@ func (t *TextView) Draw(screen tcell.Screen) { // Skip the second-to-last character of an escape tag. if currentEscapeTag < len(escapeIndices) && pos >= escapeIndices[currentEscapeTag][0] && pos < escapeIndices[currentEscapeTag][1] { + flush() if pos == escapeIndices[currentEscapeTag][1]-1 { currentEscapeTag++ } else if pos == escapeIndices[currentEscapeTag][1]-2 { @@ -801,7 +853,14 @@ func (t *TextView) Draw(screen tcell.Screen) { // Determine the width of this rune. chWidth := runewidth.RuneWidth(ch) if chWidth == 0 { - continue + // If this is not a modifier, we treat it as a space character. + if len(runeSequence) == 0 { + ch = ' ' + chWidth = 1 + } else { + runeSequence = append(runeSequence, ch) + continue + } } // Skip to the right. @@ -811,44 +870,19 @@ func (t *TextView) Draw(screen tcell.Screen) { } // Stop at the right border. - if posX+chWidth > width { + if posX+runeSeqWidth+chWidth > width { break } - // Mix the existing style with the new style. - _, _, existingStyle, _ := screen.GetContent(x+posX, y+line-t.lineOffset) - _, background, _ := existingStyle.Decompose() - style := overlayStyle(background, defaultStyle, foregroundColor, backgroundColor, attributes) + // Flush the rune sequence. + flush() - // Do we highlight this character? - var highlighted bool - if len(regionID) > 0 { - if _, ok := t.highlights[regionID]; ok { - highlighted = true - } - } - if highlighted { - fg, bg, _ := style.Decompose() - if bg == tcell.ColorDefault { - r, g, b := fg.RGB() - c := colorful.Color{R: float64(r) / 255, G: float64(g) / 255, B: float64(b) / 255} - _, _, li := c.Hcl() - if li < .5 { - bg = tcell.ColorWhite - } else { - bg = tcell.ColorBlack - } - } - style = style.Background(fg).Foreground(bg) - } - - // Draw the character. - for offset := 0; offset < chWidth; offset++ { - screen.SetContent(x+posX+offset, y+line-t.lineOffset, ch, nil, style) - } - - // Advance. - posX += chWidth + // Queue this rune. + runeSequence = append(runeSequence, ch) + runeSeqWidth += chWidth + } + if posX+runeSeqWidth <= width { + flush() } } -- cgit v1.2.3