package keymap
import (
"fmt"
"strings"
)
type CursorStyle string
func (c CursorStyle ) String () string {
cursor , found := cursors [c ]
if !found {
return string (cursorUserDefault )
}
return cursor
}
const (
cursorBlock CursorStyle = "block"
cursorUnderline CursorStyle = "underline"
cursorBeam CursorStyle = "beam"
cursorBlinkingBlock CursorStyle = "blinking-block"
cursorBlinkingUnderline CursorStyle = "blinking-underline"
cursorBlinkingBeam CursorStyle = "blinking-beam"
cursorUserDefault CursorStyle = "default"
)
var cursors = map [CursorStyle ]string {
cursorBlock : "\x1b[2 q" ,
cursorUnderline : "\x1b[4 q" ,
cursorBeam : "\x1b[6 q" ,
cursorBlinkingBlock : "\x1b[1 q" ,
cursorBlinkingUnderline : "\x1b[3 q" ,
cursorBlinkingBeam : "\x1b[5 q" ,
cursorUserDefault : "\x1b[0 q" ,
}
var defaultCursors = map [Mode ]CursorStyle {
ViInsert : cursorBlinkingBeam ,
Vi : cursorBlinkingBeam ,
ViCommand : cursorBlinkingBlock ,
ViOpp : cursorBlinkingUnderline ,
Visual : cursorBlock ,
Emacs : cursorBlinkingBlock ,
}
func (m *Engine ) PrintCursor (keymap Mode ) {
var cursor CursorStyle
cursorOptname := "cursor-" + string (keymap )
modeSet := strings .TrimSpace (m .config .GetString (cursorOptname ))
if _ , valid := cursors [CursorStyle (modeSet )]; valid {
fmt .Print (cursors [CursorStyle (modeSet )])
return
}
if defaultCur , valid := defaultCursors [keymap ]; valid {
fmt .Print (cursors [defaultCur ])
return
}
fmt .Print (cursors [cursor ])
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .