Documentation
¶
Overview ¶
Package editor provides strategies for editing bookmarks through temporary files.
Index ¶
- Constants
- Variables
- type BookmarkStrategy
- func (BookmarkStrategy) BuildBuffer(m *Meta, b *Record, idx, total int) ([]byte, error)
- func (BookmarkStrategy) Diff(oldB, newB *Record) string
- func (BookmarkStrategy) ParseBuffer(ctx context.Context, buf []byte, original *Record, idx, total int) (*Record, error)
- func (BookmarkStrategy) Save(ctx context.Context, r *db.SQLite, bm *Record) error
- type BufferBuilder
- type EditSession
- type EditStrategy
- type JSONStrategy
- func (JSONStrategy) BuildBuffer(m *Meta, b *Record, idx, total int) ([]byte, error)
- func (JSONStrategy) Diff(oldB, newB *Record) string
- func (JSONStrategy) ParseBuffer(ctx context.Context, buf []byte, original *Record, idx, total int) (*Record, error)
- func (JSONStrategy) Save(ctx context.Context, r *db.SQLite, bm *Record) error
- type Meta
- type NewBookmarkStrategy
- func (NewBookmarkStrategy) BuildBuffer(m *Meta, b *Record, idx, total int) ([]byte, error)
- func (NewBookmarkStrategy) Diff(oldB, newB *Record) string
- func (NewBookmarkStrategy) ParseBuffer(ctx context.Context, buf []byte, original *Record, idx, total int) (*Record, error)
- func (NewBookmarkStrategy) Save(ctx context.Context, r *db.SQLite, bm *Record) error
- type NotesStrategy
- func (NotesStrategy) BuildBuffer(m *Meta, b *Record, idx, total int) ([]byte, error)
- func (NotesStrategy) Diff(oldB, newB *Record) string
- func (NotesStrategy) ParseBuffer(ctx context.Context, buf []byte, original *Record, idx, total int) (*Record, error)
- func (NotesStrategy) Save(ctx context.Context, r *db.SQLite, bm *Record) error
- type Record
- type SessionOption
- type TextEditor
Constants ¶
const DefTextEditorEnv = "EDITOR"
Variables ¶
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") )
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) ParseBuffer ¶
type BufferBuilder ¶
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
}
type JSONStrategy ¶
type JSONStrategy struct{}
func (JSONStrategy) BuildBuffer ¶
func (JSONStrategy) Diff ¶
func (JSONStrategy) Diff(oldB, newB *Record) string
func (JSONStrategy) ParseBuffer ¶
type NewBookmarkStrategy ¶
type NewBookmarkStrategy struct {
// contains filtered or unexported fields
}
NewBookmarkStrategy implements the Strategy interface for creating new bookmarks.
func (NewBookmarkStrategy) BuildBuffer ¶
func (NewBookmarkStrategy) ParseBuffer ¶
type NotesStrategy ¶
type NotesStrategy struct{}
func (NotesStrategy) BuildBuffer ¶
func (NotesStrategy) Diff ¶
func (NotesStrategy) Diff(oldB, newB *Record) string
func (NotesStrategy) ParseBuffer ¶
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`