service

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package service contains clipboard domain services and business logic.

Package service implements clipboard domain services and business logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClipboardHistory

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

ClipboardHistory is a domain service that manages clipboard history. It maintains a FIFO list of clipboard entries with configurable size and age limits.

func NewClipboardHistory

func NewClipboardHistory(maxSize int, maxAge time.Duration) *ClipboardHistory

NewClipboardHistory creates a new clipboard history service. maxSize sets the maximum number of entries (0 = unlimited). maxAge sets the maximum age of entries (0 = no expiration).

func (*ClipboardHistory) Add

func (h *ClipboardHistory) Add(content []byte, mimeType value.MIMEType) error

Add adds a new entry to the history. If maxSize is exceeded, the oldest entry is removed (FIFO). Returns the created entry or an error.

func (*ClipboardHistory) Clear

func (h *ClipboardHistory) Clear()

Clear removes all entries from the history.

func (*ClipboardHistory) Contains

func (h *ClipboardHistory) Contains(id string) bool

Contains checks if an entry with the given ID exists.

func (*ClipboardHistory) Get

Get returns the entry with the given ID. Returns an error if the entry is not found.

func (*ClipboardHistory) GetAll

func (h *ClipboardHistory) GetAll() []*model.HistoryEntry

GetAll returns all entries sorted by timestamp (newest first).

func (*ClipboardHistory) GetByMIMEType

func (h *ClipboardHistory) GetByMIMEType(mimeType value.MIMEType) []*model.HistoryEntry

GetByMIMEType returns all entries matching the given MIME type. Results are sorted by timestamp (newest first).

func (*ClipboardHistory) GetRecent

func (h *ClipboardHistory) GetRecent(count int) []*model.HistoryEntry

GetRecent returns the N most recent entries. If count is 0 or negative, returns all entries. If count exceeds available entries, returns all entries.

func (*ClipboardHistory) IsEmpty

func (h *ClipboardHistory) IsEmpty() bool

IsEmpty returns true if there are no entries in the history.

func (*ClipboardHistory) MaxAge

func (h *ClipboardHistory) MaxAge() time.Duration

MaxAge returns the maximum age of entries. Returns 0 if no expiration.

func (*ClipboardHistory) MaxSize

func (h *ClipboardHistory) MaxSize() int

MaxSize returns the maximum number of entries allowed. Returns 0 if unlimited.

func (*ClipboardHistory) RemoveExpired

func (h *ClipboardHistory) RemoveExpired() int

RemoveExpired removes all entries older than maxAge. If maxAge is 0 or negative, no entries are removed. Returns the number of entries removed.

func (*ClipboardHistory) SetMaxAge

func (h *ClipboardHistory) SetMaxAge(maxAge time.Duration)

SetMaxAge updates the maximum age of entries. Does not automatically remove expired entries - call RemoveExpired() to clean up.

func (*ClipboardHistory) SetMaxSize

func (h *ClipboardHistory) SetMaxSize(maxSize int)

SetMaxSize updates the maximum number of entries. If the new size is smaller than the current size, oldest entries are removed.

func (*ClipboardHistory) Size

func (h *ClipboardHistory) Size() int

Size returns the number of entries in the history.

func (*ClipboardHistory) TotalSize

func (h *ClipboardHistory) TotalSize() int

TotalSize returns the total memory usage of all entries in bytes.

type ClipboardService

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

ClipboardService provides domain logic for clipboard operations.

func NewClipboardService

func NewClipboardService(providers []Provider) (*ClipboardService, error)

NewClipboardService creates a new clipboard service with a prioritized list of providers.

func (*ClipboardService) GetAvailableProviderName

func (s *ClipboardService) GetAvailableProviderName() string

GetAvailableProviderName returns the name of the first available provider.

func (*ClipboardService) IsAvailable

func (s *ClipboardService) IsAvailable() bool

IsAvailable returns true if any provider is available.

func (*ClipboardService) Read

Read reads content from the first available provider.

func (*ClipboardService) ReadText

func (s *ClipboardService) ReadText() (string, error)

ReadText reads text content from the clipboard.

func (*ClipboardService) Write

func (s *ClipboardService) Write(content *model.ClipboardContent) error

Write writes content using the first available provider.

func (*ClipboardService) WriteText

func (s *ClipboardService) WriteText(text string) error

WriteText writes text content to the clipboard.

type ImageCodec

type ImageCodec struct{}

ImageCodec provides image encoding and decoding functionality. It's a domain service that handles image format conversions.

func NewImageCodec

func NewImageCodec() *ImageCodec

NewImageCodec creates a new ImageCodec instance.

