Jump to content

SciTE - show hex color value in the script


Recommended Posts

Hi,

I think, you all know this: You look at a script containing color values. You have a rough idea of the colors, but would like to know how it looks like. 
I have created a Lua script that displays the color of the value in SciTE as Calltip. Set the cursor in the Hex-value, press the hotkey. Above the value a Call tip appears. The background color corresponds to the hex value.

Read the function header to obtain installation instructions.

So it looks.  calltip_col.png

EDIT:
I think it's better to bind the function not only of AutoIt. If it can be called in all files, also the color settings in the * .properties can view. For this purpose remove the file attachment from the call. Use: command.13.*=  instead of: command.13.*.au3=

 

EDIT 20.07.2015:
Now I've made some changes
- You can switch to show colors as RGB or BGR
- added new function: PreviewBackForeColor
To have a preview for back and fore color:
- Write in one line first the back color, than the fore color (i. e. as comment: "; 0xDEDEDE 0x000080") OR
  have this values inside a function call: "_AnyFunction($param1, $param2, 0xDEDEDE, $param3 0x000080)".
  If the order inside the call is reverse (first hex value is fore color), you can call the function with Flag "_fFore1st=true"
- No other color value may be included in this line. If any - the first and second color will used.
- Set the cursor in this line and hit the Hotkey.
- A Calltip appears with the back color and the text "FORE-COLOR" with color of the fore value.
- If only one color value was find in this line, this value will used as back color or, if Flag is "true", as fore color.
  In this cases the fore color is set to black and with Flag the back color is the default GUI back color "0xF0F0F0"

Because you've different functions in one script, you need another way to install and call it. Read the instructions inside the script.

First color used as back color, second as fore color.

 preview_colors_1.jpg

Function called with flag - first color is now the fore color.

 preview_colors_1_reverse.jpg

preview_colors_2.jpg

 

EDIT 2018-01-16:

Added: 

Now be also recognized in au3 scripts, variables/constants which have an color assignment inside the script or inside an include file from this script.
But it can only be one assignment per line. If the assignment is inside a comment line or -block, it will ignored.
The assignment can also be build by using function(s) [from script or include files].
example:  "Local $COLOR = '0x' & Hex(Mod(@SEC, 2) ? Random(0,0x000FFF, 1) : Random(0x001000, 0xFFF000, 1), 8)"
But the functions must NOT CONTAIN any VARIABLES! This would require a recursive assignment search. Impossible if variables get values only at runtime.

You can disable the search inside include files with an entry in SciTEUser.properties:
#~ "ShowHexColorFromCursor.lua", Dis/Enable search in Includes (0/1  NO/YES)
Get.Color.Assignment.Includes=0

The default value (without settings) is '1', enabled.
Includes in comments will ignored.

current version v0.8

show_col_var.png

 

EDIT 2018-02-22:

Changed: Read assignment from function call got any problems - removed.
Fixed: Unexpected behavior if caret doesn't touch any hex value while calling the function.
Added: Recognition of hex values from length 1 hex character.
Added: Instead of default behavior for hiding the calltip, [line 75] local bCALLTIP_END_ANYKEY = true can be used to immediately fade out the tip every time you press a key or move a mouse.

current version v0.10

-- TIME_STAMP   2018-02-22 10:26:36   v 0.10

