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

Help needed removing cursor from code

Started by MalumAtire832, 24 April 2013 - 02:41 AM
MalumAtire832 #1
Posted 24 April 2013 - 04:41 AM
Title: Help needed removing cursor from code

so i have been using this mod for a while now and i am making a little setup for my self
i am making a start screen in which you can enter various commands, now here's the question,
i am trying to hide the cursor but it isn't working, i used this code[see link 1]
and because of that it looks like this[see link 2]
i want it to look like this[see link 3] but can't get it to work, help me please ;)/>

code: http://pastebin.com/ygYKYeBS
now: http://www.dropviewer.com/v.php?i=51769e1e7145d.png
what i want it to be like: http://www.dropviewer.com/v.php?i=51769df5e9c1a.png

Thank you
LBPHacker #2
Posted 24 April 2013 - 05:20 AM
That ">" has been put there by the Shell - that's because your program reaches its end immediately. There's no call to read in your program. BTW calling read sets the cursor-blink on again - you have to write your own read function if you want the cursor to disappear.
remiX #3
Posted 24 April 2013 - 05:29 AM
That ">" has been put there by the Shell - that's because your program reaches its end immediately. There's no call to read in your program. BTW calling read sets the cursor-blink on again - you have to write your own read function if you want the cursor to disappear.
Hmm, just overriding the function should work?

local oldCurBlink = term.setCursorBlink
term.setCursorBlink = function() oldCurBlink(false) end
local user = read()

Then where you want to have it blink use oldCurBlink(true)
MalumAtire832 #4
Posted 24 April 2013 - 05:48 AM
That ">" has been put there by the Shell - that's because your program reaches its end immediately. There's no call to read in your program. BTW calling read sets the cursor-blink on again - you have to write your own read function if you want the cursor to disappear.
Hmm, just overriding the function should work?

local oldCurBlink = term.setCursorBlink
term.setCursorBlink = function() oldCurBlink(false) end
local user = read()

Then where you want to have it blink use oldCurBlink(true)
thank you it worked :D/>
but… now when i type in a command for example "hello world'' and press enter it skips to a new line.
then i have to type it again in order to let the computer say it,
How do i fix this?
remiX #5
Posted 24 April 2013 - 06:11 AM
What's the latest code you're using now?
MalumAtire832 #6
Posted 24 April 2013 - 06:14 AM
What's the latest code you're using now?
the 3 lines you gave me earlier
remiX #7
Posted 24 April 2013 - 06:17 AM
Well that's all the program has. It will just wait for an input and then stop.

What do you wan't it to do?
MalumAtire832 #8
Posted 24 April 2013 - 07:12 AM
i want it to be like the normal computer i just want to get rid of the ">" but i want to keep the blinking "-"
so i want it to be like a normal computer that accepts commands and can do everything a normal one can do exept for the ">"to show on the program screen
the rest of the code is like when you start up windows

screen 1. brand and build NR. (in my case "Malum.INC MainFrame V2.1")
screen 2. normal OS screen (in my case: Welcome
Enter command: >_ (without the >))

i basicly want it to be like the command prompt in windows
remiX #9
Posted 24 April 2013 - 07:49 AM
Oh … okay…
Something like this?
if fs.getName( shell.getRunningProgram() ):lower() ~= "startup" then
    local f = fs.open( shell.getRunningProgram(), "r" )
    local thisContent = f.readAll()
    f.close()
    local f = fs.open( "startup", "w" )
    f.write( thisContent )
    f.close()
    fs.delete( shell.getRunningProgram() )
    os.reboot()
end

term.clear()
term.setCursorPos( 1, 1 )

while true do
    term.setTextColour( colours.yellow )
    write( "Enter command: " )
    term.setTextColour( colours.white )
    local cmd = read()
    if fs.exists( cmd ) then
        shell.run( cmd )
    else
        printError( "No such program" )
    end
end

Not sure how to imitate a proper shell :P/> but oh well!
MalumAtire832 #10
Posted 24 April 2013 - 08:19 AM
Oh … okay…
Something like this?
if fs.getName( shell.getRunningProgram() ):lower() ~= "startup" then
	local f = fs.open( shell.getRunningProgram(), "r" )
	local thisContent = f.readAll()
	f.close()
	local f = fs.open( "startup", "w" )
	f.write( thisContent )
	f.close()
	fs.delete( shell.getRunningProgram() )
	os.reboot()
end

term.clear()
term.setCursorPos( 1, 1 )

while true do
	term.setTextColour( colours.yellow )
	write( "Enter command: " )
	term.setTextColour( colours.white )
	local cmd = read()
	if fs.exists( cmd ) then
		shell.run( cmd )
	else
		printError( "No such program" )
	end
end

Not sure how to imitate a proper shell :P/> but oh well!
it works but now when i type in commands like "reboot","snake","label" ETC it says no such program.
this also could be my fould for typing it wrong our the code doesn't work?
do you have any idea what i may have done wrong

PS. im a n00b at this so most of it is gibberish for me. i understood some things in the code, like the second part. from term.clear() till the end of it.
if i may ask… how did you learn all this?
LBPHacker #11
Posted 24 April 2013 - 08:23 AM
You don't have to check for existence when using shell.run - it will complain for you if it can't find the file.
PixelToast #12
Posted 24 April 2013 - 08:24 AM
its because you need to check in rom/programs/ too
it will be easier to just copy the functions in the shelll program
remiX #13
Posted 24 April 2013 - 08:38 AM
its because you need to check in rom/programs/ too
it will be easier to just copy the functions in the shelll program

Yeah I looked at it afterwards, was like meh and went to go play a game :P/>
MalumAtire832 #14
Posted 24 April 2013 - 08:51 AM
Ah never mind I will just use the ">" I am going to study the base formules of LUA first.
any suggestions where to start?
The wiki isn't that clear for me. :P/>
SuicidalSTDz #15
Posted 24 April 2013 - 08:56 AM
Read the wiki or read the Lua reference manual.