Documentation
¶
Index ¶
Constants ¶
View Source
const XpPerLevel = 1000
Variables ¶
View Source
var ( ErrWindowIsScratchpad = editor.FemtoError{Message: "cannot write, window is a scratchpad", LogLevel: slog.LevelWarn} ErrWindowIsReadonly = editor.FemtoError{Message: "cannot write, window is readonly", LogLevel: slog.LevelWarn} ErrFailedToCreateDirs = editor.FemtoError{Message: "failed to create directories", LogLevel: slog.LevelError} )
View Source
var Io = editor.DumbPlugin{ Info: editor.PluginInfo{ Id: "femto.io", Author: "femto", Name: "Input/Output", Description: "Adds basic commands for IO such as :w[rite]", }, Commands: map[string]editor.Command{ "write": { Name: "Write file", Func: func(e *editor.Editor, args ...string) error { win := e.Win() var path string if len(args) == 0 || args[0] == "" { if win.FilePath == "" { return ErrWindowIsScratchpad } path = win.FilePath } else { path = args[0] } dir := filepath.Dir(path) err := os.MkdirAll(dir, os.ModePerm) if err != nil { return ErrFailedToCreateDirs.Context(err.Error()) } b, err := e.Buf().Read1D() if err != nil { return err } err = os.WriteFile(path, []byte(string(b)), 0644) if err != nil { return err } e.Screen.PostEvent(&editor.CommandBarEvent{ Msg: fmt.Sprintf("wrote file %s", path), Time: time.Now(), }) return nil }, }, "w": editor.Alias("write"), "edit": { Name: "Opens specified file for editing in current file", Func: func(e *editor.Editor, args ...string) error { if len(args) == 0 || args[0] == "" { return editor.ErrArgumentMissing } path := args[0] b, err := os.ReadFile(path) if err != nil { slog.Warn(err.Error()) b = []byte{} e.Screen.PostEvent(&editor.CommandBarEvent{ Msg: fmt.Sprintf("file %s not found, will be created when writing", path), Time: time.Now(), }) } lines := strings.Split(string(b), "\n") rs := [][]rune{} for _, line := range lines { rs = append(rs, []rune(line)) } buf := buffer.SliceBuffer{} err = buf.Write(rs) if err != nil { return err } win := e.Tab().GetWindow("main") win.FilePath = path win.Buffer = &buf return nil }, }, "e": editor.Alias("edit"), }, }
View Source
var Movement = editor.DumbPlugin{ Info: editor.PluginInfo{ Id: "femto.movement", Author: "femto", Name: "Movement", }, Commands: map[string]editor.Command{ "left": { Func: func(e *editor.Editor, args ...string) error { e.Buf().Left(1) return nil }, }, "down": { Func: func(e *editor.Editor, args ...string) error { e.Buf().Down(1) return nil }, }, "up": { Func: func(e *editor.Editor, args ...string) error { e.Buf().Up(1) return nil }, }, "right": { Func: func(e *editor.Editor, args ...string) error { if e.Win().Mode == "insert" { e.Buf().ForceRight(1) } else { e.Buf().Right(1) } return nil }, }, "bigLeft": { Func: func(e *editor.Editor, args ...string) error { line := e.Buf().Line() x := 0 for ; x < len(line); x++ { if !unicode.IsSpace(line[x]) { break } } e.Buf().GoTo(femath.Vec2{X: x, Y: e.Buf().Pos().Y}) return nil }, }, "bigRight": { Func: func(e *editor.Editor, args ...string) error { e.Buf().GoTo(femath.Vec2{X: len(e.Buf().Line()), Y: e.Buf().Pos().Y}) return nil }, }, }, Keymap: map[string]map[string]string{ "normal": { "h": "left", "left": "left", "j": "down", "down": "down", "k": "up", "up": "up", "l": "right", "right": "right", "H": "bigLeft", "L": "bigRight", }, "insert": { "left": "left", "down": "down", "up": "up", "right": "right", }, }, }
View Source
var RosePine = editor.DumbPlugin{ Info: editor.PluginInfo{ Id: "femto.themes.rosepine", Author: "femto", Name: "Rose Pine", Description: "All natural pine, faux fur and a bit of soho vibes for the classy minimalist.", }, Themes: map[string]editor.Theme{ "rosepine.main": { Name: "Rose Pine (Main)", Default: tcell.StyleDefault.Background(tcell.NewHexColor(0x191724)).Foreground(tcell.NewHexColor(0xe0def4)), SelectionBG: tcell.NewHexColor(0x403d52), Borders: tcell.NewHexColor(0x524f67), Error: tcell.StyleDefault.Foreground(tcell.NewHexColor(0xeb6f92)), Warn: tcell.StyleDefault.Foreground(tcell.NewHexColor(0xf6c177)), Red: tcell.NewHexColor(0xeb6f92), Yellow: tcell.NewHexColor(0xf6c177), Pink: tcell.NewHexColor(0xebbcba), Blue: tcell.NewHexColor(0x31748f), LightBlue: tcell.NewHexColor(0x9ccfd8), Purple: tcell.NewHexColor(0xc4a7e7), Green: tcell.NewHexColor(0x31748f), NormalModeAccent: tcell.NewHexColor(0xc4a7e7), InsertModeAccent: tcell.NewHexColor(0xeb6f92), VisualModeAccent: tcell.NewHexColor(0x31748f), }, }, }
Functions ¶
Types ¶
type BattlePass ¶
type BattlePass struct {
Storage storage.PersistentStorage[BattlePassData]
}
func (*BattlePass) GetInfo ¶
func (p *BattlePass) GetInfo() editor.PluginInfo
type BattlePassData ¶
type BattlePassData struct {
Xp int
SelectedLanguages []string // eg .go, .rs, .py
CharsTyped map[string]int // gets reset everyday
CharsTypedObjectives map[string]int
}
func (BattlePassData) Level ¶
func (bp BattlePassData) Level() int
type CommandBar ¶
type CommandBar struct {
}
func (*CommandBar) GetInfo ¶
func (p *CommandBar) GetInfo() editor.PluginInfo
type InsertMode ¶
type InsertMode struct{}
func (*InsertMode) GetInfo ¶
func (p *InsertMode) GetInfo() editor.PluginInfo
type StatusBar ¶
type StatusBar struct {
}
func (*StatusBar) GetInfo ¶
func (s *StatusBar) GetInfo() editor.PluginInfo
type TestWindowsPlugin ¶
type TestWindowsPlugin struct{}
func (*TestWindowsPlugin) GetInfo ¶
func (p *TestWindowsPlugin) GetInfo() editor.PluginInfo
type VisualMode ¶
type VisualMode struct{}
func (*VisualMode) Draw ¶
func (p *VisualMode) Draw(e *editor.Editor) error
Looks weird, but since plugin update happens before editor update, the selection would be updated on the next frame, so we put it in Draw...
func (*VisualMode) GetInfo ¶
func (p *VisualMode) GetInfo() editor.PluginInfo
Click to show internal directories.
Click to hide internal directories.