--[[------------- I N S T A L L A T I O N   A N D   U S I N G   I N S T R U C T I O N --------------
Save the file.
At first, make an entry in your SciTEStartup.lua

LoadLuaFile("ShowHexColorFromCursor.lua", "C:\\Your Path\\with Backslash\\")


Select free command-numbers from your SciTEUser.properties.
Customize the following settings with this numbers.


# 13 Show HexColor RGB
command.name.13.*=Show RGB-Color From Cursor
command.13.*=dostring ShowHexColorFromCursor()
command.mode.13.*=subsystem:lua,savebefore:yes
command.shortcut.13.*=Ctrl+Shift+F11

# 14 Show HexColor BGR
command.name.14.*=Show BGR-Color From Cursor
command.14.*=dostring ShowHexColorFromCursor(true)
command.mode.14.*=subsystem:lua,savebefore:yes
command.shortcut.14.*=Ctrl+Alt+F11


Set the cursor in the Hex-value, press the hotkey to show the color as RGB or as BGR.
Above the value a Call tip appears. The background color corresponds to the hex value.
A possible alpha component is ignored.

[NEW]
Now be also recognized in au3 scripts, variables/constants which have an color assignment
inside the script or inside an include file from this script.
PLEASE NOTE: Each line may only contain one assignment!
If the assignment is inside a comment line or -block, it will ignored.
You can disable the search inside include files with an entry in SciTEUser.properties:
#~ "ShowHexColorFromCursor.lua", Dis/Enable search in Includes (0/1  NO/YES)
Get.Color.Assignment.Includes=0
The default value (without settings) is '1', enabled.
Includes in comments will ignored.

Be recognized AutoIt hex color code "0x12AB34" and also HTML hex color code "#12AB34" with length from 1 to 6 hex characters.
Possible alpha information will ignored.



PREVIEW FOR BACK AND FORE COLOR:
- Write in one line first the back color, than the fore color (i. e. as comment: "; 0xDEDEDE 0x000080") OR
  have this values inside a function call: "_AnyFunction($param1, $param2, 0xDEDEDE, $param3 0x000080)".
  If the order inside the call is reverse (first hex value is fore color), you can call the function with Flag "_fFore1st=true"
- No other color value may be included in this line. If any - the first and second color will used.
- Set the cursor in this line and hit the Hotkey.
- A Calltip appears with the back color and the text "FORE-COLOR" with color of the fore value.
- If only one color value was find in this line, this value will used as back color or, if Flag is "true", as fore color.
  In this cases the fore color is set to black and with Flag the back color is the default GUI back color "0xF0F0F0"

For use with AutoIt color values only.

To have both calls (w/wo flag) make two commands:

# 11 Preview Back and Fore Color / first color value is back color
command.name.11.*.au3=Preview Back and Fore Color
command.11.*.au3=dostring PreviewBackForeColor()
command.mode.11.*.au3=subsystem:lua,savebefore:yes
command.shortcut.11.*.au3=Ctrl+Shift+F12

# 16 Preview Fore and Back Color / first color value is fore color
command.name.16.*.au3=Preview Fore and Back Color
command.16.*.au3=dostring PreviewBackForeColor(true)
command.mode.16.*.au3=subsystem:lua,savebefore:yes
command.shortcut.16.*.au3=Ctrl+Alt+F12
--------------------------------------------------------------------------------------------------]]

local bDEBUG = false                -- set "true" to get debug output
local bCALLTIP_END_ANYKEY = false   -- set "true" to cancel the calltip with any key or mouse move

------------------------------------------------------------ list object to manipulate simple tables
local objList = {
list    = {},
delall  = function(self) self.list = {} return self end,
addonce = function(self, _val, _casesense)     -- return true, if added
			  local	exists = function(_val, _casesense)
				  for k in pairs(self.list) do
					  if _casesense then if self.list[k] == _val then return true end
					  else if tostring(self.list[k]):upper() == tostring(_val):upper() then return true end
					  end
				  end return false
			  end
			  if not exists(_val, _casesense) then
				  table.insert(self.list, _val)
				  return true
			  end return nil
		  end,
new     = function(self, _obj)
			_obj = _obj or {}
			setmetatable(_obj, self)
			self.__index = self
			return _obj
		 end
}
--------------------------------------------------------------------------------------- /object list


