Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Is it possible to change colors for Lua output window texts

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Discussions
View previous topic :: View next topic  
Author Message
peddroelm
Advanced Cheater
Reputation: 0

Joined: 03 Oct 2014
Posts: 55

PostPosted: Fri Apr 06, 2018 10:49 pm    Post subject: Is it possible to change colors for Lua output window texts Reply with quote

Working on some combat feedback table and I would like to have damage related feedback stuff, XP gain related feedback stuff, various state and status related stuff all with different text color.

Is there some simple set text color instruction my google fu has failed to find ?
(how) Can this be achieved ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 360

Joined: 09 May 2003
Posts: 21049
Location: The netherlands

PostPosted: Sat Apr 07, 2018 12:36 am    Post subject: Reply with quote

use a paintbox or image and use canvas's textOut to draw text. It uses the current font color
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
peddroelm
Advanced Cheater
Reputation: 0

Joined: 03 Oct 2014
Posts: 55

PostPosted: Sat Apr 07, 2018 1:25 am    Post subject: Reply with quote

Sorry , I can't make much sense of your previous advice Smile .

I tried saving this as ansicolors.LUA on desktop (same location as my .CT file)

http://lua-users.org/wiki/AnsiTerminalColors
https://github.com/kikito/ansicolors.lua


Code:

- support detection
local function isWindows()
  return type(package) == 'table' and type(package.config) == 'string' and package.config:sub(1,1) == '\\'
end

local supported = not isWindows()
if isWindows() then supported = os.getenv("ANSICON") end

local keys = {
  -- reset
  reset =      0,

  -- misc
  bright     = 1,
  dim        = 2,
  underline  = 4,
  blink      = 5,
  reverse    = 7,
  hidden     = 8,

  -- foreground colors
  black     = 30,
  red       = 31,
  green     = 32,
  yellow    = 33,
  blue      = 34,
  magenta   = 35,
  cyan      = 36,
  white     = 37,

  -- background colors
  blackbg   = 40,
  redbg     = 41,
  greenbg   = 42,
  yellowbg  = 43,
  bluebg    = 44,
  magentabg = 45,
  cyanbg    = 46,
  whitebg   = 47
}

local escapeString = string.char(27) .. '[%dm'
local function escapeNumber(number)
  return escapeString:format(number)
end

local function escapeKeys(str)

  if not supported then return "" end

  local buffer = {}
  local number
  for word in str:gmatch("%w+") do
    number = keys[word]
    assert(number, "Unknown key: " .. word)
    table.insert(buffer, escapeNumber(number) )
  end

  return table.concat(buffer)
end

local function replaceCodes(str)
  str = string.gsub(str,"(%%{(.-)})", function(_, str) return escapeKeys(str) end )
  return str
end

-- public

local function ansicolors( str )
  str = tostring(str or '')

  return replaceCodes('%{reset}' .. str .. '%{reset}')
end


return setmetatable({noReset = replaceCodes}, {__call = function (_, str) return ansicolors (str) end})


and then executing

Code:

 local colors = require 'ansicolors'
  print(colors('%{red}hello'))
  print(colors('%{redbg}hello%{reset}'))
  print(colors('%{bright red underline}hello'))


in the Lua engine window, without success :

Code:

 local colors = require 'ansicolors'
  print(colors('%{red}hello'))
  print(colors('%{redbg}hello%{reset}'))
  print(colors('%{bright red underline}hello'))

Error:[string " local colors = require 'ansicolors'
..."]:2: attempt to call a table value (local 'colors')
Script Error




EDIT:

"sadly ....

Notice that the tests will only work on an ANSI-compatible machine (windows isnít ANSI-compatible)

Windows
Windows console, by default, isnít capable of handling ANSI color codes correctly. This library tries to detect whether it is on a windows machine (by looking at package.path) and in that case it suppresses all ANSI control characters (the text appears devoid of color, but legible)."

EDIT2 :

or maybe not?
"... One notable exception was the Win32 console of Microsoft Windows before Windows 10 update TH2."
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Discussions All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites