« Module:LxTerm » : différence entre les versions

De Adadov.net wiki
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 21 : Ligne 21 :
sameCommand = true
sameCommand = true
end
end
result = result..newline.."<br />"
result = result..newline.."\n"
end
end


return result
return "<pre>"..result.."</pre>"
end
end


return p
return p

Version du 5 février 2015 à 19:58

Documentation icon Documentation Module[voir] [éditer] [historique] [purger]

Ce module implémente {{LxTerm}}, il met en forme les lignes de commande et ajoute les prompt.

{{#invoke:LxTerm|main|cmdnum=1|user=root|text=test \
test2}}

Erreur Lua à la ligne 17 : attempt to concatenate local 'prompt' (a nil value).

{{#invoke:LxTerm|main|cmdnum=1|user=root|text=test
test2}}

Erreur Lua à la ligne 17 : attempt to concatenate local 'prompt' (a nil value).

{{#invoke:LxTerm|main|user=nobody|text=test2}}

Erreur Lua à la ligne 17 : attempt to concatenate local 'prompt' (a nil value).

{{#invoke:LxTerm|main|text=test3}}

Erreur Lua à la ligne 17 : attempt to concatenate local 'prompt' (a nil value).

local documentation = require('Module:Documentation').main

local p = {}

function p.main(frame)
	local text = frame.args.text
	local prompt = frame.args.prompt
	local result = ""
	local sameCommand = false
	
	for line in text:gmatch("[^\n]+") do
		local newline
		if sameCommand then
			newline = "> "..line
			sameCommand = false
		else
			newline = prompt..line
		end
		
		if line:find("\\") then
			sameCommand = true
		end
		result = result..newline.."\n"
	end

	return "<pre>"..result.."</pre>"
end

return p