gofmt and govet
This commit is contained in:
parent
16635dcde7
commit
a3f48093eb
@ -54,5 +54,4 @@ type MainView interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LoginView interface {
|
type LoginView interface {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ type Room struct {
|
|||||||
topicCache string
|
topicCache string
|
||||||
|
|
||||||
// fetchHistoryLock is used to make sure multiple goroutines don't fetch history for this room at the same time.
|
// fetchHistoryLock is used to make sure multiple goroutines don't fetch history for this room at the same time.
|
||||||
fetchHistoryLock *sync.Mutex `json:"-"`
|
fetchHistoryLock *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (room *Room) LockHistory() {
|
func (room *Room) LockHistory() {
|
||||||
|
@ -386,7 +386,7 @@ func (view *MainView) LoadHistory(room string, initial bool) {
|
|||||||
}
|
}
|
||||||
err = roomView.SaveHistory(view.config.HistoryDir)
|
err = roomView.SaveHistory(view.config.HistoryDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Printf("%Failed to save history of %s: %v", roomView.Room.GetTitle(), err)
|
debug.Printf("Failed to save history of %s: %v", roomView.Room.GetTitle(), err)
|
||||||
}
|
}
|
||||||
view.config.Session.Save()
|
view.config.Session.Save()
|
||||||
view.parent.Render()
|
view.parent.Render()
|
||||||
|
@ -222,23 +222,9 @@ func (field *AdvancedInputField) SetFinishedFunc(handler func(key tcell.Key)) tv
|
|||||||
return field.SetDoneFunc(handler)
|
return field.SetDoneFunc(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw draws this primitive onto the screen.
|
// drawInput calculates the field width and draws the background.
|
||||||
func (field *AdvancedInputField) Draw(screen tcell.Screen) {
|
func (field *AdvancedInputField) drawInput(screen tcell.Screen, rightLimit, x, y int) (fieldWidth int) {
|
||||||
field.Box.Draw(screen)
|
fieldWidth = field.fieldWidth
|
||||||
|
|
||||||
// Prepare
|
|
||||||
x, y, width, height := field.GetInnerRect()
|
|
||||||
rightLimit := x + width
|
|
||||||
if height < 1 || rightLimit <= x {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw label.
|
|
||||||
_, drawnWidth := tview.Print(screen, field.label, x, y, rightLimit-x, tview.AlignLeft, field.labelColor)
|
|
||||||
x += drawnWidth
|
|
||||||
|
|
||||||
// Draw input area.
|
|
||||||
fieldWidth := field.fieldWidth
|
|
||||||
if fieldWidth == 0 {
|
if fieldWidth == 0 {
|
||||||
fieldWidth = math.MaxInt32
|
fieldWidth = math.MaxInt32
|
||||||
}
|
}
|
||||||
@ -249,13 +235,16 @@ func (field *AdvancedInputField) Draw(screen tcell.Screen) {
|
|||||||
for index := 0; index < fieldWidth; index++ {
|
for index := 0; index < fieldWidth; index++ {
|
||||||
screen.SetContent(x+index, y, ' ', nil, fieldStyle)
|
screen.SetContent(x+index, y, ' ', nil, fieldStyle)
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
text := field.text
|
// prepareText prepares the text to be displayed and recalculates the view and cursor offsets.
|
||||||
|
func (field *AdvancedInputField) prepareText(screen tcell.Screen, fieldWidth, x, y int) (text string) {
|
||||||
|
text = field.text
|
||||||
if text == "" && field.placeholder != "" {
|
if text == "" && field.placeholder != "" {
|
||||||
tview.Print(screen, field.placeholder, x, y, fieldWidth, tview.AlignLeft, field.placeholderTextColor)
|
tview.Print(screen, field.placeholder, x, y, fieldWidth, tview.AlignLeft, field.placeholderTextColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw entered text.
|
|
||||||
if field.maskCharacter > 0 {
|
if field.maskCharacter > 0 {
|
||||||
text = strings.Repeat(string(field.maskCharacter), utf8.RuneCountInString(field.text))
|
text = strings.Repeat(string(field.maskCharacter), utf8.RuneCountInString(field.text))
|
||||||
}
|
}
|
||||||
@ -264,7 +253,6 @@ func (field *AdvancedInputField) Draw(screen tcell.Screen) {
|
|||||||
fieldWidth--
|
fieldWidth--
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recalculate view offset
|
|
||||||
if field.cursorOffset < field.viewOffset {
|
if field.cursorOffset < field.viewOffset {
|
||||||
field.viewOffset = field.cursorOffset
|
field.viewOffset = field.cursorOffset
|
||||||
} else if field.cursorOffset > field.viewOffset+fieldWidth {
|
} else if field.cursorOffset > field.viewOffset+fieldWidth {
|
||||||
@ -272,12 +260,16 @@ func (field *AdvancedInputField) Draw(screen tcell.Screen) {
|
|||||||
} else if textWidth-field.viewOffset < fieldWidth {
|
} else if textWidth-field.viewOffset < fieldWidth {
|
||||||
field.viewOffset = textWidth - fieldWidth
|
field.viewOffset = textWidth - fieldWidth
|
||||||
}
|
}
|
||||||
// Make sure view offset didn't become negative
|
|
||||||
if field.viewOffset < 0 {
|
if field.viewOffset < 0 {
|
||||||
field.viewOffset = 0
|
field.viewOffset = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw entered text.
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// drawText draws the text and the cursor.
|
||||||
|
func (field *AdvancedInputField) drawText(screen tcell.Screen, fieldWidth, x, y int, text string) {
|
||||||
runes := []rune(text)
|
runes := []rune(text)
|
||||||
relPos := 0
|
relPos := 0
|
||||||
for pos := field.viewOffset; pos <= fieldWidth+field.viewOffset && pos < len(runes); pos++ {
|
for pos := field.viewOffset; pos <= fieldWidth+field.viewOffset && pos < len(runes); pos++ {
|
||||||
@ -298,6 +290,24 @@ func (field *AdvancedInputField) Draw(screen tcell.Screen) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw draws this primitive onto the screen.
|
||||||
|
func (field *AdvancedInputField) Draw(screen tcell.Screen) {
|
||||||
|
field.Box.Draw(screen)
|
||||||
|
|
||||||
|
x, y, width, height := field.GetInnerRect()
|
||||||
|
rightLimit := x + width
|
||||||
|
if height < 1 || rightLimit <= x {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, drawnWidth := tview.Print(screen, field.label, x, y, rightLimit-x, tview.AlignLeft, field.labelColor)
|
||||||
|
x += drawnWidth
|
||||||
|
|
||||||
|
fieldWidth := field.drawInput(screen, rightLimit, x, y)
|
||||||
|
text := field.prepareText(screen, fieldWidth, x, y)
|
||||||
|
field.drawText(screen, fieldWidth, x, y, text)
|
||||||
|
}
|
||||||
|
|
||||||
func (field *AdvancedInputField) GetCursorOffset() int {
|
func (field *AdvancedInputField) GetCursorOffset() int {
|
||||||
return field.cursorOffset
|
return field.cursorOffset
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user