Update some dependencies

This commit is contained in:
Tulir Asokan 2018-05-23 00:44:08 +03:00
parent 14903e0cdc
commit bedb9979a9
11 changed files with 195 additions and 116 deletions

8
Gopkg.lock generated
View File

@ -29,7 +29,7 @@
branch = "master" branch = "master"
name = "github.com/lucasb-eyer/go-colorful" name = "github.com/lucasb-eyer/go-colorful"
packages = ["."] packages = ["."]
revision = "231272389856c976b7500c4fffcc52ddf06ff4eb" revision = "fa0f842f26263fb2ace6d6118309c8481e029fc1"
[[projects]] [[projects]]
name = "github.com/mattn/go-runewidth" name = "github.com/mattn/go-runewidth"
@ -88,7 +88,7 @@
"html", "html",
"html/atom" "html/atom"
] ]
revision = "f73e4c9ed3b7ebdd5f699a16a880c2b1994e50dd" revision = "9ef9f5bb98a1fdc41f8cf6c250a4404b4085e389"
[[projects]] [[projects]]
name = "golang.org/x/text" name = "golang.org/x/text"
@ -124,7 +124,7 @@
branch = "master" branch = "master"
name = "maunium.net/go/gomatrix" name = "maunium.net/go/gomatrix"
packages = ["."] packages = ["."]
revision = "4ddf8d780ff6a0434a52c256015f7fcd2ca67dc9" revision = "b491397f18b90e34ef54b8b3598666564b90b01a"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -139,7 +139,7 @@
branch = "master" branch = "master"
name = "maunium.net/go/tview" name = "maunium.net/go/tview"
packages = ["."] packages = ["."]
revision = "7eabba90a261a481d36ace89daa79c56582238d7" revision = "8b261597bbdb95dcaef03854aaa0cc192f56b1ff"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"

View File

@ -308,7 +308,7 @@ second is the fast one.
![Warm, fast warm, happy and fast happy random colors, respectively.](doc/colorgens/colorgens.png) ![Warm, fast warm, happy and fast happy random colors, respectively.](doc/colorgens/colorgens.png)
Don't forget to initialize the random seed! You can see the code used for Don't forget to initialize the random seed! You can see the code used for
generating this picture in `doc/colorgens/golorgens.go`. generating this picture in `doc/colorgens/colorgens.go`.
### Getting random palettes ### Getting random palettes
As soon as you need to generate more than one random color, you probably want As soon as you need to generate more than one random color, you probably want

View File

@ -14,6 +14,7 @@ type Event struct {
ID string `json:"event_id"` // The unique ID of this event ID string `json:"event_id"` // The unique ID of this event
RoomID string `json:"room_id"` // The room the event was sent to. May be nil (e.g. for presence) RoomID string `json:"room_id"` // The room the event was sent to. May be nil (e.g. for presence)
Content map[string]interface{} `json:"content"` // The JSON content of the event. Content map[string]interface{} `json:"content"` // The JSON content of the event.
Redacts string `json:"redacts,omitempty"` // The event ID that was redacted if a m.room.redaction event
Unsigned Unsigned `json:"unsigned,omitempty"` // Unsigned content set by own homeserver. Unsigned Unsigned `json:"unsigned,omitempty"` // Unsigned content set by own homeserver.
} }

View File

@ -277,6 +277,7 @@ func (a *Application) Suspend(f func()) bool {
a.Unlock() a.Unlock()
panic(err) panic(err)
} }
a.screen.EnableMouse()
a.Unlock() a.Unlock()
a.Draw() a.Draw()

View File

@ -190,7 +190,7 @@ func (d *DropDown) GetFieldWidth() int {
// callback is called when this option was selected. It may be nil. // callback is called when this option was selected. It may be nil.
func (d *DropDown) AddOption(text string, selected func()) *DropDown { func (d *DropDown) AddOption(text string, selected func()) *DropDown {
d.options = append(d.options, &dropDownOption{Text: text, Selected: selected}) d.options = append(d.options, &dropDownOption{Text: text, Selected: selected})
d.list.AddItem(text, "", 0, selected) d.list.AddItem(text, "", 0, nil)
return d return d
} }

View File

@ -248,40 +248,18 @@ func (i *InputField) Draw(screen tcell.Screen) {
text := i.text text := i.text
if text == "" && i.placeholder != "" { if text == "" && i.placeholder != "" {
Print(screen, i.placeholder, x, y, fieldWidth, AlignLeft, i.placeholderTextColor) Print(screen, i.placeholder, x, y, fieldWidth, AlignLeft, i.placeholderTextColor)
} } else {
// Draw entered text. // Draw entered text.
if i.maskCharacter > 0 { if i.maskCharacter > 0 {
text = strings.Repeat(string(i.maskCharacter), utf8.RuneCountInString(i.text)) text = strings.Repeat(string(i.maskCharacter), utf8.RuneCountInString(i.text))
} else {
text = Escape(text)
} }
fieldWidth-- // We need one cell for the cursor. fieldWidth-- // We need one cell for the cursor.
if fieldWidth < runewidth.StringWidth(text) { if fieldWidth < runewidth.StringWidth(text) {
runes := []rune(text) Print(screen, text, x, y, fieldWidth, AlignRight, i.fieldTextColor)
for pos := len(runes) - 1; pos >= 0; pos-- {
ch := runes[pos]
w := runewidth.RuneWidth(ch)
if fieldWidth-w < 0 {
break
}
_, _, style, _ := screen.GetContent(x+fieldWidth-w, y)
style = style.Foreground(i.fieldTextColor)
for w > 0 {
fieldWidth--
screen.SetContent(x+fieldWidth, y, ch, nil, style)
w--
}
}
} else { } else {
pos := 0 Print(screen, text, x, y, fieldWidth, AlignLeft, i.fieldTextColor)
for _, ch := range text {
w := runewidth.RuneWidth(ch)
_, _, style, _ := screen.GetContent(x+pos, y)
style = style.Foreground(i.fieldTextColor)
for w > 0 {
screen.SetContent(x+pos, y, ch, nil, style)
pos++
w--
}
} }
} }

View File

@ -222,8 +222,8 @@ func (l *List) Draw(screen tcell.Screen) {
// We want to keep the current selection in view. What is our offset? // We want to keep the current selection in view. What is our offset?
var offset int var offset int
if l.showSecondaryText { if l.showSecondaryText {
if l.currentItem >= height/2 { if 2*l.currentItem >= height {
offset = l.currentItem + 1 - (height / 2) offset = (2*l.currentItem + 2 - height) / 2
} }
} else { } else {
if l.currentItem >= height { if l.currentItem >= height {
@ -296,6 +296,7 @@ func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primit
case tcell.KeyPgUp: case tcell.KeyPgUp:
l.currentItem -= 5 l.currentItem -= 5
case tcell.KeyEnter: case tcell.KeyEnter:
if l.currentItem >= 0 && l.currentItem < len(l.items) {
item := l.items[l.currentItem] item := l.items[l.currentItem]
if item.Selected != nil { if item.Selected != nil {
item.Selected() item.Selected()
@ -303,6 +304,7 @@ func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p Primit
if l.selected != nil { if l.selected != nil {
l.selected(l.currentItem, item.MainText, item.SecondaryText, item.Shortcut) l.selected(l.currentItem, item.MainText, item.SecondaryText, item.Shortcut)
} }
}
case tcell.KeyEscape: case tcell.KeyEscape:
if l.done != nil { if l.done != nil {
l.done() l.done()

24
vendor/maunium.net/go/tview/table.go generated vendored
View File

@ -33,6 +33,9 @@ type TableCell struct {
// The background color of the cell. // The background color of the cell.
BackgroundColor tcell.Color BackgroundColor tcell.Color
// The style attributes of the cell.
Attributes tcell.AttrMask
// If set to true, this cell cannot be selected. // If set to true, this cell cannot be selected.
NotSelectable bool NotSelectable bool
@ -107,6 +110,22 @@ func (c *TableCell) SetBackgroundColor(color tcell.Color) *TableCell {
return c return c
} }
// SetAttributes sets the cell's text attributes. You can combine different
// attributes using bitmask operations:
//
// cell.SetAttributes(tcell.AttrUnderline | tcell.AttrBold)
func (c *TableCell) SetAttributes(attr tcell.AttrMask) *TableCell {
c.Attributes = attr
return c
}
// SetStyle sets the cell's style (foreground color, background color, and
// attributes) all at once.
func (c *TableCell) SetStyle(style tcell.Style) *TableCell {
c.Color, c.BackgroundColor, c.Attributes = style.Decompose()
return c
}
// SetSelectable sets whether or not this cell can be selected by the user. // SetSelectable sets whether or not this cell can be selected by the user.
func (c *TableCell) SetSelectable(selectable bool) *TableCell { func (c *TableCell) SetSelectable(selectable bool) *TableCell {
c.NotSelectable = !selectable c.NotSelectable = !selectable
@ -684,11 +703,10 @@ ColumnLoop:
finalWidth = width - columnX - 1 finalWidth = width - columnX - 1
} }
cell.x, cell.y, cell.width = x+columnX+1, y+rowY, finalWidth cell.x, cell.y, cell.width = x+columnX+1, y+rowY, finalWidth
_, printed := Print(screen, cell.Text, x+columnX+1, y+rowY, finalWidth, cell.Align, cell.Color) _, printed := printWithStyle(screen, cell.Text, x+columnX+1, y+rowY, finalWidth, cell.Align, tcell.StyleDefault.Foreground(cell.Color)|tcell.Style(cell.Attributes))
if StringWidth(cell.Text)-printed > 0 && printed > 0 { if StringWidth(cell.Text)-printed > 0 && printed > 0 {
_, _, style, _ := screen.GetContent(x+columnX+1+finalWidth-1, y+rowY) _, _, style, _ := screen.GetContent(x+columnX+1+finalWidth-1, y+rowY)
fg, _, _ := style.Decompose() printWithStyle(screen, string(GraphicsEllipsis), x+columnX+1+finalWidth-1, y+rowY, 1, AlignLeft, style)
Print(screen, string(GraphicsEllipsis), x+columnX+1+finalWidth-1, y+rowY, 1, AlignLeft, fg)
} }
} }

View File

@ -769,50 +769,11 @@ func (t *TextView) Draw(screen tcell.Screen) {
} }
// Print the line. // Print the line.
var currentTag, currentRegion, currentEscapeTag, skipped int var currentTag, currentRegion, currentEscapeTag, skipped, runeSeqWidth int
for pos, ch := range text { runeSequence := make([]rune, 0, 10)
// Get the color. flush := func() {
if currentTag < len(colorTags) && pos >= colorTagIndices[currentTag][0] && pos < colorTagIndices[currentTag][1] { if len(runeSequence) == 0 {
if pos == colorTagIndices[currentTag][1]-1 { return
foregroundColor, backgroundColor, attributes = styleFromTag(foregroundColor, backgroundColor, attributes, colorTags[currentTag])
currentTag++
}
continue
}
// Get the region.
if currentRegion < len(regionIndices) && pos >= regionIndices[currentRegion][0] && pos < regionIndices[currentRegion][1] {
if pos == regionIndices[currentRegion][1]-1 {
regionID = regions[currentRegion][1]
currentRegion++
}
continue
}
// Skip the second-to-last character of an escape tag.
if currentEscapeTag < len(escapeIndices) && pos >= escapeIndices[currentEscapeTag][0] && pos < escapeIndices[currentEscapeTag][1] {
if pos == escapeIndices[currentEscapeTag][1]-1 {
currentEscapeTag++
} else if pos == escapeIndices[currentEscapeTag][1]-2 {
continue
}
}
// Determine the width of this rune.
chWidth := runewidth.RuneWidth(ch)
if chWidth == 0 {
continue
}
// Skip to the right.
if !t.wrap && skipped < skip {
skipped += chWidth
continue
}
// Stop at the right border.
if posX+chWidth > width {
break
} }
// Mix the existing style with the new style. // Mix the existing style with the new style.
@ -843,12 +804,85 @@ func (t *TextView) Draw(screen tcell.Screen) {
} }
// Draw the character. // Draw the character.
for offset := 0; offset < chWidth; offset++ { var comb []rune
screen.SetContent(x+posX+offset, y+line-t.lineOffset, ch, nil, style) 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. // Advance.
posX += chWidth 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++
}
continue
}
// 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++
}
continue
}
// 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 {
continue
}
}
// Determine the width of this rune.
chWidth := runewidth.RuneWidth(ch)
if chWidth == 0 {
// 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.
if !t.wrap && skipped < skip {
skipped += chWidth
continue
}
// Stop at the right border.
if posX+runeSeqWidth+chWidth > width {
break
}
// Flush the rune sequence.
flush()
// Queue this rune.
runeSequence = append(runeSequence, ch)
runeSeqWidth += chWidth
}
if posX+runeSeqWidth <= width {
flush()
} }
} }

