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

De Adadov.net wiki
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 8 : Ligne 8 :
local result = ""
local result = ""
local sameCommand = false
local sameCommand = false
print(text)
for line in text:gmatch("[^\n]+") do
for line in text:gmatch("[^\n]+") do

Version du 5 février 2015 à 19:28

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 16 : attempt to concatenate local 'prompt' (a nil value).

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

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

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

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

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

Erreur Lua à la ligne 16 : 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
		if sameCommand then
			line = "> "..line
			sameCommand = false
		else
			line = prompt..line
		end
		
		if line:find("\\") then
			sameCommand = true
		end
		result = result..line.."\n"
	end

	return result
end

return p