Skip to content

Unify ANSI display formatting in Core module - #450

Merged
ocots merged 1 commit into
mainfrom
unify-ansi-display
Jun 15, 2026
Merged

Unify ANSI display formatting in Core module#450
ocots merged 1 commit into
mainfrom
unify-ansi-display

Conversation

@ocots

@ocots ocots commented Jun 15, 2026

Copy link
Copy Markdown
Member

Summary

Centralizes all ANSI formatting utilities in Core/display.jl to provide a single source of truth for terminal color support across the package.

Changes

New files

  • src/Core/display.jl — ANSI formatting primitives:

    • _apply_ansi(s, code, io::IO) — base function with color detection
    • Semantic wrappers: _dim, _bold, _red, _yellow, _green
    • get_format_codes(io::IO) — semantic palette for structured display
    • Bug fix: supports_color = trueget(io, :color, false) (detection was commented out)
  • src/Core/tags.jl — Moved AbstractTag from display.jl (better organization)

  • test/suite/core/test_core_display.jl — Comprehensive tests (52 assertions):

    • Tests color detection (with/without color)
    • Tests all ANSI wrappers
    • Tests get_format_codes NamedTuple structure

Modified files

  • src/CTBase.jl — Changed load order: Core before Exceptions (was stale comment "must load first")
  • src/Core/Core.jl — Added include("display.jl") and include("tags.jl")
  • src/Exceptions/Exceptions.jl — Added using ..Core: Core for qualified access
  • src/Exceptions/display.jl — Removed local ANSI definitions, now uses qualified calls (Core._dim, Core._bold, etc.)

Philosophy compliance

  • No top-level exports — ANSI functions use underscore prefix, not exported
  • Qualified imports — Exceptions uses Core._dim instead of using ..Core: _dim
  • Single source of truth — All ANSI formatting centralized in Core

Testing

All tests pass (1242/1242), including:

  • New test_core_display.jl (52/52)
  • Existing test_exception_display.jl (155/155)

- Add Core/display.jl with _apply_ansi primitives and semantic wrappers (_dim, _bold, _red, _yellow, _green)
- Add Core/tags.jl with AbstractTag (moved from display.jl)
- Fix get_format_codes color detection bug (supports_color = true → get(io, :color, false))
- Load Core before Exceptions in CTBase.jl (Exceptions now imports from Core)
- Exceptions/display.jl uses qualified calls (Core._dim, etc.) instead of local definitions
- Add test_core_display.jl with comprehensive tests for ANSI functions
@ocots
ocots merged commit 5127b07 into main Jun 15, 2026
6 checks passed
@ocots
ocots deleted the unify-ansi-display branch June 15, 2026 21:52
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