plugins

package
v0.0.0-...-acee8aa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 16 Imported by: 0

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

func CommandBarTryPushMessage

func CommandBarTryPushMessage(e *editor.Editor, err error)

Types

type BattlePass

type BattlePass struct {
	Storage storage.PersistentStorage[BattlePassData]
}

func (*BattlePass) Draw

func (p *BattlePass) Draw(e *editor.Editor) error

func (*BattlePass) GetInfo

func (p *BattlePass) GetInfo() editor.PluginInfo

func (*BattlePass) Startup

func (p *BattlePass) Startup(e *editor.Editor) error

func (*BattlePass) Update

func (p *BattlePass) Update(e *editor.Editor, event tcell.Event) tcell.Event

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) Draw

func (p *CommandBar) Draw(e *editor.Editor) error

func (*CommandBar) GetInfo

func (p *CommandBar) GetInfo() editor.PluginInfo

func (*CommandBar) Startup

func (p *CommandBar) Startup(e *editor.Editor) error

func (*CommandBar) Update

func (p *CommandBar) Update(e *editor.Editor, event tcell.Event) tcell.Event

type InsertMode

type InsertMode struct{}

func (*InsertMode) Draw

func (p *InsertMode) Draw(e *editor.Editor) error

func (*InsertMode) GetInfo

func (p *InsertMode) GetInfo() editor.PluginInfo

func (*InsertMode) Startup

func (p *InsertMode) Startup(e *editor.Editor) error

func (*InsertMode) Update

func (p *InsertMode) Update(e *editor.Editor, event tcell.Event) tcell.Event

type StatusBar

type StatusBar struct {
}

func (*StatusBar) Draw

func (s *StatusBar) Draw(e *editor.Editor) error

func (*StatusBar) GetInfo

func (s *StatusBar) GetInfo() editor.PluginInfo

func (*StatusBar) Startup

func (s *StatusBar) Startup(e *editor.Editor) error

func (*StatusBar) Update

func (s *StatusBar) Update(e *editor.Editor, event tcell.Event) tcell.Event

type TestWindowsPlugin

type TestWindowsPlugin struct{}

func (*TestWindowsPlugin) Draw

func (p *TestWindowsPlugin) Draw(e *editor.Editor) error

func (*TestWindowsPlugin) GetInfo

func (p *TestWindowsPlugin) GetInfo() editor.PluginInfo

func (*TestWindowsPlugin) Startup

func (p *TestWindowsPlugin) Startup(e *editor.Editor) error

func (*TestWindowsPlugin) Update

func (p *TestWindowsPlugin) Update(e *editor.Editor, event tcell.Event) tcell.Event

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

func (*VisualMode) Startup

func (p *VisualMode) Startup(e *editor.Editor) error

func (*VisualMode) Update

func (p *VisualMode) Update(e *editor.Editor, event tcell.Event) tcell.Event

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL