Lua   发布时间:2022-04-12  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了仿对比软件的对比功能大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
require "iuplua"
require "iupluacontrols"

--iup.message("abc","def")

--[[
fileDlg = iup.filedlg{dialogtype = "save",title = "file save",filter = "*.bR_984_11845@p",filerinfo = "Bitmap files",directory = "C:\\Windows"}

fileDlg:popup(iup.anywhere,iup.anywherE)
--]]

--fl = io.open("E:\\Program\\Lua\\Scrawl\\cander.lua")

--for line in fl:lines() do print(linE) end

local isOnlyShowDiff = false

local tabTxtFileLeft,tabTxtFileRight = {},{}

function openFile(filePath)
	local tab = {} --clear
	local flh = io.open(filePath)
	for line in flh:lines() do 
		tab[#tab + 1] = {}
		tab[#tab].str = line 
	end
	--for _,v in ipairs(tab) do print(v) end
	return tab
end

btnAll = iup.button{title = "Show All",id = 1}
btnOnly = iup.button{title = "Only Show Difference",id = 2}

--print(iup.button1)
--[[
print(type(iup))
for k,v in pairs(iup) do 
	if type(v) == "number" then
		print(k,v) 
	end
end
--]]

function changeShow(ih,but,pressed,x,y,stat)
	--print(ih.id)
	--print(but,pressed)
	if(but == iup.bUTTON1 and pressed == 0) then
		--print(ih.id)
		--isOnlyShowDiff = not isOnlyShowDiff
		if tonumber(ih.id) == 1 then
			isOnlyShowDiff = false
		else
			isOnlyShowDiff = true
		end
		print(isOnlyShowDiff)
	end
end

btnAll.button_cb,btnOnly.button_cb = changeShow,changeShow

hbox1 = iup.hbox{BtnAll,btnOnly; margin = "3x3",gap = "2"}

slnLeft = iup.text{size = "300x",value = ""}
btnLeft = iup.button{title = "Browse"}
hbox2 = iup.hbox{slnLeft,btnLeft; margin = "3x3",gap = "2"}

mlnLeft = iup.multiline{size = "450x400",value = "",readonly = "yes",formatTing = "yes"}

--[[
tags = iup.user{Bulk = "Yes",cleanout = "Yes"}
iup.Append(tags,iup.user{@R_801_10288@ction = "1,1:1,10",fgcolor = "255 0 0"})
iup.Append(tags,iup.user{@R_801_10288@ction = "2,1:2,fgcolor = "0 255 0"})
iup.Append(tags,iup.user{@R_801_10288@ction = "3,1:3,bgcolor = "100 255 255"})
--mlnLeft.addformattag = tags

function mlnLeft.caret_cb(ih,lin,col,pos)
	str = lin..",1:"..lin..",100"
	tags2 = iup.user{Bulk = "yes",cleanout = "Yes"}
	iup.Append(tags2,iup.user{@R_801_10288@ction = str,bgcolor = "255 0 255"})
	mlnLeft.addformattag = tags2
	print(lin,pos,str)
end
--]]

vbox1 = iup.vbox{hbox2,mlnLeft}

slnRight = iup.text{size = "300x",value = ""}
btnRight = iup.button{title = "Browse"}
hbox3 = iup.hbox{slnRight,btnRight; margin = "3x3",gap = "2"}

flDlg = iup.filedlg{dialogtype = "OPEN",title = "Open File",filter = "*.*",directory = "D:\\"}

--[[
xxa = "abc"
print("abc" == "abc")
print(xxa == "abc")
xxb = "abc"
print(xxa == xxb)
--]]
--like max-len common sub-squeue problem
function markLabel(p,i,j,tab1,tab2)
	if i == 0 or j == 0 then 
		for k = 1,i do tab1[k].label = 0 end
		for k = 1,j do tab2[k].label = 0 end
		return 
	end
	local a
	local b
	if j == 1 then a = 0 else a = p[i][j - 1] end
	if i == 1 then b = 0 else b = p[i - 1][j] end
	if p[i][j] == a then
		tab2[j].label = 0
		return markLabel(p,j - 1,tab2)
	elseif p[i][j] == b then
		tab1[i].label = 0
		return markLabel(p,i - 1,tab2)
	else
		tab1[i].label,tab2[j].label = 1,1
		return markLabel(p,tab2)
	end
end

function computeDiff(tab1,tab2)
	local p = {}
	local n,m = #tab1,#tab2
	for i = 1,n do p[i] = {} end
	
	for i = 1,n do
		for j = 1,m do
			local a
			local b
			if j == 1 then a = 0 else a = p[i][j - 1] end
			if i == 1 then b = 0 else b = p[i - 1][j] end
			if tab1[i].str == tab2[j].str then
				p[i][j] = math.max(a,b) + 1
			else
				p[i][j] = math.max(a,b)
			end
		end
	end
	markLabel(p,n,m,tab2)

--[[
	for i = 1,n do
		print(i,tab1[i].label,tab2[i].label)
	end
--]]
end

mlnRight = iup.multiline{size = "450x400",formatTing = "yes"}
vbox2 = iup.vbox{hbox3,mlnRight}

hbox4 = iup.hbox{vbox1,vbox2}

vbox3 = iup.vbox{hbox1,hbox4}

function showResult()
	local tagsLeft = iup.user{Bulk = "Yes",cleanout = "Yes"}
	local tagsRight = iup.user{Bulk = "Yes",cleanout = "Yes"}

	local strLeft = ""
	local strRight = ""
	for i = 1,#tabTxtFileLeft do
		if isOnlyShowDiff then
			strLeft = strLeft .. "\n"
		else
			strLeft = strLeft .. tabTxtFileLeft[i].str .. "\n"
		end

		if tabTxtFileLeft[i].label == 0 then
			iup.Append(tagsLeft,iup.user{@R_801_10288@ction = i .. ",1:" .. i .. ",500",fgcolor = "200 0 0"})
		else
			iup.Append(tagsLeft,fgcolor = "0 200 0"})
		end
	end

	for i = 1,#tabTxtFileRight do
		if isOnlyShowDiff then
			strRight = strRight .. "\n"
		else
			strRight = strRight .. tabTxtFileRight[i].str .. "\n"
		end

		if tabTxtFileRight[i].label == 0 then
			iup.Append(tagsRight,fgcolor = "0 0 200"})
		else
			iup.Append(tagsRight,fgcolor = "0 200 0"})
		end
	end

	print(strLeft,strRight)

	mlnLeft.value,mlnRight.value = strLeft,strRight
	mlnLeft.addformattag = tagsLeft
	mlnRight.addformattag = tagsRight
end

function @R_801_10288@ctFile(ih,stat)
	if but == iup.bUTTON1 and pressed == 0 then
		flDlg:popup(iup.ANYWHERE,iup.ANYWHERE)
		--print(flDlg.@R_673_7548@
		if ih == btnLeft and flDlg.value ~= nil then
			slnLeft.value = flDlg.value
			tabTxtFileLeft = openFile(flDlg.@R_673_7548@
			--print(#tabTxtFileLeft)
			--for _,v in ipairs(tabTxtFileLeft) do print(v.str) end
			--print(flDlg.@R_673_7548@
		elseif ih == btnRight and flDlg.value ~= nil then
			slnRight.value = flDlg.value
			tabTxtFileRight = openFile(flDlg.@R_673_7548@
		end

		if slnLeft.value ~= nil and slnLeft.value ~= "" and slnRight.value ~= nil and slnRight.value ~= "" then
			--print(slnLeft.value,slnRight.@R_673_7548@
			--print("asdgasg",slnRight.@R_673_7548@
			computeDiff(tabTxtFileLeft,tabTxtFileRight)
			showResult()
			iup.Flush()
		end
	end
end

btnLeft.button_cb,btnRight.button_cb = @R_801_10288@ctFile,@R_801_10288@ctFile

dlg = iup.dialog{vbox3; title = "Contrast Soft"}
dlg:show()

iup.MainLoop()

大佬总结

以上是大佬教程为你收集整理的仿对比软件的对比功能全部内容,希望文章能够帮你解决仿对比软件的对比功能所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: