editor

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package editor provides strategies for editing bookmarks through temporary files.

Index

Constants

View Source
const DefTextEditorEnv = "EDITOR"

Variables

View Source
var (
	ErrLineNotFound    = errors.New("line not found")
	ErrTagsEmpty       = errors.New("tags cannot be empty")
	ErrURLEmpty        = errors.New("URL cannot be empty")
	ErrBufferUnchanged = errors.New("buffer unchanged")
)
View Source
var (
	ErrCommandNotFound    = errors.New("command not found")
	ErrTextEditorNotFound = errors.New("text editor not found")
)

Functions

This section is empty.

Types

type BookmarkStrategy

type BookmarkStrategy struct {
	// contains filtered or unexported fields
}

BookmarkStrategy implements the Strategy interface for editing existing bookmarks.

func (BookmarkStrategy) BuildBuffer

func (BookmarkStrategy) BuildBuffer(m *Meta, b *Record, idx, total int) ([]byte, error)

func (BookmarkStrategy) Diff

func (BookmarkStrategy) Diff(oldB, newB *Record) string

func (BookmarkStrategy) ParseBuffer

func (BookmarkStrategy) ParseBuffer(
	ctx context.Context,
	buf []byte,
	original *Record,
	idx, total int,
) (*Record, error)

func (BookmarkStrategy) Save

func (BookmarkStrategy) Save(ctx context.Context, r *db.SQLite, bm *Record) error

type BufferBuilder

type BufferBuilder struct {
	Item   *bookmark.Bookmark
	Header []byte
	Body   []byte
	Footer []byte
	Idx    int
	Total  int
}

BufferBuilder holds information about a bookmark edit operation.

func NewBufferBuilder

func NewBufferBuilder(b *bookmark.Bookmark) *BufferBuilder

func (*BufferBuilder) Buffer

func (be *BufferBuilder) Buffer() []byte

type EditSession

type EditSession struct {
	Console *ui.Console
	Editor  *TextEditor
	DB      *db.SQLite
	// contains filtered or unexported fields
}

EditSession build -> edit -> parse -> confirm -> save.

func NewEditSession

func NewEditSession(c *ui.Console, r *db.SQLite, e *TextEditor, opts ...SessionOption) *EditSession

NewEditSession creates a new editing session.

func (*EditSession) Run

func (e *EditSession) Run(bs []*Record, strategy EditStrategy) error

Run processes records for editing using the specified strategy.

type EditStrategy

type EditStrategy interface {
	// Builds the buffer shown in the editor
	BuildBuffer(m *Meta, b *Record, idx, total int) ([]byte, error)

	// Parses buffer back into a bookmark
	ParseBuffer(ctx context.Context, buf []byte, original *Record, idx, total int) (*Record, error)

	// Compares old/new for diff display
	Diff(oldB, newB *Record) string

	// Saves changes (to repository)
	Save(ctx context.Context, db *db.SQLite, b *Record) error
}

func Strategy

func Strategy(cfg *config.Config) (strategy EditStrategy, filetype string)

Strategy returns the appropriate EditStrategy and filetype based on configuration flags.

type JSONStrategy

type JSONStrategy struct{}

func (JSONStrategy) BuildBuffer

func (JSONStrategy) BuildBuffer(m *Meta, b *Record, idx, total int) ([]byte, error)

func (JSONStrategy) Diff

func (JSONStrategy) Diff(oldB, newB *Record) string

func (JSONStrategy) ParseBuffer

func (JSONStrategy) ParseBuffer(ctx context.Context, buf []byte, original *Record, idx, total int) (*Record, error)

func (JSONStrategy) Save

func (JSONStrategy) Save(ctx context.Context, r *db.SQLite, bm *Record) error

type Meta

type Meta struct {
	DBName  string
	Version string
}

func NewMeta

func NewMeta() *Meta

type NewBookmarkStrategy

type NewBookmarkStrategy struct {
	// contains filtered or unexported fields
}

NewBookmarkStrategy implements the Strategy interface for creating new bookmarks.

func (NewBookmarkStrategy) BuildBuffer

func (NewBookmarkStrategy) BuildBuffer(m *Meta, b *Record, idx, total int) ([]byte, error)

func (NewBookmarkStrategy) Diff

func (NewBookmarkStrategy) Diff(oldB, newB *Record) string

func (NewBookmarkStrategy) ParseBuffer

func (NewBookmarkStrategy) ParseBuffer(
	ctx context.Context,
	buf []byte,
	original *Record,
	idx, total int,
) (*Record, error)

func (NewBookmarkStrategy) Save

type NotesStrategy

type NotesStrategy struct{}

func (NotesStrategy) BuildBuffer

func (NotesStrategy) BuildBuffer(m *Meta, b *Record, idx, total int) ([]byte, error)

func (NotesStrategy) Diff

func (NotesStrategy) Diff(oldB, newB *Record) string

func (NotesStrategy) ParseBuffer

func (NotesStrategy) ParseBuffer(ctx context.Context, buf []byte, original *Record, idx, total int) (*Record, error)

func (NotesStrategy) Save

func (NotesStrategy) Save(ctx context.Context, r *db.SQLite, bm *Record) error

type Record

type Record = bookmark.Bookmark

type SessionOption

type SessionOption func(*EditSession)

func WithContext

func WithContext(ctx context.Context) SessionOption

func WithFileType

func WithFileType(ft string) SessionOption

func WithMeta

func WithMeta(m *Meta) SessionOption

func WithPostEditionRunE

func WithPostEditionRunE(fn postRunEditionFunc) SessionOption

type TextEditor

type TextEditor struct {
	// contains filtered or unexported fields
}

func NewEditor

func NewEditor(s string) (*TextEditor, error)

NewEditor retrieves the preferred editor to use for editing

If env variable `GOMARKS_EDITOR` is not set, uses the `EDITOR`. If env variable `EDITOR` is not set, uses the first available `TextEditors`

fallbackEditors: `"vim", "nvim", "nano", "emacs"`.

func (*TextEditor) Bytes

func (te *TextEditor) Bytes(ctx context.Context, content []byte, extension string) ([]byte, error)

Bytes edits a byte slice with a text editor.

func (*TextEditor) EditFile

func (te *TextEditor) EditFile(ctx context.Context, p string) error

EditFile edits a file with a text editor.

Jump to

Keyboard shortcuts

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