Documentation
¶
Overview ¶
Package render produit la sortie colorée et accessible destinée à l'apprenant.
Index ¶
- Constants
- func HasDarkBackground(out io.Writer, env func(string) string) bool
- func IsTerminal(w io.Writer) bool
- func NewWriter(w io.Writer, color bool) io.Writer
- func RenderDeepen(w io.Writer, e *catalog.Entry, captures map[string]string, exercise bool, ...) error
- func RenderExited(w io.Writer, v ExitedView, o Options) error
- func RenderExplanation(w io.Writer, d diagnose.Diagnosis, original string, o Options) error
- func RenderFindings(w io.Writer, items []LintItem, o Options) error
- func RenderInline(w io.Writer, items []LintItem, o Options) error
- func RenderNoExited(w io.Writer, o Options) error
- func RenderOriginal(w io.Writer, original string, o Options) error
- func ResolveColor(flag string, env func(string) string, isTTY bool) bool
- func SignalLine(name string, code int, after string, removed bool, t Theme) string
- func TerminalWidth(w io.Writer) int
- func Wrap(text string, width int, prefix string) string
- type ColorMode
- type ExitedView
- type Line
- type LintItem
- type Options
- type OtherLine
- type Theme
- func (t Theme) Anti(s string) string
- func (t Theme) Cause(s string) string
- func (t Theme) Concept(s string) string
- func (t Theme) Dim(s string) string
- func (t Theme) Emphasis(s string) string
- func (t Theme) Fix(s string) string
- func (t Theme) Highlight(code, lexer string) string
- func (t Theme) HighlightLines(lines []Line, lexer string, focusLine, focusCol int) string
- func (t Theme) Hint(s string) string
- func (t Theme) Label(s string) string
- func (t Theme) Success(s string) string
- func (t Theme) Title(s string) string
Constants ¶
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).
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).
const TabMarker = "→"
TabMarker représente une tabulation dans les extraits affichés.
Variables ¶
This section is empty.
Functions ¶
func HasDarkBackground ¶
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 NewWriter ¶
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 ¶
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
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
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
RenderNoExited indique qu'aucun conteneur n'est arrêté en erreur.
func RenderOriginal ¶ added in v0.3.0
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 ¶
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
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 ¶
TerminalWidth renvoie la largeur du terminal associé à w, ou 80 par défaut.
Types ¶
type ColorMode ¶
type ColorMode string
ColorMode est la valeur de l'option --color.
func ParseColorMode ¶
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
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 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 Theme ¶
Theme applique les styles de chaque rôle. Sans couleur, il renvoie le texte tel quel.
func (Theme) Highlight ¶
Highlight colore du code (lexer « bash », « yaml » ou « docker »). Sans couleur, le code est renvoyé tel quel.
func (Theme) HighlightLines ¶
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.