cortav  Diff

Differences From Artifact [2aa6072a5d]:

To Artifact [6b3b695c7e]:


     1      1   -- [ʞ] cli.lua
     2      2   --  ~ lexi hale <lexi@hale.su>
     3      3   --  🄯 AGPLv3
     4      4   --  ? simple command line driver for the cortav library
     5      5   local ct = require 'cortav'
     6      6   local ss = require 'sirsem'
     7      7   
            8  +local native = _G.native
            9  +
     8     10   local default_mode = {
     9     11   	['render:format'] = 'html';
    10     12   	['html:gen-styles'] = true;
    11     13   	['groff:color'] = true;
    12     14   }
    13     15   
    14     16   local function
................................................................................
   223    225   local ok, e = true, entry_cli()
   224    226   if not ok then
   225    227   	local str = 'translation failure'
   226    228   	if ss.exn.is(e) then
   227    229   		str = e.kind.desc
   228    230   	end
   229    231   	local color = false
   230         -	if log:seek() == nil then
   231         -		-- this is not a very reliable heuristic for detecting
   232         -		-- attachment to a tty but it's better than nothing
   233         -		if os.getenv('COLORTERM') then
          232  +	if native then
          233  +		if native.posix.isatty(log) then
   234    234   			color = true
   235         -		else
   236         -			local term = os.getenv('TERM')
   237         -			if term:find 'color' then color = true end
          235  +		end
          236  +	else
          237  +		if log:seek() == nil then
          238  +			-- this is not a very reliable heuristic for detecting
          239  +			-- attachment to a tty but it's better than nothing
          240  +			if os.getenv('COLORTERM') then
          241  +				color = true
          242  +			else
          243  +				local term = os.getenv('TERM')
          244  +				if term:find 'color' then color = true end
          245  +			end
   238    246   		end
   239    247   	end
   240    248   	if color then
   241    249   		str = string.format('\27[1;31m%s\27[m', str)
   242    250   	end
   243    251   	log:write(string.format('%s: %s\n', str, e))
   244    252   	os.exit(1)
   245    253   end
   246    254   os.exit(e)