format

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionError

func ActionError(w io.Writer, msg string, opts OutputOptions) error

ActionError outputs "Error: <message>" for failed action commands.

func ActionSuccess

func ActionSuccess(w io.Writer) error

ActionSuccess outputs "OK" for successful action commands.

func ComputedStyles

func ComputedStyles(w io.Writer, styles map[string]string) error

ComputedStyles outputs computed styles in text format. Format: property: value (one per line)

func ComputedStylesMulti

func ComputedStylesMulti(w io.Writer, elements []ipc.ElementWithStyles) error

ComputedStylesMulti outputs computed styles for multiple elements. Each element is identified by a CSS selector-style identifier (#id, .class:N, or tag:N) printed on a separate line before its styles. Multiple elements are separated by "--".

Format:

#header
color: blue
font-size: 16px
--
.panel:2
background: white

Elements are identified by priority: ID > first class > tag name. Index numbers are 1-based for user readability.

func Console

func Console(w io.Writer, entries []ipc.ConsoleEntry, opts OutputOptions) error

Console outputs console entries in text format.

func Cookies

func Cookies(w io.Writer, cookies []ipc.Cookie, opts OutputOptions) error

Cookies outputs cookies in text format (semicolon-separated attributes).

func EvalResult

func EvalResult(w io.Writer, data ipc.EvalData) error

EvalResult outputs the raw JavaScript return value.

func FilePath

func FilePath(w io.Writer, path string) error

FilePath outputs a file path (for screenshot, html commands).

func FormatElementIdentifier

func FormatElementIdentifier(meta ipc.ElementMeta, index int) string

FormatElementIdentifier returns a CSS selector-style identifier for an element. The identifier helps users distinguish between multiple elements in output.

Format:

  • #id if element has id attribute
  • .class:N if element has class attribute (N is 1-based index)
  • tag:N fallback using tag name (N is 1-based index)

The index parameter is 0-based but displayed as 1-based (index+1) for user-friendliness. IDs and classes are sanitized to remove invalid CSS identifier characters. If sanitization results in an empty string, the next priority level is used.

Examples:

  • Element with id="header" -> "#header"
  • Element with class="panel active" at index 0 -> ".panel:1"
  • Element with tag "div" at index 2 -> "div:3"

func InlineStyles

func InlineStyles(w io.Writer, elements []ipc.ElementWithStyles) error

InlineStyles outputs inline style attributes for multiple elements. Each element is identified by a CSS selector-style identifier (#id, .class:N, or tag:N) printed on a separate line before its inline style. Multiple elements are separated by "--". Empty inline styles are displayed as "(empty)".

Format:

#main
color: red; margin: 10px;
--
.item:1
(empty)

Elements are identified by priority: ID > first class > tag name. Index numbers are 1-based for user readability.

func MatchedRules

func MatchedRules(w io.Writer, rules []ipc.CSSMatchedRule) error

MatchedRules outputs matched CSS rules with -- separators.

func Network

func Network(w io.Writer, entries []ipc.NetworkEntry, opts OutputOptions) error

Network outputs network entries in text format.

func PropertyValue

func PropertyValue(w io.Writer, value string) error

PropertyValue outputs a single CSS property value.

func SanitizeIdentifier

func SanitizeIdentifier(s string) string

SanitizeIdentifier removes invalid CSS identifier characters. Only alphanumeric characters, hyphens, and underscores are retained. Returns an empty string if no valid characters remain.

This function is used to clean id and class attributes before using them in CSS selector notation. Invalid characters are stripped to ensure the resulting identifier is valid CSS.

func Status

func Status(w io.Writer, data ipc.StatusData, opts OutputOptions) error

Status outputs daemon status in text format.

func Tab added in v0.1.0

func Tab(w io.Writer, data ipc.TabData, opts OutputOptions) error

Tab outputs the tab list in text format.

func TabError added in v0.1.0

func TabError(w io.Writer, errorMsg string, sessions []ipc.PageSession, matches []ipc.PageSession, opts OutputOptions) error

TabError outputs a tab error with session/match information.

Types

type OutputOptions

type OutputOptions struct {
	UseColor bool // Enable ANSI color codes
}

OutputOptions controls text formatting behavior.

func DefaultOptions

func DefaultOptions() OutputOptions

DefaultOptions returns default output options based on TTY detection. Deprecated: Use NewOutputOptions instead for proper color detection.

func NewOutputOptions

func NewOutputOptions(jsonOutput bool, noColorFlag bool) OutputOptions

NewOutputOptions returns output options based on flags and environment. Priority: jsonOutput > noColorFlag > NO_COLOR env > TTY detection.

Jump to

Keyboard shortcuts

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