From ef3f081347ac063737f3e6a055bde231f19f6259 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sun, 20 Jan 2019 23:45:42 -0500 Subject: [PATCH] Add colorcolumn --- cmd/micro/display/bufwindow.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/micro/display/bufwindow.go b/cmd/micro/display/bufwindow.go index 8d11ed5f..9e4e7659 100644 --- a/cmd/micro/display/bufwindow.go +++ b/cmd/micro/display/bufwindow.go @@ -1,6 +1,7 @@ package display import ( + "log" "strconv" "unicode/utf8" @@ -389,8 +390,9 @@ func (w *BufWindow) displayBuffer() { // so we can pad appropriately when displaying line numbers maxLineNumLength := len(strconv.Itoa(b.LinesNum())) - tabsize := int(b.Settings["tabsize"].(float64)) softwrap := b.Settings["softwrap"].(bool) + tabsize := util.IntOpt(b.Settings["tabsize"]) + colorcolumn := util.IntOpt(b.Settings["colorcolumn"]) // this represents the current draw position // within the current window @@ -451,6 +453,15 @@ func (w *BufWindow) displayBuffer() { } } + if s, ok := config.Colorscheme["color-column"]; ok { + log.Println(vloc.X - w.gutterOffset) + if colorcolumn != 0 && vloc.X-w.gutterOffset == colorcolumn { + log.Println("display colorcolumn") + fg, _, _ := s.Decompose() + style = style.Background(fg) + } + } + screen.Screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, r, nil, style) if showcursor { @@ -514,18 +525,25 @@ func (w *BufWindow) displayBuffer() { } } + style := config.DefStyle for _, c := range cursors { if b.Settings["cursorline"].(bool) && w.active && !c.HasSelection() && c.Y == bloc.Y { - style := config.DefStyle if s, ok := config.Colorscheme["cursor-line"]; ok { fg, _, _ := s.Decompose() style = style.Background(fg) } - for i := vloc.X; i < w.Width; i++ { - screen.Screen.SetContent(i+w.X, vloc.Y+w.Y, ' ', nil, style) + } + } + for i := vloc.X; i < w.Width; i++ { + curStyle := style + if s, ok := config.Colorscheme["color-column"]; ok { + if colorcolumn != 0 && i-w.gutterOffset == colorcolumn { + fg, _, _ := s.Decompose() + curStyle = style.Background(fg) } } + screen.Screen.SetContent(i+w.X, vloc.Y+w.Y, ' ', nil, curStyle) } for _, c := range cursors {