From cdfea45a497cc743a07838141aad646e803ed09e Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Thu, 9 Jun 2016 16:00:43 -0400 Subject: [PATCH] Fix cursor line in true color colorschemes Ref #171 --- cmd/micro/colorscheme.go | 2 +- cmd/micro/highlighter.go | 14 ++++++++++++++ cmd/micro/micro.go | 11 ----------- cmd/micro/view.go | 16 ++++++++-------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/cmd/micro/colorscheme.go b/cmd/micro/colorscheme.go index 5abfb030..6621dd95 100644 --- a/cmd/micro/colorscheme.go +++ b/cmd/micro/colorscheme.go @@ -100,7 +100,7 @@ func StringToStyle(str string) tcell.Style { fg = strings.TrimSpace(fg) bg = strings.TrimSpace(bg) - style := tcell.StyleDefault.Foreground(StringToColor(fg)).Background(StringToColor(bg)) + style := defStyle.Foreground(StringToColor(fg)).Background(StringToColor(bg)) if strings.Contains(str, "bold") { style = style.Bold(true) } diff --git a/cmd/micro/highlighter.go b/cmd/micro/highlighter.go index 956de1d7..63e6bc08 100644 --- a/cmd/micro/highlighter.go +++ b/cmd/micro/highlighter.go @@ -140,6 +140,17 @@ func LoadSyntaxFiles() { func LoadSyntaxFilesFromDir(dir string) { InitColorscheme() + // Default style + defStyle = tcell.StyleDefault. + Foreground(tcell.ColorDefault). + Background(tcell.ColorDefault) + + // There may be another default style defined in the colorscheme + // In that case we should use that one + if style, ok := colorscheme["default"]; ok { + defStyle = style + } + syntaxFiles = make(map[[2]*regexp.Regexp]FileTypeRules) files, _ := ioutil.ReadDir(dir) for _, f := range files { @@ -395,6 +406,9 @@ func Match(v *View) SyntaxMatches { for i, line := range lines { matches[i] = make([]tcell.Style, len(line)+1) + for j, _ := range matches[i] { + matches[i][j] = defStyle + } } // We don't actually check the entire buffer, just from synLinesUp to synLinesDown diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 0523ff7c..5598ebcc 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -163,17 +163,6 @@ func InitScreen() { os.Setenv("TERM", oldTerm) } - // Default style - defStyle = tcell.StyleDefault. - Foreground(tcell.ColorDefault). - Background(tcell.ColorDefault) - - // There may be another default style defined in the colorscheme - // In that case we should use that one - if style, ok := colorscheme["default"]; ok { - defStyle = style - } - screen.SetStyle(defStyle) screen.EnableMouse() } diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 8e60c636..644c5d18 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -464,7 +464,7 @@ func (v *View) DisplayView() { } else { v.lineNumOffset = 0 } - var highlightStyle tcell.Style + highlightStyle := defStyle var hasGutterMessages bool for _, v := range v.messages { @@ -495,7 +495,7 @@ func (v *View) DisplayView() { for _, msg := range v.messages[k] { if msg.lineNum == lineN+v.Topline { msgOnLine = true - gutterStyle := tcell.StyleDefault + gutterStyle := defStyle switch msg.kind { case GutterInfo: if style, ok := colorscheme["gutter-info"]; ok { @@ -522,9 +522,9 @@ func (v *View) DisplayView() { } } if !msgOnLine { - screen.SetContent(x, lineN+v.y, ' ', nil, tcell.StyleDefault) + screen.SetContent(x, lineN+v.y, ' ', nil, defStyle) x++ - screen.SetContent(x, lineN+v.y, ' ', nil, tcell.StyleDefault) + screen.SetContent(x, lineN+v.y, ' ', nil, defStyle) x++ if v.Cursor.Y == lineN+v.Topline && messenger.gutterMessage { messenger.Reset() @@ -560,7 +560,7 @@ func (v *View) DisplayView() { } // Write the line for colN, ch := range line { - var lineStyle tcell.Style + lineStyle := defStyle if settings["syntax"].(bool) { // Syntax highlighting is enabled @@ -571,7 +571,7 @@ func (v *View) DisplayView() { (charNum.GreaterEqual(v.Cursor.CurSelection[0]) && charNum.LessThan(v.Cursor.CurSelection[1]) || charNum.LessThan(v.Cursor.CurSelection[0]) && charNum.GreaterEqual(v.Cursor.CurSelection[1])) { - lineStyle = tcell.StyleDefault.Reverse(true) + lineStyle = defStyle.Reverse(true) if style, ok := colorscheme["selection"]; ok { lineStyle = style @@ -596,7 +596,7 @@ func (v *View) DisplayView() { (charNum.GreaterEqual(v.Cursor.CurSelection[0]) && charNum.LessThan(v.Cursor.CurSelection[1]) || charNum.LessThan(v.Cursor.CurSelection[0]) && charNum.GreaterEqual(v.Cursor.CurSelection[1])) { - lineIndentStyle = tcell.StyleDefault.Reverse(true) + lineIndentStyle = defStyle.Reverse(true) if style, ok := colorscheme["selection"]; ok { lineIndentStyle = style @@ -657,7 +657,7 @@ func (v *View) DisplayView() { charNum = charNum.Move(1, v.Buf) for i := 0; i < v.width-(x-v.leftCol); i++ { - lineStyle := tcell.StyleDefault + lineStyle := defStyle if settings["cursorline"].(bool) && !v.Cursor.HasSelection() && v.Cursor.Y == lineN+v.Topline { if style, ok := colorscheme["cursor-line"]; ok { fg, _, _ := style.Decompose()