--------------------------------------------------------------------------------------- object color
local objColor = {
	--------------------------------------------- variable will un/set if color-calltip is not/shown
	colortip_show = false,
	--------------------------------- user can disable search inside include files, default: enabled
	search_in_includes = true,
	------------------------------------------------------------------- the default calltip position
	calltips_pos_def = false,
	------------------------------------------------------------ the default calltip highlight color
	calltips_colorhlt_def = 0x0000FF,   -- BGR (red)
	---------------------------------------------------------- list with include storage directories
	lInclPathes = objList:new(),
	-------------------------------------------------- list/string with includes from current buffer
	lIncl = objList:new(), sIncl = '',
	---------------------------------------------------------------------------------------- pattern
	pattHex = '()0x([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])',
	pattHex2 = '[0-9a-fA-F][0-9a-fA-F]',
	pattHexN = '0-[x#]([0-9a-fA-F]+)',
	pattHexEnd = '0x[0-9a-fA-F]+()',
	pattCS1 = '^#[Cc][Oo][Mm][Mm][Ee][Nn][Tt][Ss]%-[Ss][Tt][Aa][Rr][Tt]',
	pattCE1 = '^#[Cc][Oo][Mm][Mm][Ee][Nn][Tt][Ss]%-[Ee][Nn][Dd]',
	pattCS2 = '^#[Cc][Ss]',
	pattCE2 = '^#[Cc][Ee]',
	pattComment = '^%s*;',
	----------------------------------------------------------------------------------------- pathes
	sPathGetColorAU3,
	sFileResult,
	TEMPDIR = props['SciteUserHome']..'\\..\\..\\Temp',
	sAU3exe = props['SciteDefaultHome']..'\\..\\AutoIt3.exe',
	------------------------------------------------------------------------------------------------

	------------------------------------------------------------ set calltip values back to defaults
	SetCalltipsDefault = function(self)
		self.colortip_show = false
		scite.SendEditor(SCI_CALLTIPSETBACK, 0xFFFFFF)
		scite.SendEditor(SCI_CALLTIPSETFOREHLT, self.calltips_colorhlt_def)
		scite.SendEditor(SCI_CALLTIPSETPOSITION, self.calltips_pos_def)
		if bDEBUG then output:AppendText('> DEBUG: Calltips set to defaults') end
	end,
	---------------------------------------------------------------------------- /SetCalltipsDefault

	------------------------------------------------------------------------------ initialize values
	Startup = function(self)
		if props['Get.Color.Assignment.Includes'] == '0' then
			self.search_in_includes = false
		end

		if tonumber(props['calltips.set.above']) == 1 then
			self.calltips_pos_def = true
		end

		if props['calltips.color.highlight'] ~= '' then
			local colorhlt_user = myCallTips:BGR2Decimal(props['calltips.color.highlight'])
			if colorhlt_user ~= nil then self.calltips_colorhlt_def = colorhlt_user end
		end

		local sProp = props['openpath.$(au3)']
	    for w in sProp:gmatch('([^;]+)') do self.lInclPathes:addonce(w) end

		self.sPathGetColorAU3 = self.TEMPDIR..'\\ExecLineGetColor.au3'
		self.sFileResult = self.TEMPDIR..'\\ExecLineColor.txt'
	end,
	--------------------------------------------------------------------------------------- /Startup

	-------- check for comment line/block. Return "true/false, 0/1/-1" (0=comment line/1=#cs/-1=#ce)
    --                                               returned number for de/increase comment counter
	CheckComment = function(self, _s)
		local iMatch = _s:find(self.pattComment)
		if iMatch ~= nil then return true, 0 end
		iMatch = _s:find(self.pattCS1) or _s:find(self.pattCS2)
		if iMatch ~= nil then return true, 1 end
		iMatch = _s:find(self.pattCE1) or _s:find(self.pattCE2)
		if iMatch ~= nil then return true, -1 end
		return false, 0
	end,
	------------------------------------------------------------------------------------------------

	--------------------------------------------------------- read include files from current buffer
	IncludesFromBuffer = function(self)
		local sText, boolCmnt, countCmnt, n, incl = editor:GetText(), false, 0
		self.lIncl:delall()
		self.sIncl = ''
		for line in sText:gmatch('([^\r\n]+)') do
			boolCmnt, n = self:CheckComment(line)
			if boolCmnt then countCmnt = countCmnt + (n) end
			if not boolCmnt and countCmnt == 0 then     -- none comment line or block
				-- #include <abc.au3>
				incl = line:match("#[iI][nN][cC][lL][uU][dD][eE]%s-<([%w%s_.]+)>")
				if incl ~= nil then
					if self.lIncl:addonce(incl) then
						self.sIncl = self.sIncl..'#include <'..incl..'>\n'
						if bDEBUG then output:AppendText('> DEBUG: IncludesFromBuffer.Add "#include <'..incl..'>"\n') end
					end
				else
					-- #include 'abc.au3' or #include "abc.au3"
					_, incl = line:match("#[iI][nN][cC][lL][uU][dD][eE]%s-([\"'])([%w%s_.:\\]+)%1")
					if incl ~= nil then
						if incl:sub(1,1) == '\\' then incl = incl:sub(2,-1) end
						if self.lIncl:addonce(incl) then
							if incl:sub(2,2) == ':' then
								self.sIncl = self.sIncl..'#include "'..incl..'"\n'
								if bDEBUG then output:AppendText('> DEBUG: IncludesFromBuffer.Add "#include '.."'"..incl.."'"..'"\n') end
							else
								self.sIncl = self.sIncl..'#include "'..props['FileDir']..'\\'..incl..'"\n'
								if bDEBUG then output:AppendText('> DEBUG: IncludesFromBuffer.Add "#include '.."'"..props['FileDir']..'\\'..incl.."'"..'"\n') end
							end
						end
					end
				end
			end
		end
	end,
	---------------------------------------------------------------------------- /IncludesFromBuffer

	------------------------------------------ create the au3 file for executing the assignment line
	CreateAU3 = function(self, _sLineAssignment)
		local sTextAU3 = self.sIncl..
			'Global $sFileExport = @TempDir & "\\ExecLineColor.txt"\n'..
			'FileDelete($sFileExport)\n'..
			'Global $sLine = "'.._sLineAssignment..'"   ; line: $Variable = assignment\n'..
			'If $sLine = "NONE" Then Exit\n'..
			'Global $sExec = StringTrimLeft($sLine, StringInStr($sLine, "="))\n'..
			'Global $sColor = "0x" & Hex(Execute($sExec), 6)\n'..
			'If Not StringRegExp($sColor, "^0x[0-9A-F]{6}$") Then Exit\n'..
			'FileWrite($sFileExport, $sColor)\n'
		local fH = io.open(self.sPathGetColorAU3, 'w+')
		fH:write(sTextAU3)
		fH:close()
	end,
	------------------------------------------------------------------------------------- /CreateAU3

	--------------------------------- check, if file containing the assignment for selected variable
	FindAssignment = function(self, _path, _sSelection)
		local fH = io.open(_path)
		if fH ~= nil then
			local sRead, boolCmnt, countCmnt, n = fH:read('*all'), false, 0
			fH:close()
			for line in sRead:gmatch('([^\r\n]+)') do
				boolCmnt, n = self:CheckComment(line)
				if boolCmnt then countCmnt = countCmnt + (n) end
				if not boolCmnt and countCmnt == 0 then     -- none comment line or block
					if line:find(_sSelection..'%s*=') then
						if bDEBUG then output:AppendText('> DEBUG: Assignment line  "'..line..'"\n') end
						return line
					end
				end
			end
		end
		return nil
	end,
	-------------------------------------------------------------------------------- /FindAssignment

	-------------------------------------------------------------------- detects color from variable
	GetColorValueFromVariable = function(self, _sSelection, _iCursor, _var_beginPos, _var_endPos, _fBGR)
		local sLine = self:FindAssignment(props['FilePath'], _sSelection)
		if sLine == nil then                -- search inside include files
			-- do it not, if the user has disabled: "Get.Color.Assignment.Includes=0"  (default = 1 - enabled)
			if self.search_in_includes then
				self:IncludesFromBuffer()   -- get include files
				if #self.lIncl.list ~= 0 then
					-- open each include file, search line with assignment "_sSelection ="
					for i=1, #self.lIncl.list do
						if self.lIncl.list[i]:sub(2,2) == ':' then    -- include has full path, search only in this file
							sLine = self:FindAssignment(self.lIncl.list[i], _sSelection)
							if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..self.lIncl.list[i]..'"  --> '..tostring(sLine ~= nil)..'\n') end
						end
						if sLine == nil and self.lIncl.list[i]:find('\\') then     -- include has partial path, check first if exist in @ScriptDir
							sLine = self:FindAssignment(props['FileDir']..'\\'..self.lIncl.list[i], _sSelection)
							if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..props['FileDir']..'\\'..self.lIncl.list[i]..'"  --> '..tostring(sLine ~= nil)..'\n') end
						end
						if sLine == nil then                          -- include has filename only (or partial path),
                                                                      -- .. concanate all directories with this for searching
							for j=1, #self.lInclPathes.list do
								sLine = self:FindAssignment(self.lInclPathes.list[j]..'\\'..self.lIncl.list[i], _sSelection)
								if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..self.lInclPathes.list[j]..'\\'..self.lIncl.list[i]..'"  --> '..tostring(sLine ~= nil)..'\n') end
								if sLine == nil then
									sLine = self:FindAssignment(props['FileDir']..'\\'..self.lIncl.list[i], _sSelection)
									if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..props['FileDir']..'\\'..self.lIncl.list[i]..'"  --> '..tostring(sLine ~= nil)..'\n') end
								end
								if sLine ~= nil then break end
							end
						end
					end
				end
			end
		end

		if sLine == nil then
			sLine = 'NONE'
		else   -- trim characters right from assignment
			sLine = sLine:sub(1,sLine:match(self.pattHexEnd))
		end
		if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" \n> DEBUG: Result "'..sLine..'"\n') end
		-- create the au3-file for executing the assignment line, with 'NONE' - the last result file will delete
		self:CreateAU3(sLine)
		-- run the au3-file
		local sCmd = '"'..self.sAU3exe..'" /AutoIt3ExecuteScript "'..self.sPathGetColorAU3..'"'..' "'..sLine..'"'
		if shell then
			shell.exec(sCmd, nil, true, true)
		else
			os.execute('start "" '..sCmd)
		end

		-- check for result
		local fH = io.open(self.sFileResult)
		if fH == nil then
			scite.SendEditor(SCI_CALLTIPSHOW, _var_beginPos +1, (' NONE COLOR ASSIGNED! '))
			scite.SendEditor(SCI_CALLTIPSETHLT, 0, 22)
			scite.SendEditor(SCI_CALLTIPSETBACK, 0x33FFFF)
			scite.SendEditor(SCI_CALLTIPSETFOREHLT, 0x0000FF)
			scite.SendEditor(SCI_CALLTIPSETPOSITION, true)
			if bDEBUG then output:AppendText('> DEBUG: Set Calltip "'.._sSelection..'" --> "NONE COLOR ASSIGNED!"\n') end
		else
			local sValue = fH:read()
			fH:close()
			local R,G,B = sValue:match('('..self.pattHex2..')('..self.pattHex2..')('..self.pattHex2..')$')
			local iLen = _var_endPos - _var_beginPos -1
			scite.SendEditor(SCI_CALLTIPSHOW, _var_beginPos +1, (' '):rep(iLen))
			scite.SendEditor(SCI_CALLTIPSETHLT, 0, iLen)
			scite.SendEditor(SCI_CALLTIPSETPOSITION, true)
			if _fBGR == true then
				scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', R,G,B)))
				if bDEBUG then output:AppendText('> DEBUG: Set Calltip BGR  "'.._sSelection..'" --> "'..string.format('0x%s%s%s', R,G,B)..'"\n') end
			else
				scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', B,G,R)))
				if bDEBUG then output:AppendText('> DEBUG: Set Calltip RGB  "'.._sSelection..'" --> "'..string.format('0x%s%s%s', B,G,R)..'"\n') end
			end
		end
		self.colortip_show = true
		editor:SetSelection(_iCursor, _iCursor)
	end,
	--------------------------------------------------------------------- /GetColorValueFromVariable

	----------------------------------------- grabs the color value or variable from cursor position
	FromCursor = function(self, _fBGR)
		local function isHexChar(_asc)
			local sChar = string.char(_asc)
			if sChar:find('[#x0-9a-fA-F]') then return true else return false end
		end
		local cursor = editor.CurrentPos

		-- check if cursor is possible inside a variable
		local var_beginPos, var_endPos = cursor
		if string.char(editor.CharAt[cursor]) ~= '$' then   -- cursor is inside or behind the variable (if its a variable)
			editor:WordLeft()                               -- skip to the left
		end
		var_beginPos = editor.CurrentPos

		-- is it a variable?
		if string.char(editor.CharAt[var_beginPos]) == '$' then   -- now the cursor is in front of variable
			editor:WordRight()
			var_endPos = editor.CurrentPos
			editor:SetSelection(var_beginPos, var_endPos)
			local sSelection = editor:GetSelText()
			local iLenSel = sSelection:len()
			-- trim spaces on right site, if any
			sSelection = sSelection:gsub('%s+$','')
			var_endPos = var_endPos - (iLenSel - sSelection:len())
			if bDEBUG then output:AppendText('> DEBUG: Cursor on variable "'..sSelection..'"\n') end
			return self:GetColorValueFromVariable(sSelection, cursor, var_beginPos, var_endPos, _fBGR)
		end

		-- cursor inside hex value?
		local beginPos, endPos = cursor, cursor
		while isHexChar(editor.CharAt[beginPos-1]) do beginPos = beginPos - 1
		end
		while isHexChar(editor.CharAt[endPos]) do endPos = endPos + 1
		end
		if beginPos ~= endPos then
			if beginPos > endPos then
				editor:SetSelection(endPos, beginPos)
			else
				editor:SetSelection(beginPos, endPos)
			end
			local sMatch = tostring(editor:GetSelText()):match(self.pattHexN)
			if sMatch == nil then return editor:SetSelection(cursor, cursor) end
			local sHex6 = '0x'..('0'):rep(6-sMatch:len())..sMatch
			local iLen = sMatch:len() +2
			local R,G,B = tostring(sHex6):match('('..self.pattHex2..')('..self.pattHex2..')('..self.pattHex2..')$')
			if bDEBUG then output:AppendText('> DEBUG: Cursor on hex value\n') end
			editor:SetSelection(cursor, cursor)
			scite.SendEditor(SCI_CALLTIPSHOW, beginPos+1, (' '):rep(iLen-1))
			scite.SendEditor(SCI_CALLTIPSETHLT, 0, iLen-1)
			scite.SendEditor(SCI_CALLTIPSETPOSITION, true)
			if _fBGR == true then
				scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', R,G,B)))
				if bDEBUG then output:AppendText('> DEBUG: Set Calltip BGR hex value --> "'..string.format('0x%s%s%s', R,G,B)..'"\n') end
			else
				scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', B,G,R)))
				if bDEBUG then output:AppendText('> DEBUG: Set Calltip RGB hex value --> "'..string.format('0x%s%s%s', B,G,R)..'"\n') end
			end
			self.colortip_show = true
		else
			editor:SetSelection(cursor, cursor)
		end
	end,
	------------------------------------------------------------------------------------ /FromCursor

	----------------------------------------------------------------------- show back and fore color
	PreviewBackForeColor = function(self, _fFore1st)
		local iBackCol, iForeCol = 0xF0F0F0, 0x000000
		local cursor = editor.CurrentPos
		local sLine, iColumn = editor:GetCurLine()
		local iLineStartPos = cursor - iColumn
		local tMatch, beginPos = {}, nil
		for s, r, g, b in sLine:gmatch(self.pattHex) do
			if beginPos == nil then beginPos = s end
			local t = {} t['R']=r t['G']=g t['B']=b
			table.insert(tMatch, t)
		end
		if #tMatch == 0 then
			if bDEBUG then output:AppendText('> DEBUG: Search back/fore color --> "FAILED"\n') end
			return
		elseif #tMatch == 1 then
			if _fFore1st == true then
				iForeCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R))
				if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "ForeColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end
			else
				iBackCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R))
				if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "BackColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end
			end
		else
			if _fFore1st == true then
				iForeCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R))
				iBackCol = tonumber(string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R))
				if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "ForeColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end
				if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "BackColor" --> "'..string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)..'"\n') end
			else
				iForeCol = tonumber(string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R))
				iBackCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R))
				if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "ForeColor" --> "'..string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)..'"\n') end
				if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "BackColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end
			end
		end
		if bDEBUG then output:AppendText('> DEBUG: Set calltip back/fore color\n') end
		scite.SendEditor(SCI_CALLTIPSHOW, iLineStartPos + beginPos, ' FORE-COLOR ')
		scite.SendEditor(SCI_CALLTIPSETHLT, 0, 12)
		scite.SendEditor(SCI_CALLTIPSETBACK, iBackCol)
		scite.SendEditor(SCI_CALLTIPSETFOREHLT, iForeCol)
		self.colortip_show = true
	end
	-------------------------------------------------------------------------- /PreviewBackForeColor
}
-------------------------------------------------------------------------------------- /object color


