]> git.lizzy.rs Git - micro.git/blob - cmd/micro/view.go
2f34ccf05dfc0e52a50dfb64f69e4264a6c52248
[micro.git] / cmd / micro / view.go
1 package main
2
3 import (
4         "strconv"
5         "strings"
6         "time"
7
8         "github.com/mattn/go-runewidth"
9         "github.com/zyedidia/tcell"
10 )
11
12 // The View struct stores information about a view into a buffer.
13 // It stores information about the cursor, and the viewport
14 // that the user sees the buffer from.
15 type View struct {
16         // A pointer to the buffer's cursor for ease of access
17         Cursor *Cursor
18
19         // The topmost line, used for vertical scrolling
20         Topline int
21         // The leftmost column, used for horizontal scrolling
22         leftCol int
23
24         // Percentage of the terminal window that this view takes up (from 0 to 100)
25         widthPercent  int
26         heightPercent int
27
28         // Specifies whether or not this view holds a help buffer
29         Help bool
30
31         // Actual with and height
32         width  int
33         height int
34
35         // Where this view is located
36         x, y int
37
38         // How much to offset because of line numbers
39         lineNumOffset int
40
41         // Holds the list of gutter messages
42         messages map[string][]GutterMessage
43
44         // This is the index of this view in the views array
45         Num int
46         // What tab is this view stored in
47         TabNum int
48
49         // The buffer
50         Buf *Buffer
51         // The statusline
52         sline Statusline
53
54         // Since tcell doesn't differentiate between a mouse release event
55         // and a mouse move event with no keys pressed, we need to keep
56         // track of whether or not the mouse was pressed (or not released) last event to determine
57         // mouse release events
58         mouseReleased bool
59
60         // This stores when the last click was
61         // This is useful for detecting double and triple clicks
62         lastClickTime time.Time
63
64         // lastCutTime stores when the last ctrl+k was issued.
65         // It is used for clearing the clipboard to replace it with fresh cut lines.
66         lastCutTime time.Time
67
68         // freshClip returns true if the clipboard has never been pasted.
69         freshClip bool
70
71         // Was the last mouse event actually a double click?
72         // Useful for detecting triple clicks -- if a double click is detected
73         // but the last mouse event was actually a double click, it's a triple click
74         doubleClick bool
75         // Same here, just to keep track for mouse move events
76         tripleClick bool
77
78         // Syntax highlighting matches
79         matches SyntaxMatches
80         // The matches from the last frame
81         lastMatches SyntaxMatches
82
83         splitNode *LeafNode
84 }
85
86 // NewView returns a new fullscreen view
87 func NewView(buf *Buffer) *View {
88         screenW, screenH := screen.Size()
89         return NewViewWidthHeight(buf, screenW, screenH-1)
90 }
91
92 // NewViewWidthHeight returns a new view with the specified width and height percentages
93 // Note that w and h are percentages not actual values
94 func NewViewWidthHeight(buf *Buffer, w, h int) *View {
95         v := new(View)
96
97         v.x, v.y = 0, 0
98
99         v.width = w
100         v.height = h
101
102         v.ToggleTabbar()
103
104         v.OpenBuffer(buf)
105
106         v.messages = make(map[string][]GutterMessage)
107
108         v.sline = Statusline{
109                 view: v,
110         }
111
112         if settings["statusline"].(bool) {
113                 v.height--
114         }
115
116         return v
117 }
118
119 func (v *View) ToggleStatusLine() {
120         if settings["statusline"].(bool) {
121                 v.height--
122         } else {
123                 v.height++
124         }
125 }
126
127 func (v *View) ToggleTabbar() {
128         if len(tabs) > 1 {
129                 if v.y == 0 {
130                         // Include one line for the tab bar at the top
131                         v.height--
132                         v.y = 1
133                 }
134         } else {
135                 if v.y == 1 {
136                         v.y = 0
137                         v.height++
138                 }
139         }
140 }
141
142 // ScrollUp scrolls the view up n lines (if possible)
143 func (v *View) ScrollUp(n int) {
144         // Try to scroll by n but if it would overflow, scroll by 1
145         if v.Topline-n >= 0 {
146                 v.Topline -= n
147         } else if v.Topline > 0 {
148                 v.Topline--
149         }
150 }
151
152 // ScrollDown scrolls the view down n lines (if possible)
153 func (v *View) ScrollDown(n int) {
154         // Try to scroll by n but if it would overflow, scroll by 1
155         if v.Topline+n <= v.Buf.NumLines-v.height {
156                 v.Topline += n
157         } else if v.Topline < v.Buf.NumLines-v.height {
158                 v.Topline++
159         }
160 }
161
162 // CanClose returns whether or not the view can be closed
163 // If there are unsaved changes, the user will be asked if the view can be closed
164 // causing them to lose the unsaved changes
165 // The message is what to print after saying "You have unsaved changes. "
166 func (v *View) CanClose(msg string) bool {
167         if v.Buf.IsModified {
168                 quit, canceled := messenger.Prompt("You have unsaved changes. "+msg, "Unsaved", NoCompletion)
169                 if !canceled {
170                         if strings.ToLower(quit) == "yes" || strings.ToLower(quit) == "y" {
171                                 return true
172                         } else if strings.ToLower(quit) == "save" || strings.ToLower(quit) == "s" {
173                                 v.Save()
174                                 return true
175                         }
176                 }
177         } else {
178                 return true
179         }
180         return false
181 }
182
183 // OpenBuffer opens a new buffer in this view.
184 // This resets the topline, event handler and cursor.
185 func (v *View) OpenBuffer(buf *Buffer) {
186         screen.Clear()
187         v.CloseBuffer()
188         v.Buf = buf
189         v.Cursor = &buf.Cursor
190         v.Topline = 0
191         v.leftCol = 0
192         v.Cursor.ResetSelection()
193         v.Relocate()
194         v.messages = make(map[string][]GutterMessage)
195
196         v.matches = Match(v)
197
198         // Set mouseReleased to true because we assume the mouse is not being pressed when
199         // the editor is opened
200         v.mouseReleased = true
201         v.lastClickTime = time.Time{}
202 }
203
204 // CloseBuffer performs any closing functions on the buffer
205 func (v *View) CloseBuffer() {
206         if v.Buf != nil {
207                 v.Buf.Serialize()
208         }
209 }
210
211 // ReOpen reloads the current buffer
212 func (v *View) ReOpen() {
213         if v.CanClose("Continue? (yes, no, save) ") {
214                 screen.Clear()
215                 v.Buf.ReOpen()
216                 v.Relocate()
217                 v.matches = Match(v)
218         }
219 }
220
221 // HSplit opens a horizontal split with the given buffer
222 func (v *View) HSplit(buf *Buffer) bool {
223         v.splitNode.HSplit(buf)
224         tabs[v.TabNum].Resize()
225         return false
226 }
227
228 // VSplit opens a vertical split with the given buffer
229 func (v *View) VSplit(buf *Buffer) bool {
230         v.splitNode.VSplit(buf)
231         tabs[v.TabNum].Resize()
232         return false
233 }
234
235 // Relocate moves the view window so that the cursor is in view
236 // This is useful if the user has scrolled far away, and then starts typing
237 func (v *View) Relocate() bool {
238         ret := false
239         cy := v.Cursor.Y
240         scrollmargin := int(settings["scrollmargin"].(float64))
241         if cy < v.Topline+scrollmargin && cy > scrollmargin-1 {
242                 v.Topline = cy - scrollmargin
243                 ret = true
244         } else if cy < v.Topline {
245                 v.Topline = cy
246                 ret = true
247         }
248         if cy > v.Topline+v.height-1-scrollmargin && cy < v.Buf.NumLines-scrollmargin {
249                 v.Topline = cy - v.height + 1 + scrollmargin
250                 ret = true
251         } else if cy >= v.Buf.NumLines-scrollmargin && cy > v.height {
252                 v.Topline = v.Buf.NumLines - v.height
253                 ret = true
254         }
255
256         cx := v.Cursor.GetVisualX()
257         if cx < v.leftCol {
258                 v.leftCol = cx
259                 ret = true
260         }
261         if cx+v.lineNumOffset+1 > v.leftCol+v.width {
262                 v.leftCol = cx - v.width + v.lineNumOffset + 1
263                 ret = true
264         }
265         return ret
266 }
267
268 // MoveToMouseClick moves the cursor to location x, y assuming x, y were given
269 // by a mouse click
270 func (v *View) MoveToMouseClick(x, y int) {
271         if y-v.Topline > v.height-1 {
272                 v.ScrollDown(1)
273                 y = v.height + v.Topline - 1
274         }
275         if y >= v.Buf.NumLines {
276                 y = v.Buf.NumLines - 1
277         }
278         if y < 0 {
279                 y = 0
280         }
281         if x < 0 {
282                 x = 0
283         }
284
285         x = v.Cursor.GetCharPosInLine(y, x)
286         if x > Count(v.Buf.Line(y)) {
287                 x = Count(v.Buf.Line(y))
288         }
289         v.Cursor.X = x
290         v.Cursor.Y = y
291         v.Cursor.LastVisualX = v.Cursor.GetVisualX()
292 }
293
294 // HandleEvent handles an event passed by the main loop
295 func (v *View) HandleEvent(event tcell.Event) {
296         // This bool determines whether the view is relocated at the end of the function
297         // By default it's true because most events should cause a relocate
298         relocate := true
299
300         v.Buf.CheckModTime()
301
302         switch e := event.(type) {
303         case *tcell.EventResize:
304                 // Window resized
305                 tabs[v.TabNum].Resize()
306         case *tcell.EventKey:
307                 if e.Key() == tcell.KeyRune && (e.Modifiers() == 0 || e.Modifiers() == tcell.ModShift) {
308                         // Insert a character
309                         if v.Cursor.HasSelection() {
310                                 v.Cursor.DeleteSelection()
311                                 v.Cursor.ResetSelection()
312                         }
313                         v.Buf.Insert(v.Cursor.Loc, string(e.Rune()))
314                         v.Cursor.Right()
315
316                         for _, pl := range loadedPlugins {
317                                 _, err := Call(pl+".onRune", []string{string(e.Rune())})
318                                 if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
319                                         TermMessage(err)
320                                 }
321                         }
322                 } else {
323                         for key, actions := range bindings {
324                                 if e.Key() == key.keyCode {
325                                         if e.Key() == tcell.KeyRune {
326                                                 if e.Rune() != key.r {
327                                                         continue
328                                                 }
329                                         }
330                                         if e.Modifiers() == key.modifiers {
331                                                 relocate = false
332                                                 for _, action := range actions {
333                                                         relocate = action(v) || relocate
334                                                 }
335                                         }
336                                 }
337                         }
338                 }
339         case *tcell.EventPaste:
340                 if v.Cursor.HasSelection() {
341                         v.Cursor.DeleteSelection()
342                         v.Cursor.ResetSelection()
343                 }
344                 clip := e.Text()
345                 v.Buf.Insert(v.Cursor.Loc, clip)
346                 v.Cursor.Loc = v.Cursor.Loc.Move(Count(clip), v.Buf)
347                 v.freshClip = false
348         case *tcell.EventMouse:
349                 x, y := e.Position()
350                 x -= v.lineNumOffset - v.leftCol + v.x
351                 y += v.Topline - v.y
352                 // Don't relocate for mouse events
353                 relocate = false
354
355                 button := e.Buttons()
356
357                 switch button {
358                 case tcell.Button1:
359                         // Left click
360                         if v.mouseReleased {
361                                 v.MoveToMouseClick(x, y)
362                                 if time.Since(v.lastClickTime)/time.Millisecond < doubleClickThreshold {
363                                         if v.doubleClick {
364                                                 // Triple click
365                                                 v.lastClickTime = time.Now()
366
367                                                 v.tripleClick = true
368                                                 v.doubleClick = false
369
370                                                 v.Cursor.SelectLine()
371                                         } else {
372                                                 // Double click
373                                                 v.lastClickTime = time.Now()
374
375                                                 v.doubleClick = true
376                                                 v.tripleClick = false
377
378                                                 v.Cursor.SelectWord()
379                                         }
380                                 } else {
381                                         v.doubleClick = false
382                                         v.tripleClick = false
383                                         v.lastClickTime = time.Now()
384
385                                         v.Cursor.OrigSelection[0] = v.Cursor.Loc
386                                         v.Cursor.CurSelection[0] = v.Cursor.Loc
387                                         v.Cursor.CurSelection[1] = v.Cursor.Loc
388                                 }
389                                 v.mouseReleased = false
390                         } else if !v.mouseReleased {
391                                 v.MoveToMouseClick(x, y)
392                                 if v.tripleClick {
393                                         v.Cursor.AddLineToSelection()
394                                 } else if v.doubleClick {
395                                         v.Cursor.AddWordToSelection()
396                                 } else {
397                                         v.Cursor.CurSelection[1] = v.Cursor.Loc
398                                 }
399                         }
400                 case tcell.ButtonNone:
401                         // Mouse event with no click
402                         if !v.mouseReleased {
403                                 // Mouse was just released
404
405                                 // Relocating here isn't really necessary because the cursor will
406                                 // be in the right place from the last mouse event
407                                 // However, if we are running in a terminal that doesn't support mouse motion
408                                 // events, this still allows the user to make selections, except only after they
409                                 // release the mouse
410
411                                 if !v.doubleClick && !v.tripleClick {
412                                         v.MoveToMouseClick(x, y)
413                                         v.Cursor.CurSelection[1] = v.Cursor.Loc
414                                 }
415                                 v.mouseReleased = true
416                         }
417                 case tcell.WheelUp:
418                         // Scroll up
419                         scrollspeed := int(settings["scrollspeed"].(float64))
420                         v.ScrollUp(scrollspeed)
421                 case tcell.WheelDown:
422                         // Scroll down
423                         scrollspeed := int(settings["scrollspeed"].(float64))
424                         v.ScrollDown(scrollspeed)
425                 }
426         }
427
428         if relocate {
429                 v.Relocate()
430         }
431         if settings["syntax"].(bool) {
432                 v.matches = Match(v)
433         }
434 }
435
436 // GutterMessage creates a message in this view's gutter
437 func (v *View) GutterMessage(section string, lineN int, msg string, kind int) {
438         lineN--
439         gutterMsg := GutterMessage{
440                 lineNum: lineN,
441                 msg:     msg,
442                 kind:    kind,
443         }
444         for _, v := range v.messages {
445                 for _, gmsg := range v {
446                         if gmsg.lineNum == lineN {
447                                 return
448                         }
449                 }
450         }
451         messages := v.messages[section]
452         v.messages[section] = append(messages, gutterMsg)
453 }
454
455 // ClearGutterMessages clears all gutter messages from a given section
456 func (v *View) ClearGutterMessages(section string) {
457         v.messages[section] = []GutterMessage{}
458 }
459
460 // ClearAllGutterMessages clears all the gutter messages
461 func (v *View) ClearAllGutterMessages() {
462         for k := range v.messages {
463                 v.messages[k] = []GutterMessage{}
464         }
465 }
466
467 func (v *View) drawCell(x, y int, ch rune, combc []rune, style tcell.Style) {
468         if x >= v.x && x < v.x+v.width && y >= v.y && y < v.y+v.height {
469                 screen.SetContent(x, y, ch, combc, style)
470         }
471 }
472
473 // DisplayView renders the view to the screen
474 func (v *View) DisplayView() {
475         // The charNum we are currently displaying
476         // starts at the start of the viewport
477         charNum := Loc{0, v.Topline}
478
479         // Convert the length of buffer to a string, and get the length of the string
480         // We are going to have to offset by that amount
481         maxLineLength := len(strconv.Itoa(v.Buf.NumLines))
482
483         if settings["ruler"] == true {
484                 // + 1 for the little space after the line number
485                 v.lineNumOffset = maxLineLength + 1
486         } else {
487                 v.lineNumOffset = 0
488         }
489
490         // We need to add to the line offset if there are gutter messages
491         var hasGutterMessages bool
492         for _, v := range v.messages {
493                 if len(v) > 0 {
494                         hasGutterMessages = true
495                 }
496         }
497         if hasGutterMessages {
498                 v.lineNumOffset += 2
499         }
500
501         if v.x != 0 {
502                 // One space for the extra split divider
503                 v.lineNumOffset++
504         }
505
506         // These represent the current screen coordinates
507         screenX, screenY := 0, 0
508
509         highlightStyle := defStyle
510
511         // ViewLine is the current line from the top of the viewport
512         for viewLine := 0; viewLine < v.height; viewLine++ {
513                 screenY = v.y + viewLine
514                 screenX = v.x
515
516                 // This is the current line number of the buffer that we are drawing
517                 curLineN := viewLine + v.Topline
518
519                 if v.x != 0 {
520                         // Draw the split divider
521                         v.drawCell(screenX, screenY, '|', nil, defStyle.Reverse(true))
522                         screenX++
523                 }
524
525                 // If the buffer is smaller than the view height we have to clear all this space
526                 if curLineN >= v.Buf.NumLines {
527                         for i := screenX; i < v.x+v.width; i++ {
528                                 v.drawCell(i, screenY, ' ', nil, defStyle)
529                         }
530
531                         continue
532                 }
533                 line := v.Buf.Line(curLineN)
534
535                 // If there are gutter messages we need to display the '>>' symbol here
536                 if hasGutterMessages {
537                         // msgOnLine stores whether or not there is a gutter message on this line in particular
538                         msgOnLine := false
539                         for k := range v.messages {
540                                 for _, msg := range v.messages[k] {
541                                         if msg.lineNum == curLineN {
542                                                 msgOnLine = true
543                                                 gutterStyle := defStyle
544                                                 switch msg.kind {
545                                                 case GutterInfo:
546                                                         if style, ok := colorscheme["gutter-info"]; ok {
547                                                                 gutterStyle = style
548                                                         }
549                                                 case GutterWarning:
550                                                         if style, ok := colorscheme["gutter-warning"]; ok {
551                                                                 gutterStyle = style
552                                                         }
553                                                 case GutterError:
554                                                         if style, ok := colorscheme["gutter-error"]; ok {
555                                                                 gutterStyle = style
556                                                         }
557                                                 }
558                                                 v.drawCell(screenX, screenY, '>', nil, gutterStyle)
559                                                 screenX++
560                                                 v.drawCell(screenX, screenY, '>', nil, gutterStyle)
561                                                 screenX++
562                                                 if v.Cursor.Y == curLineN {
563                                                         messenger.Message(msg.msg)
564                                                         messenger.gutterMessage = true
565                                                 }
566                                         }
567                                 }
568                         }
569                         // If there is no message on this line we just display an empty offset
570                         if !msgOnLine {
571                                 v.drawCell(screenX, screenY, ' ', nil, defStyle)
572                                 screenX++
573                                 v.drawCell(screenX, screenY, ' ', nil, defStyle)
574                                 screenX++
575                                 if v.Cursor.Y == curLineN && messenger.gutterMessage {
576                                         messenger.Reset()
577                                         messenger.gutterMessage = false
578                                 }
579                         }
580                 }
581
582                 if settings["ruler"] == true {
583                         // Write the line number
584                         lineNumStyle := defStyle
585                         if style, ok := colorscheme["line-number"]; ok {
586                                 lineNumStyle = style
587                         }
588                         if style, ok := colorscheme["current-line-number"]; ok {
589                                 if curLineN == v.Cursor.Y {
590                                         lineNumStyle = style
591                                 }
592                         }
593
594                         lineNum := strconv.Itoa(curLineN + 1)
595
596                         // Write the spaces before the line number if necessary
597                         for i := 0; i < maxLineLength-len(lineNum); i++ {
598                                 v.drawCell(screenX, screenY, ' ', nil, lineNumStyle)
599                                 screenX++
600                         }
601                         // Write the actual line number
602                         for _, ch := range lineNum {
603                                 v.drawCell(screenX, screenY, ch, nil, lineNumStyle)
604                                 screenX++
605                         }
606
607                         // Write the extra space
608                         v.drawCell(screenX, screenY, ' ', nil, lineNumStyle)
609                         screenX++
610                 }
611
612                 // Now we actually draw the line
613                 for colN, ch := range line {
614                         lineStyle := defStyle
615
616                         if settings["syntax"].(bool) {
617                                 // Syntax highlighting is enabled
618                                 highlightStyle = v.matches[viewLine][colN]
619                         }
620
621                         if v.Cursor.HasSelection() &&
622                                 (charNum.GreaterEqual(v.Cursor.CurSelection[0]) && charNum.LessThan(v.Cursor.CurSelection[1]) ||
623                                         charNum.LessThan(v.Cursor.CurSelection[0]) && charNum.GreaterEqual(v.Cursor.CurSelection[1])) {
624                                 // The current character is selected
625                                 lineStyle = defStyle.Reverse(true)
626
627                                 if style, ok := colorscheme["selection"]; ok {
628                                         lineStyle = style
629                                 }
630                         } else {
631                                 lineStyle = highlightStyle
632                         }
633
634                         // We need to display the background of the linestyle with the correct color if cursorline is enabled
635                         // and this is the current view and there is no selection on this line and the cursor is on this line
636                         if settings["cursorline"].(bool) && tabs[curTab].curView == v.Num && !v.Cursor.HasSelection() && v.Cursor.Y == curLineN {
637                                 if style, ok := colorscheme["cursor-line"]; ok {
638                                         fg, _, _ := style.Decompose()
639                                         lineStyle = lineStyle.Background(fg)
640                                 }
641                         }
642
643                         if ch == '\t' {
644                                 // If the character we are displaying is a tab, we need to do a bunch of special things
645
646                                 // First the user may have configured an `indent-char` to be displayed to show that this
647                                 // is a tab character
648                                 lineIndentStyle := defStyle
649                                 if style, ok := colorscheme["indent-char"]; ok {
650                                         lineIndentStyle = style
651                                 }
652                                 if v.Cursor.HasSelection() &&
653                                         (charNum.GreaterEqual(v.Cursor.CurSelection[0]) && charNum.LessThan(v.Cursor.CurSelection[1]) ||
654                                                 charNum.LessThan(v.Cursor.CurSelection[0]) && charNum.GreaterEqual(v.Cursor.CurSelection[1])) {
655
656                                         lineIndentStyle = defStyle.Reverse(true)
657
658                                         if style, ok := colorscheme["selection"]; ok {
659                                                 lineIndentStyle = style
660                                         }
661                                 }
662                                 if settings["cursorline"].(bool) && tabs[curTab].curView == v.Num && !v.Cursor.HasSelection() && v.Cursor.Y == curLineN {
663                                         if style, ok := colorscheme["cursor-line"]; ok {
664                                                 fg, _, _ := style.Decompose()
665                                                 lineIndentStyle = lineIndentStyle.Background(fg)
666                                         }
667                                 }
668                                 // Here we get the indent char
669                                 indentChar := []rune(settings["indentchar"].(string))
670                                 if screenX-v.x-v.leftCol >= v.lineNumOffset {
671                                         v.drawCell(screenX-v.leftCol, screenY, indentChar[0], nil, lineIndentStyle)
672                                 }
673                                 // Now the tab has to be displayed as a bunch of spaces
674                                 tabSize := int(settings["tabsize"].(float64))
675                                 for i := 0; i < tabSize-1; i++ {
676                                         screenX++
677                                         if screenX-v.x-v.leftCol >= v.lineNumOffset {
678                                                 v.drawCell(screenX-v.leftCol, screenY, ' ', nil, lineStyle)
679                                         }
680                                 }
681                         } else if runewidth.RuneWidth(ch) > 1 {
682                                 if screenX-v.x-v.leftCol >= v.lineNumOffset {
683                                         v.drawCell(screenX, screenY, ch, nil, lineStyle)
684                                 }
685                                 for i := 0; i < runewidth.RuneWidth(ch)-1; i++ {
686                                         screenX++
687                                         if screenX-v.x-v.leftCol >= v.lineNumOffset {
688                                                 v.drawCell(screenX-v.leftCol, screenY, '<', nil, lineStyle)
689                                         }
690                                 }
691                         } else {
692                                 if screenX-v.x-v.leftCol >= v.lineNumOffset {
693                                         v.drawCell(screenX-v.leftCol, screenY, ch, nil, lineStyle)
694                                 }
695                         }
696                         charNum = charNum.Move(1, v.Buf)
697                         screenX++
698                 }
699                 // Here we are at a newline
700
701                 // The newline may be selected, in which case we should draw the selection style
702                 // with a space to represent it
703                 if v.Cursor.HasSelection() &&
704                         (charNum.GreaterEqual(v.Cursor.CurSelection[0]) && charNum.LessThan(v.Cursor.CurSelection[1]) ||
705                                 charNum.LessThan(v.Cursor.CurSelection[0]) && charNum.GreaterEqual(v.Cursor.CurSelection[1])) {
706
707                         selectStyle := defStyle.Reverse(true)
708
709                         if style, ok := colorscheme["selection"]; ok {
710                                 selectStyle = style
711                         }
712                         v.drawCell(screenX, screenY, ' ', nil, selectStyle)
713                         screenX++
714                 }
715
716                 charNum = charNum.Move(1, v.Buf)
717
718                 for i := 0; i < v.width; i++ {
719                         lineStyle := defStyle
720                         if settings["cursorline"].(bool) && tabs[curTab].curView == v.Num && !v.Cursor.HasSelection() && v.Cursor.Y == curLineN {
721                                 if style, ok := colorscheme["cursor-line"]; ok {
722                                         fg, _, _ := style.Decompose()
723                                         lineStyle = lineStyle.Background(fg)
724                                 }
725                         }
726                         if screenX-v.x-v.leftCol+i >= v.lineNumOffset {
727                                 v.drawCell(screenX-v.leftCol+i, screenY, ' ', nil, lineStyle)
728                         }
729                 }
730         }
731 }
732
733 // DisplayCursor draws the current buffer's cursor to the screen
734 func (v *View) DisplayCursor() {
735         // Don't draw the cursor if it is out of the viewport or if it has a selection
736         if (v.Cursor.Y-v.Topline < 0 || v.Cursor.Y-v.Topline > v.height-1) || v.Cursor.HasSelection() {
737                 screen.HideCursor()
738         } else {
739                 screen.ShowCursor(v.x+v.Cursor.GetVisualX()+v.lineNumOffset-v.leftCol, v.Cursor.Y-v.Topline+v.y)
740         }
741 }
742
743 // Display renders the view, the cursor, and statusline
744 func (v *View) Display() {
745         v.DisplayView()
746         if v.Num == tabs[curTab].curView {
747                 v.DisplayCursor()
748         }
749         _, screenH := screen.Size()
750         if settings["statusline"].(bool) {
751                 v.sline.Display()
752         } else if (v.y + v.height) != screenH-1 {
753                 for x := 0; x < v.width; x++ {
754                         screen.SetContent(v.x+x, v.y+v.height, '-', nil, defStyle.Reverse(true))
755                 }
756         }
757 }