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

De Adadov.net wiki
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 10 : Ligne 10 :
for line in text:gmatch("[^\n]+") do
for line in text:gmatch("[^\n]+") do
local newline
if sameCommand then
if sameCommand then
line = "> "..line
newline = "> "..line
sameCommand = false
sameCommand = false
else
else
line = prompt..line
newline = prompt..line
end
end
Ligne 20 : Ligne 21 :
sameCommand = true
sameCommand = true
end
end
result = result..line
result = result..newline.."<br />"
end
end



Version du 5 février 2015 à 19:56

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.."<br />"
	end

	return result
end

return p