---------------------------------------------------------------------------------- region EventClass
ShowColorEvt = EventClass:new(Common)

function ShowColorEvt:OnKey()
	if objColor.colortip_show then
		if bCALLTIP_END_ANYKEY then scite.SendEditor(SCI_CALLTIPCANCEL) end
		objColor:SetCalltipsDefault()
	end
end

function ShowColorEvt:OnDwellStart()
	if objColor.colortip_show then
		if bCALLTIP_END_ANYKEY then scite.SendEditor(SCI_CALLTIPCANCEL) end
		objColor:SetCalltipsDefault()
	end
end
--------------------------------------------------------------------------------- /region EventClass


-------------------------------------------------------------------------- function call redirection
function ShowHexColorFromCursor(_fBGR)
	objColor:FromCursor(_fBGR)
end  --> ShowHexColorFromCursor


function PreviewBackForeColor(_fFore1st)
	objColor:PreviewBackForeColor(_fFore1st)
end  --> PreviewBackForeColor
----------------------------------------------------------------------------------------------------


---------------------------------------------------------------------------------------- run startup
objColor:Startup()
----------------------------------------------------------------------------------------------------

 

 

 

ShowHexColorFromCursor[0.10].lua

Edited by BugFix

Best Regards BugFix  

Link to post
Share on other sites