77
vendor/maunium.net/go/tview/util.go generated vendored
View File

@ -297,7 +297,7 @@ func Print(screen tcell.Screen, text string, x, y, maxWidth, align int, color tc
// printWithStyle works like Print() but it takes a style instead of just a // printWithStyle works like Print() but it takes a style instead of just a
// foreground color. // foreground color.
func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int, style tcell.Style) (int, int) { func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int, style tcell.Style) (int, int) {
if maxWidth < 0 { if maxWidth <= 0 || len(text) == 0 {
return 0, 0 return 0, 0
} }
@ -315,6 +315,9 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int,
colorPos, escapePos, runePos, startPos int colorPos, escapePos, runePos, startPos int
foregroundColor, backgroundColor, attributes string foregroundColor, backgroundColor, attributes string
) )
if from >= len(runes) {
return ""
}
for pos := range text { for pos := range text {
// Handle color tags. // Handle color tags.
if colorPos < len(colorIndices) && pos >= colorIndices[colorPos][0] && pos < colorIndices[colorPos][1] { if colorPos < len(colorIndices) && pos >= colorIndices[colorPos][0] && pos < colorIndices[colorPos][1] {
@ -361,6 +364,9 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int,
width += w width += w
start = index start = index
} }
for start < len(runes) && runewidth.RuneWidth(runes[start]) == 0 {
start++
}
return printWithStyle(screen, substring(start, len(runes)), x+maxWidth-width, y, width, AlignLeft, style) return printWithStyle(screen, substring(start, len(runes)), x+maxWidth-width, y, width, AlignLeft, style)
} else if align == AlignCenter { } else if align == AlignCenter {
width := runewidth.StringWidth(strippedText) width := runewidth.StringWidth(strippedText)
@ -376,12 +382,15 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int,
var choppedLeft, choppedRight, leftIndex, rightIndex int var choppedLeft, choppedRight, leftIndex, rightIndex int
rightIndex = len(runes) - 1 rightIndex = len(runes) - 1
for rightIndex > leftIndex && width-choppedLeft-choppedRight > maxWidth { for rightIndex > leftIndex && width-choppedLeft-choppedRight > maxWidth {
leftWidth := runewidth.RuneWidth(runes[leftIndex])
rightWidth := runewidth.RuneWidth(runes[rightIndex])
if choppedLeft < choppedRight { if choppedLeft < choppedRight {
leftWidth := runewidth.RuneWidth(runes[leftIndex])
choppedLeft += leftWidth choppedLeft += leftWidth
leftIndex++ leftIndex++
for leftIndex < len(runes) && leftIndex < rightIndex && runewidth.RuneWidth(runes[leftIndex]) == 0 {
leftIndex++
}
} else { } else {
rightWidth := runewidth.RuneWidth(runes[rightIndex])
choppedRight += rightWidth choppedRight += rightWidth
rightIndex-- rightIndex--
} }
@ -397,9 +406,39 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int,
colorPos, escapePos int colorPos, escapePos int
foregroundColor, backgroundColor, attributes string foregroundColor, backgroundColor, attributes string
) )
runeSequence := make([]rune, 0, 10)
runeSeqWidth := 0
flush := func() {
if len(runeSequence) == 0 {
return // Nothing to flush.
}
// Print the rune sequence.
finalX := x + drawnWidth
_, _, finalStyle, _ := screen.GetContent(finalX, y)
_, background, _ := finalStyle.Decompose()
finalStyle = overlayStyle(background, style, foregroundColor, backgroundColor, attributes)
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++ {
// To avoid undesired effects, we place the same character in all cells.
screen.SetContent(finalX+offset, y, runeSequence[0], comb, finalStyle)
}
// Advance and reset.
drawn += len(runeSequence)
drawnWidth += runeSeqWidth
runeSequence = runeSequence[:0]
runeSeqWidth = 0
}
for pos, ch := range text { for pos, ch := range text {
// Handle color tags. // Handle color tags.
if colorPos < len(colorIndices) && pos >= colorIndices[colorPos][0] && pos < colorIndices[colorPos][1] { if colorPos < len(colorIndices) && pos >= colorIndices[colorPos][0] && pos < colorIndices[colorPos][1] {
flush()
if pos == colorIndices[colorPos][1]-1 { if pos == colorIndices[colorPos][1]-1 {
foregroundColor, backgroundColor, attributes = styleFromTag(foregroundColor, backgroundColor, attributes, colors[colorPos]) foregroundColor, backgroundColor, attributes = styleFromTag(foregroundColor, backgroundColor, attributes, colors[colorPos])
colorPos++ colorPos++
@ -409,6 +448,7 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int,
// Handle escape tags. // Handle escape tags.
if escapePos < len(escapeIndices) && pos >= escapeIndices[escapePos][0] && pos < escapeIndices[escapePos][1] { if escapePos < len(escapeIndices) && pos >= escapeIndices[escapePos][0] && pos < escapeIndices[escapePos][1] {
flush()
if pos == escapeIndices[escapePos][1]-1 { if pos == escapeIndices[escapePos][1]-1 {
escapePos++ escapePos++
} else if pos == escapeIndices[escapePos][1]-2 { } else if pos == escapeIndices[escapePos][1]-2 {
@ -419,21 +459,26 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int,
// Check if we have enough space for this rune. // Check if we have enough space for this rune.
chWidth := runewidth.RuneWidth(ch) chWidth := runewidth.RuneWidth(ch)
if drawnWidth+chWidth > maxWidth { if drawnWidth+chWidth > maxWidth {
break break // No. We're done then.
}
finalX := x + drawnWidth
// Print the rune.
_, _, finalStyle, _ := screen.GetContent(finalX, y)
_, background, _ := finalStyle.Decompose()
finalStyle = overlayStyle(background, style, foregroundColor, backgroundColor, attributes)
for offset := 0; offset < chWidth; offset++ {
// To avoid undesired effects, we place the same character in all cells.
screen.SetContent(finalX+offset, y, ch, nil, finalStyle)
} }
drawn++ // Put this rune in the queue.
drawnWidth += chWidth if chWidth == 0 {
// If this is not a modifier, we treat it as a space character.
if len(runeSequence) == 0 {
ch = ' '
chWidth = 1
}
} else {
// We have a character. Flush all previous runes.
flush()
}
runeSequence = append(runeSequence, ch)
runeSeqWidth += chWidth
}
if drawnWidth+runeSeqWidth <= maxWidth {
flush()
} }
return drawn, drawnWidth return drawn, drawnWidth