207 lines
5.0 KiB
Go
207 lines
5.0 KiB
Go
package editor
|
|
|
|
import (
|
|
"git.gophernest.net/azpect/TextEditor/internal/core"
|
|
"git.gophernest.net/azpect/TextEditor/internal/input"
|
|
"git.gophernest.net/azpect/TextEditor/internal/style"
|
|
"github.com/alecthomas/chroma/v2/styles"
|
|
)
|
|
|
|
type ModelBuilder struct {
|
|
model Model
|
|
}
|
|
|
|
// RPGLE
|
|
// abap
|
|
// algol
|
|
// algol_nu
|
|
// arduino
|
|
// ashen
|
|
// aura-theme-dark
|
|
// aura-theme-dark-soft
|
|
// autumn
|
|
// average
|
|
// base16-snazzy
|
|
// borland
|
|
// bw
|
|
// catppuccin-frappe
|
|
// catppuccin-latte
|
|
// catppuccin-macchiato
|
|
// catppuccin-mocha
|
|
// colorful
|
|
// doom-one
|
|
// doom-one2
|
|
// dracula
|
|
// emacs
|
|
// evergarden
|
|
// friendly
|
|
// fruity
|
|
// github
|
|
// github-dark
|
|
// gruvbox
|
|
// gruvbox-light
|
|
// hr_high_contrast
|
|
// hrdark
|
|
// igor
|
|
// lovelace
|
|
// manni
|
|
// modus-operandi
|
|
// modus-vivendi
|
|
// monokai
|
|
// monokailight
|
|
// murphy
|
|
// native
|
|
// nord
|
|
// nordic
|
|
// onedark
|
|
// onesenterprise
|
|
// paraiso-dark
|
|
// paraiso-light
|
|
// pastie
|
|
// perldoc
|
|
// pygments
|
|
// rainbow_dash
|
|
// rose-pine
|
|
// rose-pine-dawn
|
|
// rose-pine-moon
|
|
// rrt
|
|
// solarized-dark
|
|
// solarized-dark256
|
|
// solarized-light
|
|
// swapoff
|
|
// tango
|
|
// tokyonight-day
|
|
// tokyonight-moon
|
|
// tokyonight-night
|
|
// tokyonight-storm
|
|
// trac
|
|
// vim
|
|
// vs
|
|
// vulcan
|
|
// witchhazel
|
|
// xcode
|
|
// xcode-dark
|
|
func NewModelBuilder() *ModelBuilder {
|
|
chromaStyle := styles.Get("kanagawa-wave")
|
|
|
|
return &ModelBuilder{
|
|
model: Model{
|
|
buffers: []*core.Buffer{},
|
|
windows: []*core.Window{},
|
|
activeWindowId: -1,
|
|
mode: core.NormalMode,
|
|
termWidth: 0,
|
|
termHeight: 0,
|
|
input: input.NewHandler(),
|
|
insertCount: 0,
|
|
insertKeys: []string{},
|
|
insertAction: nil,
|
|
command: "",
|
|
commandCursor: 0,
|
|
commandOutput: nil,
|
|
settings: core.NewDefaultSettings(),
|
|
registers: core.DefaultRegisters(),
|
|
styles: style.ChromaStyles(chromaStyle),
|
|
},
|
|
}
|
|
}
|
|
|
|
// ModelBuilder.WithBuffers: Set the buffers for the model. Buffers represent
|
|
// the in-memory text content of files being edited.
|
|
func (mb *ModelBuilder) WithBuffers(buffers []*core.Buffer) *ModelBuilder {
|
|
mb.model.buffers = buffers
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.AddBuffer: Add a single buffer to the model's buffer list.
|
|
func (mb *ModelBuilder) AddBuffer(buffer *core.Buffer) *ModelBuilder {
|
|
mb.model.buffers = append(mb.model.buffers, buffer)
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithWindows: Set the windows for the model. Windows are viewports
|
|
// that display buffer content with their own cursor position and scroll state.
|
|
func (mb *ModelBuilder) WithWindows(windows []*core.Window) *ModelBuilder {
|
|
mb.model.windows = windows
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.AddWindow: Add a single window to the model's window list.
|
|
func (mb *ModelBuilder) AddWindow(window *core.Window) *ModelBuilder {
|
|
mb.model.windows = append(mb.model.windows, window)
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithActiveWindowId: Set the ID of the currently active window.
|
|
// This determines which window receives input and displays the cursor.
|
|
func (mb *ModelBuilder) WithActiveWindowId(id int) *ModelBuilder {
|
|
mb.model.activeWindowId = id
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithMode: Set the editor mode (Normal, Insert, Visual, etc).
|
|
func (mb *ModelBuilder) WithMode(mode core.Mode) *ModelBuilder {
|
|
mb.model.mode = mode
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithTermSize: Set the terminal dimensions in columns and rows.
|
|
func (mb *ModelBuilder) WithTermSize(width, height int) *ModelBuilder {
|
|
mb.model.termWidth = width
|
|
mb.model.termHeight = height
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithTermWidth: Set the terminal width in columns.
|
|
func (mb *ModelBuilder) WithTermWidth(width int) *ModelBuilder {
|
|
mb.model.termWidth = width
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithTermHeight: Set the terminal height in rows.
|
|
func (mb *ModelBuilder) WithTermHeight(height int) *ModelBuilder {
|
|
mb.model.termHeight = height
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithSettings: Set the editor settings (tabstop, scrolloff, etc).
|
|
func (mb *ModelBuilder) WithSettings(settings core.EditorSettings) *ModelBuilder {
|
|
mb.model.settings = settings
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithRegisters: Set the register map for yank/delete/paste operations.
|
|
func (mb *ModelBuilder) WithRegisters(registers map[rune]core.Register) *ModelBuilder {
|
|
mb.model.registers = registers
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithCommand: Set the command line text.
|
|
func (mb *ModelBuilder) WithCommand(command string) *ModelBuilder {
|
|
mb.model.command = command
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithCommandCursor: Set the cursor position in the command line.
|
|
func (mb *ModelBuilder) WithCommandCursor(cursor int) *ModelBuilder {
|
|
mb.model.commandCursor = cursor
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithCommandOutput: Set the command line output.
|
|
func (mb *ModelBuilder) WithCommandOutput(out *core.CommandOutput) *ModelBuilder {
|
|
mb.model.commandOutput = out
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.WithStyles: Set the visual styling for the editor.
|
|
func (mb *ModelBuilder) WithStyles(styles style.Styles) *ModelBuilder {
|
|
mb.model.styles = styles
|
|
return mb
|
|
}
|
|
|
|
// ModelBuilder.Build: Build and return the configured Model instance.
|
|
func (mb *ModelBuilder) Build() *Model {
|
|
return &mb.model
|
|
}
|