lunarmodules / busted

Elegant Lua unit testing.
https://lunarmodules.github.io/busted/
MIT License
1.4k stars 185 forks source link

New Windows consoles output in color! #625

Closed endowdly closed 2 years ago

endowdly commented 4 years ago

With Windows 10, the new Console Host and Windows Terminal both support ANSI escape codes and support term.colors.

Here is a simple change I made to utfTerminal.lua:

Original

-- begin handler... 
local s = require 'say'
local pretty = require 'pl.pretty'
local io = io
local colors

if package.config:sub(1,1) == '\\' and not os.getenv("ANSICON") then
  -- Disable colors on Windows.
  colors = setmetatable({}, {__index = function() return function(s) return s end end})
else
  colors = require 'term.colors'
end
-- ... 

Warning: does no version or or system checking

Modified

-- utfWindows.lua

local s = require 'say'
local pretty = require 'pl.pretty'
local io = io
local colors = require 'term.colors

-- ...

Not sure if your team would like to incorporate this with some os version checking??

Note: the console has to be set to output UTF-8, otherwise it'll pump out .NETUnicode (UTF-16 LE) by default.

# Setting it in PowerShell is easy...
[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Tieske commented 3 years ago

I think this could be interesting, big question is how to fool-proof test for this ability?

endowdly commented 3 years ago

@Tieske This is a great question, and not sure how I would approach this. Frankly, testing the console host (especially for Windows) is not something I know how to do, or even know how to approach.

My thought would be a call of some kind, either to C++ libs or to PowerShell that could query the console and return a value in the Lua module that could set up the term colors?

Tieske commented 2 years ago

see https://github.com/Olivine-Labs/busted/pull/675 which adds flags to force behaviour.

closing this. If not appropriate, please reopen.