11 "github.com/zyedidia/tcell"
14 // The ViewType defines what kind of view this is
15 type ViewType struct {
17 Readonly bool // The file cannot be edited
18 Scratch bool // The file cannot be saved
22 vtDefault = ViewType{0, false, false}
23 vtHelp = ViewType{1, true, true}
24 vtLog = ViewType{2, true, true}
25 vtScratch = ViewType{3, false, true}
26 vtRaw = ViewType{4, true, true}
27 vtTerm = ViewType{5, true, true}
30 // The View struct stores information about a view into a buffer.
31 // It stores information about the cursor, and the viewport
32 // that the user sees the buffer from.
34 // A pointer to the buffer's cursor for ease of access
37 // The topmost line, used for vertical scrolling
39 // The leftmost column, used for horizontal scrolling
42 // Specifies whether or not this view holds a help buffer
45 // Actual width and height
52 // Where this view is located
55 // How much to offset because of line numbers
58 // Holds the list of gutter messages
59 messages map[string][]GutterMessage
61 // This is the index of this view in the views array
63 // What tab is this view stored in
71 // Since tcell doesn't differentiate between a mouse release event
72 // and a mouse move event with no keys pressed, we need to keep
73 // track of whether or not the mouse was pressed (or not released) last event to determine
74 // mouse release events
77 // We need to keep track of insert key press toggle
79 // This stores when the last click was
80 // This is useful for detecting double and triple clicks
81 lastClickTime time.Time
84 // lastCutTime stores when the last ctrl+k was issued.
85 // It is used for clearing the clipboard to replace it with fresh cut lines.
88 // freshClip returns true if the clipboard has never been pasted.
91 // Was the last mouse event actually a double click?
92 // Useful for detecting triple clicks -- if a double click is detected
93 // but the last mouse event was actually a double click, it's a triple click
95 // Same here, just to keep track for mouse move events
98 // The cellview used for displaying and syntax highlighting
110 // NewView returns a new fullscreen view
111 func NewView(buf *Buffer) *View {
112 screenW, screenH := screen.Size()
113 return NewViewWidthHeight(buf, screenW, screenH)
116 // NewViewWidthHeight returns a new view with the specified width and height
117 // Note that w and h are raw column and row values
118 func NewViewWidthHeight(buf *Buffer, w, h int) *View {
125 v.cellview = new(CellView)
131 v.messages = make(map[string][]GutterMessage)
133 v.sline = &Statusline{
137 v.scrollbar = &ScrollBar{
141 if v.Buf.Settings["statusline"].(bool) {
145 v.term = new(Terminal)
147 for pl := range loadedPlugins {
148 _, err := Call(pl+".onViewOpen", v)
149 if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
158 // ToggleStatusLine creates an extra row for the statusline if necessary
159 func (v *View) ToggleStatusLine() {
160 if v.Buf.Settings["statusline"].(bool) {
167 // StartTerminal execs a command in this view
168 func (v *View) StartTerminal(execCmd []string) error {
169 err := v.term.Start(execCmd, v)
171 v.term.Resize(v.Width, v.Height)
177 // CloseTerminal shuts down the tty running in this view
178 // and returns it to the default view type
179 func (v *View) CloseTerminal() {
183 // ToggleTabbar creates an extra row for the tabbar if necessary
184 func (v *View) ToggleTabbar() {
187 // Include one line for the tab bar at the top
199 func (v *View) paste(clip string) {
200 leadingWS := GetLeadingWhitespace(v.Buf.Line(v.Cursor.Y))
202 if v.Cursor.HasSelection() {
203 v.Cursor.DeleteSelection()
204 v.Cursor.ResetSelection()
206 clip = strings.Replace(clip, "\n", "\n"+leadingWS, -1)
207 v.Buf.Insert(v.Cursor.Loc, clip)
208 // v.Cursor.Loc = v.Cursor.Loc.Move(Count(clip), v.Buf)
210 messenger.Message("Pasted clipboard")
213 // ScrollUp scrolls the view up n lines (if possible)
214 func (v *View) ScrollUp(n int) {
215 // Try to scroll by n but if it would overflow, scroll by 1
216 if v.Topline-n >= 0 {
218 } else if v.Topline > 0 {
223 // ScrollDown scrolls the view down n lines (if possible)
224 func (v *View) ScrollDown(n int) {
225 // Try to scroll by n but if it would overflow, scroll by 1
226 if v.Topline+n <= v.Buf.NumLines {
228 } else if v.Topline < v.Buf.NumLines-1 {
233 // CanClose returns whether or not the view can be closed
234 // If there are unsaved changes, the user will be asked if the view can be closed
235 // causing them to lose the unsaved changes
236 func (v *View) CanClose() bool {
237 if v.Type == vtDefault && v.Buf.Modified() {
240 if v.Buf.Settings["autosave"].(bool) {
243 choice, canceled = messenger.YesNoPrompt("Save changes to " + v.Buf.GetName() + " before closing? (y,n,esc) ")
257 // OpenBuffer opens a new buffer in this view.
258 // This resets the topline, event handler and cursor.
259 func (v *View) OpenBuffer(buf *Buffer) {
263 v.Cursor = &buf.Cursor
266 v.Cursor.ResetSelection()
269 v.messages = make(map[string][]GutterMessage)
271 // Set mouseReleased to true because we assume the mouse is not being pressed when
272 // the editor is opened
273 v.mouseReleased = true
274 // Set isOverwriteMode to false, because we assume we are in the default mode when editor
276 v.isOverwriteMode = false
277 v.lastClickTime = time.Time{}
279 GlobalPluginCall("onBufferOpen", v.Buf)
282 // Open opens the given file in the view
283 func (v *View) Open(filename string) {
284 filename = ReplaceHome(filename)
285 file, err := os.Open(filename)
286 fileInfo, _ := os.Stat(filename)
288 if err == nil && fileInfo.IsDir() {
289 messenger.Error(filename, " is a directory")
297 messenger.Message(err.Error())
298 // File does not exist -- create an empty buffer with that name
299 buf = NewBufferFromString("", filename)
301 buf = NewBuffer(file, FSize(file), filename)
306 // CloseBuffer performs any closing functions on the buffer
307 func (v *View) CloseBuffer() {
313 // ReOpen reloads the current buffer
314 func (v *View) ReOpen() {
322 // HSplit opens a horizontal split with the given buffer
323 func (v *View) HSplit(buf *Buffer) {
325 if v.Buf.Settings["splitbottom"].(bool) {
328 v.splitNode.HSplit(buf, v.Num+i)
331 // VSplit opens a vertical split with the given buffer
332 func (v *View) VSplit(buf *Buffer) {
334 if v.Buf.Settings["splitright"].(bool) {
337 v.splitNode.VSplit(buf, v.Num+i)
340 // HSplitIndex opens a horizontal split with the given buffer at the given index
341 func (v *View) HSplitIndex(buf *Buffer, splitIndex int) {
342 v.splitNode.HSplit(buf, splitIndex)
345 // VSplitIndex opens a vertical split with the given buffer at the given index
346 func (v *View) VSplitIndex(buf *Buffer, splitIndex int) {
347 v.splitNode.VSplit(buf, splitIndex)
350 // GetSoftWrapLocation gets the location of a visual click on the screen and converts it to col,line
351 func (v *View) GetSoftWrapLocation(vx, vy int) (int, int) {
352 if !v.Buf.Settings["softwrap"].(bool) {
353 if vy >= v.Buf.NumLines {
354 vy = v.Buf.NumLines - 1
356 vx = v.Cursor.GetCharPosInLine(vy, vx)
360 screenX, screenY := 0, v.Topline
361 for lineN := v.Topline; lineN < v.Bottomline(); lineN++ {
362 line := v.Buf.Line(lineN)
363 if lineN >= v.Buf.NumLines {
364 return 0, v.Buf.NumLines - 1
368 for _, ch := range line {
369 if screenX >= v.Width-v.lineNumOffset {
374 if screenX == vx && screenY == vy {
379 screenX += int(v.Buf.Settings["tabsize"].(float64)) - 1
395 // Bottomline returns the line number of the lowest line in the view
396 // You might think that this is obviously just v.Topline + v.Height
397 // but if softwrap is enabled things get complicated since one buffer
398 // line can take up multiple lines in the view
399 func (v *View) Bottomline() int {
400 if !v.Buf.Settings["softwrap"].(bool) {
401 return v.Topline + v.Height
404 screenX, screenY := 0, 0
406 for lineN := v.Topline; lineN < v.Topline+v.Height; lineN++ {
407 line := v.Buf.Line(lineN)
410 for _, ch := range line {
411 if screenX >= v.Width-v.lineNumOffset {
417 screenX += int(v.Buf.Settings["tabsize"].(float64)) - 1
427 if screenY >= v.Height {
431 return numLines + v.Topline
434 // Relocate moves the view window so that the cursor is in view
435 // This is useful if the user has scrolled far away, and then starts typing
436 func (v *View) Relocate() bool {
437 height := v.Bottomline() - v.Topline
440 scrollmargin := int(v.Buf.Settings["scrollmargin"].(float64))
441 if cy < v.Topline+scrollmargin && cy > scrollmargin-1 {
442 v.Topline = cy - scrollmargin
444 } else if cy < v.Topline {
448 if cy > v.Topline+height-1-scrollmargin && cy < v.Buf.NumLines-scrollmargin {
449 v.Topline = cy - height + 1 + scrollmargin
451 } else if cy >= v.Buf.NumLines-scrollmargin && cy > height {
452 v.Topline = v.Buf.NumLines - height
456 if !v.Buf.Settings["softwrap"].(bool) {
457 cx := v.Cursor.GetVisualX()
462 if cx+v.lineNumOffset+1 > v.leftCol+v.Width {
463 v.leftCol = cx - v.Width + v.lineNumOffset + 1
470 // GetMouseClickLocation gets the location in the buffer from a mouse click
472 func (v *View) GetMouseClickLocation(x, y int) (int, int) {
473 x -= v.lineNumOffset - v.leftCol + v.x
476 if y-v.Topline > v.Height-1 {
478 y = v.Height + v.Topline - 1
487 newX, newY := v.GetSoftWrapLocation(x, y)
488 if newX > Count(v.Buf.Line(newY)) {
489 newX = Count(v.Buf.Line(newY))
495 // MoveToMouseClick moves the cursor to location x, y assuming x, y were given
497 func (v *View) MoveToMouseClick(x, y int) {
498 if y-v.Topline > v.Height-1 {
500 y = v.Height + v.Topline - 1
509 x, y = v.GetSoftWrapLocation(x, y)
510 if x > Count(v.Buf.Line(y)) {
511 x = Count(v.Buf.Line(y))
515 v.Cursor.LastVisualX = v.Cursor.GetVisualX()
518 // Execute actions executes the supplied actions
519 func (v *View) ExecuteActions(actions []func(*View, bool) bool) bool {
521 readonlyBindingsList := []string{"Delete", "Insert", "Backspace", "Cut", "Play", "Paste", "Move", "Add", "DuplicateLine", "Macro"}
522 for _, action := range actions {
523 readonlyBindingsResult := false
524 funcName := ShortFuncName(action)
525 if v.Type.Readonly == true {
526 // check for readonly and if true only let key bindings get called if they do not change the contents.
527 for _, readonlyBindings := range readonlyBindingsList {
528 if strings.Contains(funcName, readonlyBindings) {
529 readonlyBindingsResult = true
533 if !readonlyBindingsResult {
534 // call the key binding
535 relocate = action(v, true) || relocate
537 if funcName != "ToggleMacro" && funcName != "PlayMacro" {
539 curMacro = append(curMacro, action)
548 // SetCursor sets the view's and buffer's cursor
549 func (v *View) SetCursor(c *Cursor) bool {
554 v.Buf.curCursor = c.Num
559 // HandleEvent handles an event passed by the main loop
560 func (v *View) HandleEvent(event tcell.Event) {
561 if v.Type == vtTerm {
562 v.term.HandleEvent(event)
567 v.Buf.Insert(v.Cursor.Loc, reflect.TypeOf(event).String()[7:])
568 v.Buf.Insert(v.Cursor.Loc, fmt.Sprintf(": %q\n", event.EscSeq()))
570 switch e := event.(type) {
571 case *tcell.EventKey:
572 if e.Key() == tcell.KeyCtrlQ {
580 // This bool determines whether the view is relocated at the end of the function
581 // By default it's true because most events should cause a relocate
586 switch e := event.(type) {
587 case *tcell.EventRaw:
588 for key, actions := range bindings {
589 if key.keyCode == -1 {
590 if e.EscSeq() == key.escape {
591 for _, c := range v.Buf.cursors {
597 relocate = v.ExecuteActions(actions) || relocate
599 v.SetCursor(&v.Buf.Cursor)
605 case *tcell.EventKey:
606 // Check first if input is a key binding, if it is we 'eat' the input and don't insert a rune
608 for key, actions := range bindings {
609 if e.Key() == key.keyCode {
610 if e.Key() == tcell.KeyRune {
611 if e.Rune() != key.r {
615 if e.Modifiers() == key.modifiers {
616 for _, c := range v.Buf.cursors {
623 relocate = v.ExecuteActions(actions) || relocate
625 v.SetCursor(&v.Buf.Cursor)
632 if !isBinding && e.Key() == tcell.KeyRune {
633 // Check viewtype if readonly don't insert a rune (readonly help and log view etc.)
634 if v.Type.Readonly == false {
635 for _, c := range v.Buf.cursors {
638 // Insert a character
639 if v.Cursor.HasSelection() {
640 v.Cursor.DeleteSelection()
641 v.Cursor.ResetSelection()
644 if v.isOverwriteMode {
647 v.Buf.Replace(v.Cursor.Loc, next, string(e.Rune()))
649 v.Buf.Insert(v.Cursor.Loc, string(e.Rune()))
652 for pl := range loadedPlugins {
653 _, err := Call(pl+".onRune", string(e.Rune()), v)
654 if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
660 curMacro = append(curMacro, e.Rune())
663 v.SetCursor(&v.Buf.Cursor)
666 case *tcell.EventPaste:
667 // Check viewtype if readonly don't paste (readonly help and log view etc.)
668 if v.Type.Readonly == false {
669 if !PreActionCall("Paste", v) {
673 for _, c := range v.Buf.cursors {
677 v.SetCursor(&v.Buf.Cursor)
679 PostActionCall("Paste", v)
681 case *tcell.EventMouse:
682 // Don't relocate for mouse events
685 button := e.Buttons()
687 for key, actions := range bindings {
688 if button == key.buttons && e.Modifiers() == key.modifiers {
689 for _, c := range v.Buf.cursors {
694 relocate = v.ExecuteActions(actions) || relocate
696 v.SetCursor(&v.Buf.Cursor)
701 for key, actions := range mouseBindings {
702 if button == key.buttons && e.Modifiers() == key.modifiers {
703 for _, action := range actions {
710 case tcell.ButtonNone:
711 // Mouse event with no click
712 if !v.mouseReleased {
713 // Mouse was just released
716 x -= v.lineNumOffset - v.leftCol + v.x
719 // Relocating here isn't really necessary because the cursor will
720 // be in the right place from the last mouse event
721 // However, if we are running in a terminal that doesn't support mouse motion
722 // events, this still allows the user to make selections, except only after they
725 if !v.doubleClick && !v.tripleClick {
726 v.MoveToMouseClick(x, y)
727 v.Cursor.SetSelectionEnd(v.Cursor.Loc)
728 v.Cursor.CopySelection("primary")
730 v.mouseReleased = true
737 // We run relocate again because there's a bug with relocating with softwrap
738 // when for example you jump to the bottom of the buffer and it tries to
739 // calculate where to put the topline so that the bottom line is at the bottom
740 // of the terminal and it runs into problems with visual lines vs real lines.
741 // This is (hopefully) a temporary solution
746 func (v *View) mainCursor() bool {
747 return v.Buf.curCursor == len(v.Buf.cursors)-1
750 // GutterMessage creates a message in this view's gutter
751 func (v *View) GutterMessage(section string, lineN int, msg string, kind int) {
753 gutterMsg := GutterMessage{
758 for _, v := range v.messages {
759 for _, gmsg := range v {
760 if gmsg.lineNum == lineN {
765 messages := v.messages[section]
766 v.messages[section] = append(messages, gutterMsg)
769 // ClearGutterMessages clears all gutter messages from a given section
770 func (v *View) ClearGutterMessages(section string) {
771 v.messages[section] = []GutterMessage{}
774 // ClearAllGutterMessages clears all the gutter messages
775 func (v *View) ClearAllGutterMessages() {
776 for k := range v.messages {
777 v.messages[k] = []GutterMessage{}
781 // Opens the given help page in a new horizontal split
782 func (v *View) openHelp(helpPage string) {
783 if data, err := FindRuntimeFile(RTHelp, helpPage).Data(); err != nil {
784 TermMessage("Unable to load help text", helpPage, "\n", err)
786 helpBuffer := NewBufferFromString(string(data), helpPage+".md")
787 helpBuffer.name = "Help"
789 if v.Type == vtHelp {
790 v.OpenBuffer(helpBuffer)
793 CurView().Type = vtHelp
798 // DisplayView draws the view to the screen
799 func (v *View) DisplayView() {
800 if v.Type == vtTerm {
805 if v.Buf.Settings["softwrap"].(bool) && v.leftCol != 0 {
809 if v.Type == vtLog || v.Type == vtRaw {
810 // Log or raw views should always follow the cursor...
814 // We need to know the string length of the largest line number
815 // so we can pad appropriately when displaying line numbers
816 maxLineNumLength := len(strconv.Itoa(v.Buf.NumLines))
818 if v.Buf.Settings["ruler"] == true {
819 // + 1 for the little space after the line number
820 v.lineNumOffset = maxLineNumLength + 1
825 // We need to add to the line offset if there are gutter messages
826 var hasGutterMessages bool
827 for _, v := range v.messages {
829 hasGutterMessages = true
832 if hasGutterMessages {
838 // One space for the extra split divider
843 xOffset := v.x + v.lineNumOffset
851 v.cellview.Draw(v.Buf, top, height, left, width-v.lineNumOffset)
857 for visualLineN, line = range v.cellview.lines {
864 if firstChar != nil {
865 if firstChar.realLoc.Y == realLineN {
868 realLineN = firstChar.realLoc.Y
873 colorcolumn := int(v.Buf.Settings["colorcolumn"].(float64))
874 if colorcolumn != 0 && xOffset+colorcolumn-v.leftCol < v.Width {
875 style := GetColor("color-column")
876 fg, _, _ := style.Decompose()
877 st := defStyle.Background(fg)
878 screen.SetContent(xOffset+colorcolumn-v.leftCol, yOffset+visualLineN, ' ', nil, st)
883 // If there are gutter messages we need to display the '>>' symbol here
884 if hasGutterMessages {
885 // msgOnLine stores whether or not there is a gutter message on this line in particular
887 for k := range v.messages {
888 for _, msg := range v.messages[k] {
889 if msg.lineNum == realLineN {
891 gutterStyle := defStyle
894 if style, ok := colorscheme["gutter-info"]; ok {
898 if style, ok := colorscheme["gutter-warning"]; ok {
902 if style, ok := colorscheme["gutter-error"]; ok {
906 screen.SetContent(screenX, yOffset+visualLineN, '>', nil, gutterStyle)
908 screen.SetContent(screenX, yOffset+visualLineN, '>', nil, gutterStyle)
910 if v.Cursor.Y == realLineN && !messenger.hasPrompt {
911 messenger.Message(msg.msg)
912 messenger.gutterMessage = true
917 // If there is no message on this line we just display an empty offset
919 screen.SetContent(screenX, yOffset+visualLineN, ' ', nil, defStyle)
921 screen.SetContent(screenX, yOffset+visualLineN, ' ', nil, defStyle)
923 if v.Cursor.Y == realLineN && messenger.gutterMessage {
925 messenger.gutterMessage = false
930 lineNumStyle := defStyle
931 if v.Buf.Settings["ruler"] == true {
932 // Write the line number
933 if style, ok := colorscheme["line-number"]; ok {
936 if style, ok := colorscheme["current-line-number"]; ok {
937 if realLineN == v.Cursor.Y && tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() {
942 lineNum := strconv.Itoa(realLineN + 1)
944 // Write the spaces before the line number if necessary
945 for i := 0; i < maxLineNumLength-len(lineNum); i++ {
946 screen.SetContent(screenX+divider, yOffset+visualLineN, ' ', nil, lineNumStyle)
949 if softwrapped && visualLineN != 0 {
950 // Pad without the line number because it was written on the visual line before
952 screen.SetContent(screenX+divider, yOffset+visualLineN, ' ', nil, lineNumStyle)
956 // Write the actual line number
957 for _, ch := range lineNum {
958 screen.SetContent(screenX+divider, yOffset+visualLineN, ch, nil, lineNumStyle)
963 // Write the extra space
964 screen.SetContent(screenX+divider, yOffset+visualLineN, ' ', nil, lineNumStyle)
970 for _, char := range line {
972 lineStyle := char.style
974 colorcolumn := int(v.Buf.Settings["colorcolumn"].(float64))
975 if colorcolumn != 0 && char.visualLoc.X == colorcolumn {
976 style := GetColor("color-column")
977 fg, _, _ := style.Decompose()
978 lineStyle = lineStyle.Background(fg)
981 charLoc := char.realLoc
982 for _, c := range v.Buf.cursors {
984 if v.Cursor.HasSelection() &&
985 (charLoc.GreaterEqual(v.Cursor.CurSelection[0]) && charLoc.LessThan(v.Cursor.CurSelection[1]) ||
986 charLoc.LessThan(v.Cursor.CurSelection[0]) && charLoc.GreaterEqual(v.Cursor.CurSelection[1])) {
987 // The current character is selected
988 lineStyle = defStyle.Reverse(true)
990 if style, ok := colorscheme["selection"]; ok {
995 v.SetCursor(&v.Buf.Cursor)
997 if v.Buf.Settings["cursorline"].(bool) && tabs[curTab].CurView == v.Num &&
998 !v.Cursor.HasSelection() && v.Cursor.Y == realLineN {
999 style := GetColor("cursor-line")
1000 fg, _, _ := style.Decompose()
1001 lineStyle = lineStyle.Background(fg)
1004 screen.SetContent(xOffset+char.visualLoc.X, yOffset+char.visualLoc.Y, char.drawChar, nil, lineStyle)
1006 for i, c := range v.Buf.cursors {
1008 if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
1009 v.Cursor.Y == char.realLoc.Y && v.Cursor.X == char.realLoc.X && (!cursorSet || i != 0) {
1010 ShowMultiCursor(xOffset+char.visualLoc.X, yOffset+char.visualLoc.Y, i)
1014 v.SetCursor(&v.Buf.Cursor)
1024 if lastChar != nil {
1025 lastX = xOffset + lastChar.visualLoc.X + lastChar.width
1026 for i, c := range v.Buf.cursors {
1028 if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
1029 v.Cursor.Y == lastChar.realLoc.Y && v.Cursor.X == lastChar.realLoc.X+1 {
1030 ShowMultiCursor(lastX, yOffset+lastChar.visualLoc.Y, i)
1031 cx, cy = lastX, yOffset+lastChar.visualLoc.Y
1034 v.SetCursor(&v.Buf.Cursor)
1035 realLoc = Loc{lastChar.realLoc.X + 1, realLineN}
1036 visualLoc = Loc{lastX - xOffset, lastChar.visualLoc.Y}
1037 } else if len(line) == 0 {
1038 for i, c := range v.Buf.cursors {
1040 if tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() &&
1041 v.Cursor.Y == realLineN {
1042 ShowMultiCursor(xOffset, yOffset+visualLineN, i)
1043 cx, cy = xOffset, yOffset+visualLineN
1046 v.SetCursor(&v.Buf.Cursor)
1048 realLoc = Loc{0, realLineN}
1049 visualLoc = Loc{0, visualLineN}
1052 if v.Cursor.HasSelection() &&
1053 (realLoc.GreaterEqual(v.Cursor.CurSelection[0]) && realLoc.LessThan(v.Cursor.CurSelection[1]) ||
1054 realLoc.LessThan(v.Cursor.CurSelection[0]) && realLoc.GreaterEqual(v.Cursor.CurSelection[1])) {
1055 // The current character is selected
1056 selectStyle := defStyle.Reverse(true)
1058 if style, ok := colorscheme["selection"]; ok {
1061 screen.SetContent(xOffset+visualLoc.X, yOffset+visualLoc.Y, ' ', nil, selectStyle)
1064 if v.Buf.Settings["cursorline"].(bool) && tabs[curTab].CurView == v.Num &&
1065 !v.Cursor.HasSelection() && v.Cursor.Y == realLineN {
1066 for i := lastX; i < xOffset+v.Width-v.lineNumOffset; i++ {
1067 style := GetColor("cursor-line")
1068 fg, _, _ := style.Decompose()
1069 style = style.Background(fg)
1070 if !(tabs[curTab].CurView == v.Num && !v.Cursor.HasSelection() && i == cx && yOffset+visualLineN == cy) {
1071 screen.SetContent(i, yOffset+visualLineN, ' ', nil, style)
1078 dividerStyle := defStyle
1079 if style, ok := colorscheme["divider"]; ok {
1080 dividerStyle = style
1082 for i := 0; i < v.Height; i++ {
1083 screen.SetContent(v.x, yOffset+i, '|', nil, dividerStyle.Reverse(true))
1088 // ShowMultiCursor will display a cursor at a location
1089 // If i == 0 then the terminal cursor will be used
1090 // Otherwise a fake cursor will be drawn at the position
1091 func ShowMultiCursor(x, y, i int) {
1093 screen.ShowCursor(x, y)
1095 r, _, _, _ := screen.GetContent(x, y)
1096 screen.SetContent(x, y, r, nil, defStyle.Reverse(true))
1100 // Display renders the view, the cursor, and statusline
1101 func (v *View) Display() {
1102 if globalSettings["termtitle"].(bool) {
1103 screen.SetTitle("micro: " + v.Buf.GetName())
1106 // Don't draw the cursor if it is out of the viewport or if it has a selection
1107 if v.Num == tabs[curTab].CurView && (v.Cursor.Y-v.Topline < 0 || v.Cursor.Y-v.Topline > v.Height-1 || v.Cursor.HasSelection()) {
1110 _, screenH := screen.Size()
1112 if v.Buf.Settings["scrollbar"].(bool) {
1113 v.scrollbar.Display()
1116 if v.Buf.Settings["statusline"].(bool) {
1118 } else if (v.y + v.Height) != screenH-1 {
1119 for x := 0; x < v.Width; x++ {
1120 screen.SetContent(v.x+x, v.y+v.Height, '-', nil, defStyle.Reverse(true))