]> git.lizzy.rs Git - micro.git/blobdiff - internal/display/statusline.go
Add scrollbar color group (#1840)
[micro.git] / internal / display / statusline.go
index e4a6a1de72162da1192e2ed5517f50e02ca38058..5c5f551280d1e4b972979b4c1eb3c255a666cbd9 100644 (file)
@@ -3,21 +3,19 @@ package display
 import (
        "bytes"
        "fmt"
-       "path"
        "regexp"
        "strconv"
        "strings"
-       "unicode/utf8"
 
        luar "layeh.com/gopher-luar"
 
        runewidth "github.com/mattn/go-runewidth"
        lua "github.com/yuin/gopher-lua"
-       "github.com/zyedidia/micro/internal/buffer"
-       "github.com/zyedidia/micro/internal/config"
-       ulua "github.com/zyedidia/micro/internal/lua"
-       "github.com/zyedidia/micro/internal/screen"
-       "github.com/zyedidia/micro/internal/util"
+       "github.com/zyedidia/micro/v2/internal/buffer"
+       "github.com/zyedidia/micro/v2/internal/config"
+       ulua "github.com/zyedidia/micro/v2/internal/lua"
+       "github.com/zyedidia/micro/v2/internal/screen"
+       "github.com/zyedidia/micro/v2/internal/util"
 )
 
 // StatusLine represents the information line at the bottom
@@ -32,9 +30,6 @@ type StatusLine struct {
 
 var statusInfo = map[string]func(*buffer.Buffer) string{
        "filename": func(b *buffer.Buffer) string {
-               if b.Settings["basename"].(bool) {
-                       return path.Base(b.GetName())
-               }
                return b.GetName()
        },
        "line": func(b *buffer.Buffer) string {
@@ -47,21 +42,24 @@ var statusInfo = map[string]func(*buffer.Buffer) string{
                if b.Modified() {
                        return "+ "
                }
+               if b.Type.Readonly {
+                       return "[ro] "
+               }
                return ""
        },
 }
 
-func SetStatusInfoFnLua(s string, fn string) {
+func SetStatusInfoFnLua(fn string) {
        luaFn := strings.Split(fn, ".")
+       if len(luaFn) <= 1 {
+               return
+       }
        plName, plFn := luaFn[0], luaFn[1]
-       var pl *config.Plugin
-       for _, p := range config.Plugins {
-               if p.Name == plName {
-                       pl = p
-                       break
-               }
+       pl := config.FindPlugin(plName)
+       if pl == nil {
+               return
        }
-       statusInfo[s] = func(b *buffer.Buffer) string {
+       statusInfo[fn] = func(b *buffer.Buffer) string {
                if pl == nil || !pl.IsEnabled() {
                        return ""
                }
@@ -78,8 +76,6 @@ func SetStatusInfoFnLua(s string, fn string) {
        }
 }
 
-// TODO: plugin modify status line formatter
-
 // NewStatusLine returns a statusline bound to a window
 func NewStatusLine(win *BufWindow) *StatusLine {
        s := new(StatusLine)
@@ -120,13 +116,13 @@ func (s *StatusLine) Display() {
                                style = style.Reverse(true)
                        }
                        for _, r := range sug {
-                               screen.Screen.SetContent(x, y-keymenuOffset, r, nil, style)
+                               screen.SetContent(x, y-keymenuOffset, r, nil, style)
                                x++
                                if x >= s.win.Width {
                                        return
                                }
                        }
-                       screen.Screen.SetContent(x, y-keymenuOffset, ' ', nil, statusLineStyle)
+                       screen.SetContent(x, y-keymenuOffset, ' ', nil, statusLineStyle)
                        x++
                        if x >= s.win.Width {
                                return
@@ -134,7 +130,7 @@ func (s *StatusLine) Display() {
                }
 
                for x < s.win.Width {
-                       screen.Screen.SetContent(x, y-keymenuOffset, ' ', nil, statusLineStyle)
+                       screen.SetContent(x, y-keymenuOffset, ' ', nil, statusLineStyle)
                        x++
                }
                return
@@ -171,37 +167,39 @@ func (s *StatusLine) Display() {
                statusLineStyle = style
        }
 
-       leftLen := util.StringWidth(leftText, utf8.RuneCount(leftText), 1)
-       rightLen := util.StringWidth(rightText, utf8.RuneCount(rightText), 1)
+       leftLen := util.StringWidth(leftText, util.CharacterCount(leftText), 1)
+       rightLen := util.StringWidth(rightText, util.CharacterCount(rightText), 1)
 
        winX := s.win.X
        for x := 0; x < s.win.Width; x++ {
                if x < leftLen {
-                       r, size := utf8.DecodeRune(leftText)
+                       r, combc, size := util.DecodeCharacter(leftText)
                        leftText = leftText[size:]
                        rw := runewidth.RuneWidth(r)
                        for j := 0; j < rw; j++ {
                                c := r
                                if j > 0 {
                                        c = ' '
+                                       combc = nil
                                        x++
                                }
-                               screen.Screen.SetContent(winX+x, y, c, nil, statusLineStyle)
+                               screen.SetContent(winX+x, y, c, combc, statusLineStyle)
                        }
                } else if x >= s.win.Width-rightLen && x < rightLen+s.win.Width-rightLen {
-                       r, size := utf8.DecodeRune(rightText)
+                       r, combc, size := util.DecodeCharacter(rightText)
                        rightText = rightText[size:]
                        rw := runewidth.RuneWidth(r)
                        for j := 0; j < rw; j++ {
                                c := r
                                if j > 0 {
                                        c = ' '
+                                       combc = nil
                                        x++
                                }
-                               screen.Screen.SetContent(winX+x, y, c, nil, statusLineStyle)
+                               screen.SetContent(winX+x, y, c, combc, statusLineStyle)
                        }
                } else {
-                       screen.Screen.SetContent(winX+x, y, ' ', nil, statusLineStyle)
+                       screen.SetContent(winX+x, y, ' ', nil, statusLineStyle)
                }
        }
 }