Help us shape the future of Go! Take the 2026 Go Developer Survey

render

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package render produit la sortie colorée et accessible destinée à l'apprenant.

Index

Constants

View Source
const (
	LabelLogTail = "Fin du journal"
	LabelOthers  = "Autres conteneurs arrêtés en erreur :"
)

Libellés de l'analyse d'un conteneur arrêté (feature 004).

View Source
const (
	SymbolError    = "✖"
	LabelConcept   = "📘 Concept"
	LabelCause     = "🔎 Cause probable"
	LabelFixes     = "💡 Corrections"
	LabelAnti      = "⚠ Anti-pattern"
	SymbolSuccess  = "✔"
	LabelDeepen    = "➜ Pour aller plus loin"
	LabelOriginal  = "Message Docker d'origine"
	LabelUnknown   = "Erreur non reconnue"
	LabelExercise  = "🧪 Exercice"
	LabelExample   = "▶ Exemple"
	LabelDocLink   = "📖 Documentation"
	LabelRepeated  = "↺ Même erreur que précédemment"
	LabelLast      = "↺ Explication complète"
	LabelProblem   = "✖ Problème"
	LabelFixedPart = "💡 Version corrigée"
	// Feature 003 : pièges de la ligne de commande.
	SymbolWarning  = "⚠"
	SymbolInfo     = "ℹ"
	SymbolReminder = "↺"
	LabelFix       = "💡 Correction"
	LabelInCommand = "⚠ Dans ta commande — cause probable"
)

Libellés et symboles de chaque bloc. Ils restent affichés sans couleur : la couleur n'est jamais le seul porteur d'information (FR-007a).

View Source
const TabMarker = "→"

TabMarker représente une tabulation dans les extraits affichés.

Variables

This section is empty.

Functions

func HasDarkBackground

func HasDarkBackground(out io.Writer, env func(string) string) bool

HasDarkBackground devine si le fond du terminal est sombre : d'abord par la variable COLORFGBG (« texte;fond »), puis en interrogeant le terminal quand stdin et la sortie en sont un. Par défaut, le fond est supposé sombre.

func IsTerminal

func IsTerminal(w io.Writer) bool

IsTerminal indique si w est un terminal.

func NewWriter

func NewWriter(w io.Writer, color bool) io.Writer

NewWriter enveloppe w pour adapter les couleurs aux capacités du terminal (16, 256 ou 16 millions de couleurs). Quand la couleur est forcée sur une sortie qui n'est pas un terminal, le profil 256 couleurs est utilisé.

func RenderDeepen

func RenderDeepen(w io.Writer, e *catalog.Entry, captures map[string]string, exercise bool, o Options) error

RenderDeepen affiche l'approfondissement d'une entrée : concept détaillé, exemple exécutable coloré, exercice (sur demande) et lien vers la documentation officielle.

func RenderExited added in v0.3.0

func RenderExited(w io.Writer, v ExitedView, o Options) error

RenderExited affiche l'analyse : conteneur, fin du journal, concept, cause, corrections.

func RenderExplanation

func RenderExplanation(w io.Writer, d diagnose.Diagnosis, original string, o Options) error

RenderExplanation écrit l'explication d'un diagnostic, en français, dans l'ordre : résumé, concept, cause, corrections, anti-pattern, message d'origine, approfondissement.

func RenderFindings added in v0.3.0

func RenderFindings(w io.Writer, items []LintItem, o Options) error

RenderFindings écrit les pièges d'une ligne de commande en un seul affichage : avertissements puis informations (l'ordre reçu est conservé), rappels en une ligne.

func RenderInline added in v0.3.0

func RenderInline(w io.Writer, items []LintItem, o Options) error

RenderInline ajoute à une explication d'erreur les pièges de la ligne de commande, présentés comme cause probable (FR-010).

func RenderNoExited added in v0.3.0

func RenderNoExited(w io.Writer, o Options) error

RenderNoExited indique qu'aucun conteneur n'est arrêté en erreur.

func RenderOriginal added in v0.3.0

func RenderOriginal(w io.Writer, original string, o Options) error

RenderOriginal écrit seulement le message Docker d'origine (utilisé quand un piège de la ligne de commande remplace le bloc « erreur non reconnue »).

func ResolveColor

func ResolveColor(flag string, env func(string) string, isTTY bool) bool