Very cool

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to post
Share on other sites
  • 2 weeks later...

Very usefull.

Thanks for sharing.
 

btw.
Added here: https://www.autoitscript.com/wiki/SciTE4AutoIt3#Useful_Lua_links_and_scripts

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 for other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2022-03-07

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By BlueSkyMemory
      While Scite doesn't support high dpi, I open it in compatibility settings. But it brings another problem:My au3 app automatically enables high dpi, causing gui disorder.
      I've tried #AutoIt3Wrapper_Res_HiDpi=N but it doesn't work. I'd appreciate it if you could offer some help. Thanks.
    • By edubensa
      Hi! Can someone help me with this? I upgraded from SciTe Edit Lite to full version. Now every time I edit a script it opens on a new SciTe tab, but I want it opens on a new window like before the upgrade. Can someone help me with that? Thanks!!
    • By BugFix
      When posting scripts to platforms that use different tab settings (e.g. GitHub), they are ripped from their formatting.
      Thus, it is better to replace all tabs with spaces in the correct position before posting. I have created the following Lua script for this purpose. It replaces all tabs with the appropriate number of spaces in the document opened in SciTE. By default a tab width of 4 characters is used. But other values are also possible, details about this and the installation and usage are at the beginning of the script.
      -- TIME_STAMP 2022-05-01 11:28:55 v 0.1 --[[ == Installation == • Store the file to "YOUR-PATH/TabReplaceSciTE.lua" • New entry in your "SciTEUser.properties" (find a free command number, in example is "49" used, and a free shortcut) #49 Replace TAB with spaces command.name.49.*=Replace TAB with spaces command.49.*=dofile "YOUR-PATH/TabReplaceSciTE.lua" command.mode.49.*=subsystem:lua,savebefore:no command.shortcut.49.*=Ctrl+Alt+Shift+R • If your sources has different values for TAB width, you can modify the command call in this script (last line), "TabReplace_FileInSciTE(2)" or "TabReplace_FileInSciTE(8)". Or add a property to your "SciTEUser.properties" to have more flexibility: # The currently used tab.size, which is replaced by spaces # Without this property or with empty value "4" is used. tab.replace.width=2 Then change the last line in this script to: TabReplace_FileInSciTE(props['tab.replace.width']) == Usage == • Open any script. • Hit the shortcut. • In the opened document, all TAB will be replaced by the number of spaces corresponding to the TAB position in the line. ]] ---------------------------------------------------------------------------------------------------- --[[ in...: _line A line of text whose TAB are to be replaced by spaces. .....: _tabsize TAB size in number of characters. If it is omitted, 4 is used. out..: The line, with TAB replaced if necessary, and the number of replacements. ]] ---------------------------------------------------------------------------------------------------- TabReplace_Line = function(_line, _tabsize) if _line:find('^[\r\n]+$') then return _line, 0 end -- only a line break if _line == '' then return _line, 0 end -- only a empty string local posTab = _line:find('\t') if posTab == nil then return _line, 0 end -- no TAB included _tabsize = _tabsize or 4 -- default TAB width local tTab, s, sRep, iLen, sumLen = {}, ' ', '', 0, 0 while posTab ~= nil do -- calculation replacement string, taking into account characters to be inserted iLen = (_tabsize - ((posTab + sumLen -1) % _tabsize)) sumLen = sumLen + iLen -1 -- total length of the replacements sRep = s:rep(iLen) -- create replacement string table.insert(tTab, sRep) -- save to table posTab = _line:find('\t', posTab +1) -- find next TAB end local idx = 0 _line = _line:gsub('\t', function() idx = idx +1 return tTab[idx] end) return _line, idx end ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- --[[ Replaces all TAB in the file currently open in SciTE ]] ---------------------------------------------------------------------------------------------------- TabReplace_FileInSciTE = function(_tabsize) local caret = editor.CurrentPos local fvl = editor.FirstVisibleLine local content = '' if _tabsize == '' then _tabsize = nil end for i=0, editor.LineCount -1 do local line = editor:GetLine(i) line = line or '' line = TabReplace_Line(line, _tabsize) content = content..line end editor:BeginUndoAction() editor:ClearAll() editor:InsertText(0, content) editor:EndUndoAction() editor.CurrentPos = caret editor:SetSel(caret, caret) editor.FirstVisibleLine = fvl end ---------------------------------------------------------------------------------------------------- TabReplace_FileInSciTE(4) -- If required: Change the TAB size here  
      TabReplaceSciTE.lua
    • By mrider
      Greetings all,
      I went looking around for dark themes for SciTE and didn't have much luck.  No wish to necro-post, but I found this post -> A dark theme for SciTE but it seems as if things were ended at a single change for AutoIt where I was hoping for a comprehensive dark theme.  I currently have a dark desktop in Mint where xed, the terminal emulator, vim, and etcetera do an acceptable job of showing the dark theme.  Then I load SciTE and get blinded.  To resolve this, I'm currently working on creating a set of lang.properties files that use the Solarized themes (both light and dark).  The mechanism is simple enough: I wrote a small Perl program which parsed all the properties files and extracted all the distinct color values.  Then I assigned indexes to all the distinct colors, and wrote the colors themselves out to a separate properties file.  Next I parsed that and I used the formula for reducing the color palette to fewer colors as a baseline for generating the Solarized light theme - which turned out surprisingly less awful than I would have guessed.  Next I generated a color theme where all the colors are reversed for the Solarized dark theme.  The result is dark, but the individual source files I look at still need more help (Perl was particularly bad).  At this point, it is possible on my computer to switch to either the Solarized light or dark theme with one line of text in my user options file.
      Now I'm working my way through source-code cleaning up the result.  My first stop is completing Perl, but AutoIt is my next stop.  I'm happy to put the modified files out there for all to use (if you want them).
      I'm willing to do all the legwork for all the properties files.  The problem is that I'm only familiar with some of the languages that SciTE recognizes (for example - I wouldn't know Baan if it bit me on the butt).  I looked all around both the Solarized website and the Scintilla/SciTE website, and I can't find any reference files that can be used to test the colors.  Which means that any language I don't understand will get the colors chosen by the algorithm, which is admittedly fairly rough. 
       
      Which leads me to this post: What would be particularly useful would be code samples in different languages.  The more of the style numbers that are touched in that language the better.  I don't care if the code is "quality" code, I'm more interested in whether the code snip is properly colorized (for some values of "proper").  I understand that nobody is obligated to help me with "my project".  However, I promise that I will do my best with any code snips in any language and I will post the results here.  I'm using xed and vim as my templates, so my results will (mostly) resemble results there.
      I'll post my work here as time progresses, I'll probably have a working version for Perl and AutoIt in the next few days, and I'll do my best with other languages going forward.  As I say, I welcome code snips in any language that SciTE colorizes using a properties file.
       
      Edit1: Attached is the first Solarized Version.  I have only tested this in the default install of SciTE.  I'm certain there are going to be differences between the default install and the full version, but I don't yet know what those differences will be.  To use this:
      Detach the zip file. Drop the folder into your profile directory.  For example: C:\Users\mrider\Solarized . Open your local options file in SciTE (Options -> Open User Options File). Add the line "import Solarized\SolarDark" (without the quotes) to your file. You can turn the dark theme on and off with a comment character (#) at the beginning of the statement. Enable "Solar Light" theme similarly using "import Solarized\SolarLight". As I say, this doesn't work in the full version, so only use this if you are using the basic version.  I'll chase the full version next.
       
      Edit2: Attached is the second Solarized Version.  This works with the full install of SciTe, but so far I've only tested it with Autoit, Batch Files, and Perl.  I'll keep expanding the languages as I go.  To use this:
      Detach the zip file. I had to navigate to "C:\Program Files (x86)\AutoIt3\SciTE" and relax the file permissions to perform the next step. Drop the folder in the SciTE install directory (it doesn't seem to work in one's profile directory). Open your local options file in SciTE (Options -> Open User Options File) - note that this opens the user properties file inside the SciTE directory, not your profile. Add the line "import Solarized\SolarDark" (without the quotes) to your file. You can turn the dark theme on and off with a comment character (#) at the beginning of the statement. Enable "Solar Light" theme similarly using "import Solarized\SolarLight".  
      Solarized_AutoIt_SciTE_version_only.zip
      Solarized_SciTE_Full_Install.zip
    • By beautifulsoup
      Hi All,
      I'm not sure if its possible that I'm trying to achieve, I've looked into https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/AutoIt3Wrapper.html and such resources for help, but I cant really find the answer to my question.
      So upon compiling the script in SciTE, the exe file is given a Description under file Properties>Details. I understand, that  one can enter info manually there and it can even implement the version automatically with each compilation.
       
      What I'm trying to achieve is to somehow include the "@ScriptName" in the Details>File Description Field. But as I see no variable can be taken after "#" in this case.
       
      Do You think its achievable? (Win 10)
       
      Much obliged for taking time on reading this.
       
      Kind Regards,
      Brave


×
×
  • Create New...