Add ANSI escape sequence handling for compilation output#140
Open
KlevisImeri wants to merge 5 commits into
Open
Add ANSI escape sequence handling for compilation output#140KlevisImeri wants to merge 5 commits into
KlevisImeri wants to merge 5 commits into
Conversation
- Add PLAN.md with implementation design for porting Emacs' ansi-color behavior - Add lua/compile-mode/ansi.lua module for ANSI CSI and OSC escape sequence processing - Addresses issue ej-shafran#135: non-SGR sequences (e.g. OSC 8 hyperlinks) now handled gracefully
- Add ansi.lua module centralizing all ANSI processing - Three modes: passthrough, filter, render - CSI non-SGR stripping, OSC stripping, SGR color rendering via baleia - Partial escape sequence buffering for chunked output - Configurable OSC handler table for side effects - Lazy initialization on first buf_set_lines call - Update config, docs (README + vimdoc), health check
- Fix PARTIAL_CSI_PATTERN missing $ anchor causing complete sequences to be incorrectly buffered as partials - Fix process_osc to return handler return value instead of discarding it - Add ansi.flush() to write remaining partial buffer on process exit - Centralize modifiable toggle in buf_set_lines with buf_is_valid guard - Add M.reset() for test isolation - Call ansi.reset() in test_helpers.setup_tests - Update osc_handlers to return "" (strip) or URI (OSC 8) - Fix carriage_return_spec expectation for \e[K stripping - Set Lua runtime to LuaJIT in .luarc-ci.json for \x escape support - Add Makefile test/% and test-debug/% targets for individual test files - Add 32 tests covering filter, passthrough, partial buffering, OSC handlers, fallback, and integration - Update documentation: handler return value, partial buffering note, OSC 8 default behavior, moved osc_handlers to end of config
- Replace vim.regex/vim.fn.substitute with Lua string patterns and gsub - Clean up pattern naming (drop _SUFFIX convention and L_ prefixes) - Fix render mode negative index handling for baleia extmarks - Expose strip functions (_strip_csi, _strip_non_sgr_csi, _strip_osc) for testing - Add assert_output, assert_buffer, assert_render test helpers - Add pattern correctness and render mode test suites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds ANSI escape sequence handling to compilation output, inspired by Emacs'
ansi-color.elandansi-osc.el. A newansi.luamodule centralizes all processing: CSI stripping, OSC handling, and SGR color rendering via baleia.Closes #135
The new config options added are:
ansi_color_for_compilation:Controls how ANSI escape sequences are handled:
"render"(default): strip non-SGR CSI and OSC, render SGR colors via baleia.nvim"filter": strip all CSI and OSC sequences, write plain text"passthrough": no processing, pass through raw escape sequencesWhen
"render"is set but baleia.nvim is unavailable, falls back to"filter"with a warning.osc_handlers:A table mapping OSC command numbers to handler functions. Each handler receives the data portion of the OSC sequence and must return a replacement string that
appears in the buffer. Return
""to strip. Default handlers strip all sequences except OSC 8 (hyperlinks), which renders the URI visible.Behavior Changes
"Lua.runtime.version": "LuaJIT",which is the one Neovim uses.\e[Kand other CSI sequences now stripped: The test incarriage_return_spec.luathat expected\e[Kto appear in buffer output has been updated. Terminal cursor control sequences don't apply to Neovim buffers and are now correctly removed.process exits.
CI
make typecheckpassesmake fmtpassesmake testpasses (all existing + 32 new)