ResolveColor décide si la sortie doit être colorée.

  • --color=always ou --color=never l'emportent sur tout le reste ;
  • en mode auto : NO_COLOR (non vide) désactive, CLICOLOR_FORCE=1 force, sinon la couleur n'est active que si la sortie est un terminal.

func SignalLine added in v0.3.0

func SignalLine(name string, code int, after string, removed bool, t Theme) string

SignalLine est la ligne affichée à l'invite quand un conteneur lancé en arrière-plan s'est arrêté en erreur (FR-013) ; after est le délai depuis son lancement (« 3 s »).

func TerminalWidth

func TerminalWidth(w io.Writer) int

TerminalWidth renvoie la largeur du terminal associé à w, ou 80 par défaut.

func Wrap

func Wrap(text string, width int, prefix string) string

Wrap coupe un paragraphe à la largeur donnée, chaque ligne étant précédée de prefix.

Types

type ColorMode

type ColorMode string

ColorMode est la valeur de l'option --color.

const (
	ColorAuto   ColorMode = "auto"
	ColorAlways ColorMode = "always"
	ColorNever  ColorMode = "never"
)

func ParseColorMode

func ParseColorMode(s string) (ColorMode, error)

ParseColorMode valide la valeur de l'option --color.

type ExitedView added in v0.3.0

type ExitedView struct {
	Entry          *catalog.Entry
	Captures       map[string]string
	Log            []string // au plus 20 lignes, déjà nettoyées et masquées
	LogUnavailable string   // raison, si le journal ne peut pas être lu
	Others         []OtherLine
}

ExitedView est l'analyse d'un conteneur arrêté, prête à afficher : captures nettoyées et masquées (name, image, code, lifetime, age, state, variable, restart_count, restart_policy, compose_project, compose_service…), fin du journal et autres conteneurs en erreur.

type Line

type Line struct {
	Number int
	Text   string
}

Line est une ligne numérotée d'un extrait de fichier.

type LintItem added in v0.3.0

type LintItem struct {
	Entry    *catalog.Entry
	Captures map[string]string
	Reminder bool // rappel d'une ligne (même piège affiché en complet il y a moins de 10 minutes)
}

LintItem est un piège de la ligne de commande à afficher (feature 003).

type Options

type Options struct {
	Theme         Theme
	Width         int    // largeur de mise en page (40 minimum)
	DockerVersion string // version du client Docker, si connue (FR-001b)
	Repeated      bool   // même erreur depuis moins de 10 minutes : rendu court
	Interactive   bool   // stderr non capturé
	ExitCode      int
}

Options règle le rendu d'une explication.

type OtherLine added in v0.3.0

type OtherLine struct {
	Name    string
	Code    int
	Age     string
	Summary string
}

OtherLine est un autre conteneur en erreur, résumé en une ligne.

type Theme

type Theme struct {
	Color bool
	Dark  bool
	// contains filtered or unexported fields
}

Theme applique les styles de chaque rôle. Sans couleur, il renvoie le texte tel quel.

func NewTheme

func NewTheme(colorOn, dark bool) Theme

NewTheme construit le thème. La palette unique s'adapte au fond clair ou sombre.

func (Theme) Anti

func (t Theme) Anti(s string) string

func (Theme) Cause

func (t Theme) Cause(s string) string

func (Theme) Concept

func (t Theme) Concept(s string) string

func (Theme) Dim

func (t Theme) Dim(s string) string

func (Theme) Emphasis

func (t Theme) Emphasis(s string) string

func (Theme) Fix

func (t Theme) Fix(s string) string

func (Theme) Highlight

func (t Theme) Highlight(code, lexer string) string

Highlight colore du code (lexer « bash », « yaml » ou « docker »). Sans couleur, le code est renvoyé tel quel.

func (Theme) HighlightLines

func (t Theme) HighlightLines(lines []Line, lexer string, focusLine, focusCol int) string

HighlightLines affiche un extrait numéroté. La ligne focusLine est marquée par « ➤ » (et surlignée en couleur) ; si focusCol > 0, un « ^ » est placé sous la colonne fautive.

func (Theme) Hint

func (t Theme) Hint(s string) string

func (Theme) Label

func (t Theme) Label(s string) string

func (Theme) Success

func (t Theme) Success(s string) string

func (Theme) Title

func (t Theme) Title(s string) string

Jump to

Keyboard shortcuts

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