This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
crackroach's profile picture

term.clearLine() EVOLVED

Started by crackroach, 05 December 2012 - 07:57 AM
crackroach #1
Posted 05 December 2012 - 08:57 AM
I'm clearly not experimented enough to make a function like this, so if anyone could help me make this I'll be happy.

Here's the idea: a function that clear only a specific part on a line.

I got an idea on how to make it, but not how to script it.

Thanks
billysback #2
Posted 05 December 2012 - 09:03 AM
Code:

local function clearLine(y)
   local tx,ty = term.getSize()
   local empty = ""
   for i=1,tx do empty = empty.." " end
   term.setCursorPos(1,y)
   term.setBackgroundColor(colors.black)
   term.setTextColor(colors.white)
   term.write(empty)
end
Lyqyd #3
Posted 05 December 2012 - 09:45 AM
That just does what clearLine already does, except that you have to specify the line instead of it using the line you're currently on. His suggestion was a function that clears only part of a line.
crackroach #4
Posted 05 December 2012 - 10:00 AM
That just does what clearLine already does, except that you have to specify the line instead of it using the line you're currently on. His suggestion was a function that clears only part of a line.

Yeah it would simplify the clearing part of login or even information in a graphic. I've tried to make a function like that myself, but i don't know how to keep whats already written on a line and clear the part i don't want…to resume: i just don't know… :lol:/>
Cranium #5
Posted 05 December 2012 - 10:00 AM

function clearPart(x1, x2, y)
    term.setCursorPos(x1, y)
    local xCur = x1
    repeat
	    write(" ")
	    xCur = xCur + 1
    until xCur == x2
end
Fairly simple. Specify the line ( y ) that you want to start on, the beginning x position ( x1 ), and ending x position ( x2 ).
billysback #6
Posted 05 December 2012 - 10:08 AM
There's a clearLine() function???
I didn't realize that was your suggestion however…
crackroach #7
Posted 05 December 2012 - 10:10 AM

function clearPart(x1, x2, y)
	term.setCursorPos(x1, y)
	local xCur = x1
	repeat
		write(" ")
		xCur = xCur + 1
	until xCur == x2
end
Fairly simple. Specify the line ( y ) that you want to start on, the beginning x position ( x1 ), and ending x position ( x2 ).

Thanks Cranium, can I use that function in a program that I'm gonna make public?



There's a clearLine() function???
I didn't realize that was your suggestion however…

Thank you billysback, I appreciate the help you gave me.
Cranium #8
Posted 05 December 2012 - 10:17 AM
Of course you can. Code that gets posted here is usually public anyway…
MysticT #9
Posted 05 December 2012 - 11:53 AM
A slightly shorter version without loops:

local function clearPart(x1, x2, y)
  term.setCursorPos(x1, y)
  term.write(string.rep(" ", (x2 - x1) + 1))
end