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

Emulated Window

Started by KingMachine, 01 August 2012 - 05:56 PM
KingMachine #1
Posted 01 August 2012 - 07:56 PM
So I've got this window emulator type of deal going…but I'm at a loss as to what I should do about this problem;
http://imgur.com/yp9PI

Should I do an os.pullEvent('key') and just redraw it then reset the cursor back to where it was?
I don't want to have to do that man…am I gonna have to do that? Is there a way to write without pushing the line? Please don't do this to me…Those symbols at the end of that line vary with screen size..that's a lot of logic to have to break down…(quantity wise, not quality, but still)
MysticT #2
Posted 01 August 2012 - 08:03 PM
You'r using read() right? It clears the screen from the cursor to the end of the line, that's why the symbol disapears. You'll have to write your own read function (you can copy the one in bios.lua and modify it) that doesn't clear the last character.
KingMachine #3
Posted 01 August 2012 - 08:08 PM
I'm actually not using read….in fact, this is after self successful termination (Yeah, I totally derped, I know). Perhaps I should just work on an os.pullEvent('key') buffer. That wouldn't kill my symbols right?
PS:
even though I'm working on an OS, I don't believe in modifying the CC rom or bios in anyway other than adding apis. My reasoning is for compatibility.

EDIT:

Had another idea..
parallel(waitInput, fixWindow)

where
waitInput would be

input = read()

and fixWindow would be
if os.pullEvent('key') then
redrawTheLineForTyping()
end

(psuedo code, but you get my point)

Then I COULD use read(), (which I wasn't even using before, but will make things easier in the long run…)
but I'd still have to manually restore my window…
MysticT #4
Posted 01 August 2012 - 08:14 PM
Then what do you use to get the input? If it's your own function, just modify it to keep the last character.
To make a read function you just need a loop that gets the "key" and "char" events, so you add all the chars pressed to a buffer (a table or string) and write them to the screen, and when the enter key is pressed just break the loop.
KingMachine #5
Posted 01 August 2012 - 09:54 PM
I didn't have anyway to get the input yet. Like I said, I derped hard. And yes, I'm aware of how I would do a buffer. I'm more or less asking if my idea is correct, not how to perform my idea. Looking for logic, not lua.
Lyqyd #6
Posted 02 August 2012 - 02:56 AM
And we're telling you that that "problem" is intrinsic to the read() function, and won't be an issue if you make your own read function that doesn't clear the whole line, which is not a terribly difficult thing to do.
BigSHinyToys #7
Posted 02 August 2012 - 03:38 AM
I had a similar problem with the WIFI section of [CC1.3] BENCH v0.9 multi perpous testing utility
every time a new message would be recived it would over rite part of the screen I solved it by making a routine to redraw this part over the screen.I did like you are thinking of doing i used coroutines raw thought not using the parallel functions it may be of help to look at that. the WIFI section of BENCH 0.9 should work septate to the rest of BENCH.


or
copy read() to something like safeRead() then replace the term.clearLine with a write(string.rep(" ",lengthOfstring+1)) and it will only affect the part of the screen with text on it.
Cranium #8
Posted 02 August 2012 - 03:06 PM
I also had this overwriting problem, and I fixed it by using the parallel API to create a function that would redraw my borders and "stationary" images at the beginning of every new function and at the end of every function. It really helped, but I don't know if it would help you, since it is a PAIN to do…
KingMachine #9
Posted 02 August 2012 - 05:06 PM
Cool, so I guess redrawing looks like the acceptable course of action here. Thanks guys.
EDIT: (I'm not editing the rom for purity's sake)
Lyqyd #10
Posted 02 August 2012 - 06:04 PM
No one suggested editing the rom.
KaoS #11
Posted 03 August 2012 - 09:34 AM
but WHY??? I would advise you to just write a very simple program for accepting input, you haven't posted your code but redrawing a window needs a fair amount, checking screen size and accommodating for it etc, every time you press a key it will have to redo all of that so you will end up using so much more system resources, personally I am very purist in that I would easily prefer to manually type out 5 pages of coding than let my code be inefficient and slow… maybe it's just me but I think rewriting the read() function would be easier as you already have it, you just need to change it
KingMachine #12
Posted 03 August 2012 - 05:11 PM
And the vote has been swayed…editing the read command would be best.
Also lyqyd I don't know why I assumed the rom would have to be editted. I was thinking that i would have to edit the read function in the computer, but then I realized I could just make an editted copy in my api. My bad.