126 lines
3.3 KiB
Go
126 lines
3.3 KiB
Go
package editor
|
|
|
|
import (
|
|
"git.gophernest.net/azpect/TextEditor/internal/action"
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
// Styles holds all the visual styling for the editor.
|
|
// Passed to Window.View() so windows can render themselves.
|
|
type Styles struct {
|
|
// Cursor styles by mode
|
|
CursorNormal lipgloss.Style
|
|
CursorInsert lipgloss.Style
|
|
CursorCommand lipgloss.Style
|
|
|
|
// Gutter (line numbers)
|
|
Gutter lipgloss.Style
|
|
GutterCurrentLine lipgloss.Style
|
|
|
|
// Visual mode
|
|
VisualHighlight lipgloss.Style
|
|
VisualAnchor lipgloss.Style // debugging
|
|
|
|
// Status bar
|
|
StatusBar lipgloss.Style
|
|
StatusBarActive lipgloss.Style
|
|
|
|
// Command line
|
|
CommandError lipgloss.Style
|
|
}
|
|
|
|
// DefaultStyles returns the default editor color scheme.
|
|
func DefaultStyles() Styles {
|
|
return Styles{
|
|
CursorNormal: lipgloss.NewStyle().Reverse(true),
|
|
CursorInsert: lipgloss.NewStyle().Underline(true),
|
|
CursorCommand: lipgloss.NewStyle().Reverse(true),
|
|
|
|
Gutter: lipgloss.NewStyle().
|
|
Background(lipgloss.Color("236")).
|
|
Foreground(lipgloss.Color("243")),
|
|
|
|
GutterCurrentLine: lipgloss.NewStyle().
|
|
Background(lipgloss.Color("236")).
|
|
Foreground(lipgloss.Color("#d69d00")),
|
|
|
|
VisualHighlight: lipgloss.NewStyle().
|
|
Background(lipgloss.Color("#7a6a00")),
|
|
|
|
VisualAnchor: lipgloss.NewStyle().
|
|
Background(lipgloss.Color("#a89020")),
|
|
|
|
StatusBar: lipgloss.NewStyle().
|
|
Background(lipgloss.Color("236")).
|
|
Foreground(lipgloss.Color("243")),
|
|
|
|
StatusBarActive: lipgloss.NewStyle().
|
|
Background(lipgloss.Color("62")).
|
|
Foreground(lipgloss.Color("230")),
|
|
|
|
CommandError: lipgloss.NewStyle().
|
|
Foreground(lipgloss.Color("#e3203a")),
|
|
}
|
|
}
|
|
|
|
// CursorStyle returns the appropriate cursor style for the given mode.
|
|
func (s Styles) CursorStyle(mode action.Mode) lipgloss.Style {
|
|
switch mode {
|
|
case action.InsertMode:
|
|
return s.CursorInsert
|
|
case action.CommandMode:
|
|
return s.CursorCommand
|
|
default:
|
|
return s.CursorNormal
|
|
}
|
|
}
|
|
|
|
// ==================================================
|
|
// Deprecated
|
|
// ==================================================
|
|
// func (m Model) cursorStyle() lipgloss.Style {
|
|
// switch m.mode {
|
|
// case action.NormalMode,
|
|
// action.VisualMode,
|
|
// action.VisualBlockMode,
|
|
// action.VisualLineMode:
|
|
// // Block cursor for normal mode
|
|
// return lipgloss.NewStyle().Reverse(true)
|
|
// case action.InsertMode:
|
|
// // Bar/underline for insert mode
|
|
// return lipgloss.NewStyle().Underline(true)
|
|
// case action.CommandMode:
|
|
// return lipgloss.NewStyle().Reverse(true)
|
|
// default:
|
|
// return lipgloss.NewStyle().Reverse(true)
|
|
// }
|
|
// }
|
|
//
|
|
// // DEBUGGING STYLE
|
|
// func (m Model) visualAnchorStyle() lipgloss.Style {
|
|
// bg := lipgloss.Color("#a89020")
|
|
// return lipgloss.NewStyle().Background(bg)
|
|
// }
|
|
//
|
|
// func (m Model) gutterStyle(currentLine bool) lipgloss.Style {
|
|
// bg := lipgloss.Color("236")
|
|
// fg := lipgloss.Color("243")
|
|
// if currentLine {
|
|
// fg = lipgloss.Color("#d69d00")
|
|
// }
|
|
// return lipgloss.NewStyle().
|
|
// Width(m.Settings().GutterSize).
|
|
// Background(bg).
|
|
// Foreground(fg)
|
|
// }
|
|
//
|
|
// func (m Model) visualHighlightStyle() lipgloss.Style {
|
|
// bg := lipgloss.Color("#7a6a00")
|
|
// return lipgloss.NewStyle().Background(bg)
|
|
// }
|
|
//
|
|
// func (m Model) commandErrorStyle() lipgloss.Style {
|
|
// fg := lipgloss.Color("#e3203a")
|
|
// return lipgloss.NewStyle().Foreground(fg)
|
|
// }
|