aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-03-23 01:07:44 +0200
committerTulir Asokan <tulir@maunium.net>2018-03-23 01:20:26 +0200
commita3f48093ebd8fcc3dc2ffefc727378ae8dca7269 (patch)
treea27d46999800d480c5bdc17b7285e6f203dc41f9
parent16635dcde7b3402e7eff44864b4dba5a2ddd8a37 (diff)
gofmt and govet
-rw-r--r--interface/ui.go1
-rw-r--r--matrix/pushrules/action.go4
-rw-r--r--matrix/rooms/member.go6
-rw-r--r--matrix/rooms/room.go2
-rw-r--r--ui/debug/external.go2
-rw-r--r--ui/view-main.go2
-rw-r--r--ui/widget/advanced-inputfield.go54
7 files changed, 40 insertions, 31 deletions
diff --git a/interface/ui.go b/interface/ui.go
index f08c9f3..43e214b 100644
--- a/interface/ui.go
+++ b/interface/ui.go
@@ -54,5 +54,4 @@ type MainView interface {
}
type LoginView interface {
-
}
diff --git a/matrix/pushrules/action.go b/matrix/pushrules/action.go
index 1de973f..acb97b9 100644
--- a/matrix/pushrules/action.go
+++ b/matrix/pushrules/action.go
@@ -46,9 +46,9 @@ type PushActionArrayShould struct {
// Whether or not the array contained a Notify, DontNotify or Coalesce action type.
NotifySpecified bool
// Whether or not the event in question should trigger a notification.
- Notify bool
+ Notify bool
// Whether or not the event in question should be highlighted.
- Highlight bool
+ Highlight bool
// Whether or not the event in question should trigger a sound alert.
PlaySound bool
diff --git a/matrix/rooms/member.go b/matrix/rooms/member.go
index 4af20a6..20c994b 100644
--- a/matrix/rooms/member.go
+++ b/matrix/rooms/member.go
@@ -35,11 +35,11 @@ type Member struct {
// The MXID of the member.
UserID string `json:"-"`
// The membership status. Defaults to leave.
- Membership Membership `json:"membership"`
+ Membership Membership `json:"membership"`
// The display name of the user. Defaults to the user ID.
- DisplayName string `json:"displayname"`
+ DisplayName string `json:"displayname"`
// The avatar URL of the user. Defaults to an empty string.
- AvatarURL string `json:"avatar_url"`
+ AvatarURL string `json:"avatar_url"`
}
// eventToRoomMember converts a m.room.member state event into a Member object.
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index 4166fd7..56614de 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -42,7 +42,7 @@ type Room struct {
topicCache string
// 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() {
diff --git a/ui/debug/external.go b/ui/debug/external.go
index 8122b2a..faabbcc 100644
--- a/ui/debug/external.go
+++ b/ui/debug/external.go
@@ -34,7 +34,7 @@ func EnableExternal() {
func ExtPrintf(text string, args ...interface{}) {
if writer != nil {
- fmt.Fprintf(writer, text + "\n", args...)
+ fmt.Fprintf(writer, text+"\n", args...)
}
}
diff --git a/ui/view-main.go b/ui/view-main.go
index 9c0550c..844962d 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -386,7 +386,7 @@ func (view *MainView) LoadHistory(room string, initial bool) {
}
err = roomView.SaveHistory(view.config.HistoryDir)
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.parent.Render()
diff --git a/ui/widget/advanced-inputfield.go b/ui/widget/advanced-inputfield.go
index 4948247..f74ce29 100644
--- a/ui/widget/advanced-inputfield.go
+++ b/ui/widget/advanced-inputfield.go
@@ -222,23 +222,9 @@ func (field *AdvancedInputField) SetFinishedFunc(handler func(key tcell.Key)) tv
return field.SetDoneFunc(handler)
}
-// Draw draws this primitive onto the screen.
-func (field *AdvancedInputField) Draw(screen tcell.Screen) {
- field.Box.Draw(screen)
-
- // 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
+// drawInput calculates the field width and draws the background.
+func (field *AdvancedInputField) drawInput(screen tcell.Screen, rightLimit, x, y int) (fieldWidth int) {
+ fieldWidth = field.fieldWidth
if fieldWidth == 0 {
fieldWidth = math.MaxInt32
}
@@ -249,13 +235,16 @@ func (field *AdvancedInputField) Draw(screen tcell.Screen) {
for index := 0; index < fieldWidth; index++ {
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 != "" {
tview.Print(screen, field.placeholder, x, y, fieldWidth, tview.AlignLeft, field.placeholderTextColor)
}
- // Draw entered text.
if field.maskCharacter > 0 {
text = strings.Repeat(string(field.maskCharacter), utf8.RuneCountInString(field.text))
}
@@ -264,7 +253,6 @@ func (field *AdvancedInputField) Draw(screen tcell.Screen) {
fieldWidth--
}
- // Recalculate view offset
if field.cursorOffset < field.viewOffset {
field.viewOffset = field.cursorOffset
} else if field.cursorOffset > field.viewOffset+fieldWidth {
@@ -272,12 +260,16 @@ func (field *AdvancedInputField) Draw(screen tcell.Screen) {
} else if textWidth-field.viewOffset < fieldWidth {
field.viewOffset = textWidth - fieldWidth
}
- // Make sure view offset didn't become negative
+
if 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)
relPos := 0
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 {
return field.cursorOffset
}