diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index ccbe2d98..0b4391ae 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -1,7 +1,6 @@ package display import ( - "runtime" "strconv" "unicode/utf8" @@ -340,11 +339,10 @@ func (w *BufWindow) getStyle(style tcell.Style, bloc buffer.Loc, r rune) (tcell. func (w *BufWindow) showCursor(x, y int, main bool) { if w.active { - if main && runtime.GOOS != "windows" { - screen.Screen.ShowCursor(x, y) + if main { + screen.ShowCursor(x, y) } else { - r, _, _, _ := screen.Screen.GetContent(x, y) - screen.Screen.SetContent(x, y, r, nil, config.DefStyle.Reverse(true)) + screen.ShowFakeCursor(x, y) } } } @@ -596,13 +594,7 @@ func (w *BufWindow) displayBuffer() { screen.Screen.SetContent(i+w.X, vloc.Y+w.Y, ' ', nil, curStyle) } - for _, c := range cursors { - if c.X == bloc.X && c.Y == bloc.Y && !c.HasSelection() { - w.showCursor(w.X+vloc.X, w.Y+vloc.Y, c.Num == 0) - } - } - - draw(' ', curStyle, false) + draw(' ', curStyle, true) bloc.X = w.StartCol bloc.Y++ diff --git a/internal/display/infowindow.go b/internal/display/infowindow.go index b179c81e..45dc2c65 100644 --- a/internal/display/infowindow.go +++ b/internal/display/infowindow.go @@ -121,7 +121,7 @@ func (i *InfoWindow) displayBuffer() { totalwidth := blocX - nColsBeforeStart for len(line) > 0 { if activeC.X == blocX { - screen.Screen.ShowCursor(vlocX, i.Y) + screen.ShowCursor(vlocX, i.Y) } r, size := utf8.DecodeRune(line) @@ -155,7 +155,7 @@ func (i *InfoWindow) displayBuffer() { } } if activeC.X == blocX { - screen.Screen.ShowCursor(vlocX, i.Y) + screen.ShowCursor(vlocX, i.Y) } } diff --git a/internal/display/termwindow.go b/internal/display/termwindow.go index 95a90037..23ae1dbe 100644 --- a/internal/display/termwindow.go +++ b/internal/display/termwindow.go @@ -111,6 +111,6 @@ func (w *TermWindow) Display() { } if w.State.CursorVisible() && w.active { curx, cury := w.State.Cursor() - screen.Screen.ShowCursor(curx+w.X, cury+w.Y) + screen.ShowCursor(curx+w.X, cury+w.Y) } } diff --git a/internal/screen/screen.go b/internal/screen/screen.go index ec3fbdd0..cca9036d 100644 --- a/internal/screen/screen.go +++ b/internal/screen/screen.go @@ -6,6 +6,7 @@ import ( "sync" "github.com/zyedidia/micro/internal/config" + "github.com/zyedidia/micro/internal/util" "github.com/zyedidia/tcell" ) @@ -31,6 +32,19 @@ func Redraw() { DrawChan <- true } +func ShowFakeCursor(x, y int) { + r, _, _, _ := Screen.GetContent(x, y) + Screen.SetContent(x, y, r, nil, config.DefStyle.Reverse(true)) +} + +func ShowCursor(x, y int) { + if util.FakeCursor { + ShowFakeCursor(x, y) + } else { + Screen.ShowCursor(x, y) + } +} + // TempFini shuts the screen down temporarily func TempFini() bool { screenWasNil := Screen == nil diff --git a/internal/util/util.go b/internal/util/util.go index 92af3bce..9bc3f7e1 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -7,6 +7,7 @@ import ( "os/user" "path/filepath" "regexp" + "runtime" "strconv" "strings" "time" @@ -30,6 +31,9 @@ var ( CompileDate = "Unknown" // Debug logging Debug = "ON" + // FakeCursor is used to disable the terminal cursor and have micro + // draw its own (enabled for windows consoles where the cursor is slow) + FakeCursor = true ) func init() { @@ -38,6 +42,10 @@ func init() { if err != nil { fmt.Println("Invalid version: ", Version, err) } + + if runtime.GOOS == "windows" { + FakeCursor = true + } } // SliceEnd returns a byte slice where the index is a rune index