Skip to content

feat: sanitize terminal control characters in the output package - #237

Draft
Vladislav Nechakhin (vladislav-nechakhin) wants to merge 1 commit into
mainfrom
feat/terminal-output
Draft

feat: sanitize terminal control characters in the output package#237
Vladislav Nechakhin (vladislav-nechakhin) wants to merge 1 commit into
mainfrom
feat/terminal-output

Conversation

@vladislav-nechakhin

Copy link
Copy Markdown

Description

Text returned by the API is printed to the terminal as-is, so control characters in it are acted on by the terminal rather than displayed. This adds a printing API to internal/output that replaces those characters with a visible placeholder, and makes the existing renderers use it. Pretty output now shows U+FFFD in their place; JSON output is unchanged.

Key changes:

  • New printers: Printf, Println, Fprintf, Fprintln, Errorf, Errorln.
  • PrintLines/FprintLines for multi-line text such as encoded JSON.
  • PrintProxied/FprintProxied for output another program produced, where escape sequences must pass through untouched.
  • OutputTable, OutputTree and PrintRunsTable sanitize their titles, headers and cells; table rendering moved into a shared TableTo that takes a writer.
  • TruncateRunes replaces the byte slice that shortened long run names, which could cut a multi-byte character in half.
  • start_time is parsed instead of byte-sliced at fixed offsets, so an unexpected value renders as N/A.
  • Titles underline to their rune count instead of their byte length.
  • Dropped PrintError, which had no callers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant