glyphs

package
v0.0.0-...-68956d0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package glyphs — filter.go: byte-level emoji → ASCII rewriter.

Implemented as a precomputed bytes.Replacer-equivalent: a flat list of (needle, replacement) pairs scanned in a single left-to-right pass. Keeps allocations to one buffer per Write call.

Package glyphs resolves the active glyph-rendering mode (rich vs safe) and installs an os.Stdout / os.Stderr byte-stream filter that rewrites emoji into ASCII fallbacks when "safe" is active.

Composition: chains AFTER gitmap/theme.Install — both packages wrap the standard handles with a pipe; stacking is fine and order- independent since each filter only touches its own byte patterns.

Package glyphs — install.go: optional pipe-wrap that runs every stdout / stderr byte through Filter. Skipped entirely in ModeRich for true zero-overhead passthrough.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Drain

func Drain()

Drain closes every installed pipe writer and waits for the matching forwarder goroutine to flush its buffered bytes to the underlying destination fd. MUST be called before os.Exit when output integrity matters (e.g. cliexit.Fail) — otherwise the last failure message can vanish on Windows.

After Drain returns the wrapped os.Stdout / os.Stderr are closed and any further writes will fail with ErrClosed. That is the correct shape for an exit-path-only flusher.

func Filter

func Filter(p []byte, mode Mode) []byte

Filter returns p with every glyph rewritten per table when mode is ModeSafe. ModeRich returns p unchanged (zero-cost passthrough).

func Install

func Install()

Install resolves the active mode and (when ModeSafe) replaces os.Stdout / os.Stderr with pipe-backed writers that filter glyphs. Idempotent across calls.

func IsValidLabel

func IsValidLabel(label string) bool

IsValidLabel reports whether label is a recognized glyph mode.

Types

type Mode

type Mode int

Mode is the resolved glyph selection.

const (
	// ModeRich passes UTF-8 emoji through unchanged.
	ModeRich Mode = iota
	// ModeSafe rewrites emoji to ASCII fallbacks.
	ModeSafe
)

func Active

func Active() Mode

Active returns the resolved mode (defaults to ModeRich pre-Install).

func Parse

func Parse(label string) Mode

Parse maps a user label to a Mode. Unknown values resolve via auto.

func Resolve

func Resolve() Mode

Resolve picks the mode from the GITMAP_GLYPHS env var (populated by the flag stripper or the user's shell).

Jump to

Keyboard shortcuts

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