func (*ImageCodec) ConvertFormat

func (c *ImageCodec) ConvertFormat(data []byte, targetFormat value.MIMEType) ([]byte, error)

ConvertFormat converts an image from one format to another.

func (*ImageCodec) Decode

func (c *ImageCodec) Decode(data []byte) (image.Image, value.MIMEType, error)

Decode decodes image data from any supported format (PNG, JPEG, GIF, BMP). Returns the decoded image and the detected format.

func (*ImageCodec) DecodeGIF

func (c *ImageCodec) DecodeGIF(data []byte) (image.Image, error)

DecodeGIF decodes GIF image data.

func (*ImageCodec) DecodeJPEG

func (c *ImageCodec) DecodeJPEG(data []byte) (image.Image, error)

DecodeJPEG decodes JPEG image data.

func (*ImageCodec) DecodePNG

func (c *ImageCodec) DecodePNG(data []byte) (image.Image, error)

DecodePNG decodes PNG image data.

func (*ImageCodec) DetectFormat

func (c *ImageCodec) DetectFormat(data []byte) (value.MIMEType, error)

DetectFormat detects the image format from the data bytes. It uses magic bytes to identify the format.

func (*ImageCodec) EncodeGIF

func (c *ImageCodec) EncodeGIF(img image.Image) ([]byte, error)

EncodeGIF encodes image data to GIF format.

func (*ImageCodec) EncodeJPEG

func (c *ImageCodec) EncodeJPEG(img image.Image, quality int) ([]byte, error)

EncodeJPEG encodes image data to JPEG format with the specified quality (1-100). Default quality is 90 if quality <= 0 or quality > 100.

func (*ImageCodec) EncodePNG

func (c *ImageCodec) EncodePNG(img image.Image) ([]byte, error)

EncodePNG encodes image data to PNG format. The input imageData should be raw pixel data or an already decoded image.

type Provider

type Provider interface {
	// Read reads content from the clipboard
	Read() (*model.ClipboardContent, error)

	// Write writes content to the clipboard
	Write(content *model.ClipboardContent) error

	// IsAvailable returns true if the clipboard provider is available
	IsAvailable() bool

	// Name returns the name of the provider (e.g., "OSC52", "Windows Native")
	Name() string
}

Provider is the interface that clipboard implementations must satisfy. This is a domain interface (hexagonal architecture port).

type RichTextCodec

type RichTextCodec struct{}

RichTextCodec provides HTML and RTF encoding/decoding functionality. It's a domain service that handles rich text format conversions.

func NewRichTextCodec

func NewRichTextCodec() *RichTextCodec

NewRichTextCodec creates a new RichTextCodec instance.

func (*RichTextCodec) DecodeHTML

func (c *RichTextCodec) DecodeHTML(htmlContent string) (string, value.TextStyles, error)

DecodeHTML decodes HTML content to plain text and extracts styles. This is a simplified decoder that handles basic tags only. Returns the plain text, detected styles, and any error.

func (*RichTextCodec) DecodeRTF

func (c *RichTextCodec) DecodeRTF(rtfContent string) (string, value.TextStyles, error)

DecodeRTF decodes RTF content to plain text and extracts styles. This is a simplified decoder that handles basic RTF tags only. Returns the plain text, detected styles, and any error.

func (*RichTextCodec) EncodeHTML

func (c *RichTextCodec) EncodeHTML(text string, styles value.TextStyles) (string, error)

EncodeHTML encodes text with styles into HTML format. Supports basic formatting: bold, italic, underline, and colors.

func (*RichTextCodec) EncodeRTF

func (c *RichTextCodec) EncodeRTF(text string, styles value.TextStyles) (string, error)

EncodeRTF encodes text with styles into RTF format. Supports basic formatting: bold, italic, underline, and colors.

func (*RichTextCodec) HTMLToRTF

func (c *RichTextCodec) HTMLToRTF(htmlContent string) (string, error)

HTMLToRTF converts HTML content to RTF format.

func (*RichTextCodec) RTFToHTML

func (c *RichTextCodec) RTFToHTML(rtfContent string) (string, error)

RTFToHTML converts RTF content to HTML format.

func (*RichTextCodec) StripHTMLTags

func (c *RichTextCodec) StripHTMLTags(htmlContent string) (string, error)

StripHTMLTags removes all HTML tags from the input, leaving only plain text. This provides security by removing potentially dangerous HTML.

func (*RichTextCodec) StripRTFFormatting

func (c *RichTextCodec) StripRTFFormatting(rtfContent string) (string, error)

StripRTFFormatting removes all RTF formatting from the input, leaving only plain text.

Jump to

Keyboard shortcuts

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