Jump to content




Replace term so top row is not used


  • You cannot reply to this topic
14 replies to this topic

#1 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 14 October 2015 - 09:15 PM

I am trying to replace parts of the term API so that nothing can use the top row of the window. So, this is what I have now for new functions:
function _G.term.setCursorPos(x, y)
oldtermsetcursorpos(x, y+1)
end

function _G.term.getSize()
local x, y = oldtermgetsize()
return x, (y-1)
end

function _G.term.getCursorPos()
local x, y = oldtermgetcursorpos()
return x, (y+1)
end
But, then it results in this:
Attached Image: screenshot (2).png
It normally looks like this:
Attached Image: screenshot (3).png

Am I missing a function that would need to be replaced as well?

NOTE: I am showing this with the Northbridge Terminal OS rather than CraftOS because CraftOS with these modifications doesn't work properly in Mimic at least. It doesn't print anything then. I am currently using Mimic for testing as I am on my Chromebook at this moment.

Edited by Selim, 14 October 2015 - 09:31 PM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 14 October 2015 - 09:30 PM

The simple way is to define a window that covers the area of the screen you wish to use, then just term.redirect() to that.

#3 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 14 October 2015 - 09:33 PM

I will look into that.

Edited by Selim, 14 October 2015 - 09:36 PM.


#4 TYKUHN2

  • Members
  • 210 posts
  • LocationSomewhere in this dimension... I think.

Posted 14 October 2015 - 10:30 PM

I cannot test because CraftOS as you stated hates this change, but what I suspect is when your printing it is printing to y+1 which sets the pos to y+1 which then next run adds another 1 effectively y+2

Basically detect if y = old 0 then return y+1 else return Y position.

#5 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 15 October 2015 - 01:37 PM

I figured it out, I needed to y-1 in term.getCursorPos() instead of y+1.

#6 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 17 October 2015 - 06:10 PM

View PostSelim, on 15 October 2015 - 01:37 PM, said:

I figured it out, I needed to y-1 in term.getCursorPos() instead of y+1.
If you try to run programs you need to overwrite os.pullEvent, too. (If you want correct events).

#7 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 18 October 2015 - 06:07 AM

View PostSelim, on 15 October 2015 - 01:37 PM, said:

I figured it out, I needed to y-1 in term.getCursorPos() instead of y+1.
Perhaps you could just simply check one thing
function _G.term.setCursorPos(x, y)
  if y == 1 then
    y = 2
  end
  oldtermsetcursorpos(x, y+1)
end


#8 valithor

  • Members
  • 1,053 posts

Posted 18 October 2015 - 06:12 AM

View PostDragon53535, on 18 October 2015 - 06:07 AM, said:

View PostSelim, on 15 October 2015 - 01:37 PM, said:

I figured it out, I needed to y-1 in term.getCursorPos() instead of y+1.
Perhaps you could just simply check one thing
function _G.term.setCursorPos(x, y)
  if y == 1 then
	y = 2
  end
  oldtermsetcursorpos(x, y+1)
end

The only problem with doing the if statement would be the fact you wouldn't be able to print to the second line. If you put in 1, then it would end up being 3, 2 would end be 3 as well. Either way creating a window is the smarter thing to do as bomb suggested, since simple overwrites like these could lead to unexpected results, things not behaving how they would expected to, or bypasses (for his solution simply passing 0 will write to the first line).

edit:

Just putting the addition in a else would fix the problem, but it would still have the problem of passing 0.

function _G.term.setCursorPos(x, y)
  y = y <= 1 and 1 or y
  oldtermsetcursorpos(x, y+1)
end

Edited by valithor, 18 October 2015 - 06:18 AM.


#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 October 2015 - 06:37 AM

View Postvalithor, on 18 October 2015 - 06:12 AM, said:

(for his solution simply passing 0 will write to the first line).

Eh?

#10 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 18 October 2015 - 09:39 AM

View PostBomb Bloke, on 18 October 2015 - 06:37 AM, said:

View Postvalithor, on 18 October 2015 - 06:12 AM, said:

(for his solution simply passing 0 will write to the first line).

Eh?
Valithor was referring to Dragons code. If you enter 0 for the Y coord it would increase it by 1 (so it becomes 1).

Edited by H4X0RZ, 18 October 2015 - 09:40 AM.


#11 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 18 October 2015 - 12:53 PM

I'd go with BombBloke's suggestion for this, just create a new window object and redirect to that
--# Get the size of the screen
local w, h = term.getSize()

--# Create the window object
local win = window.create( term.current(), 1, 2, w, h - 1, true )

--# Redirect to the window object
term.redirect( win )

--# Test it
term.setBackgroundColor( colors.white )
term.clear()


#12 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 19 October 2015 - 02:20 PM

Derpity Derp, forgot to actually edit that bottom line, as well as check for zero and less.

function _G.term.setCursorPos(x, y)
  y = y < 2 and 2 or y
  oldtermsetcursorpos(x, y)
end
I don't know if i'm right in assuming that 1.92 will write on the first line due to truncation, or if the Java side actually rounds it.

Edited by Dragon53535, 19 October 2015 - 02:23 PM.


#13 Konlab

  • Members
  • 595 posts
  • LocationKerbin

Posted 19 October 2015 - 02:24 PM

View PostDragon53535, on 19 October 2015 - 02:20 PM, said:

Derpity Derp, forgot to actually edit that bottom line, as well as check for zero and less.

function _G.term.setCursorPos(x, y)
  y = y < 2 and 2 or y
  oldtermsetcursorpos(x, y)
end
I don't know if i'm right in assuming that 1.92 will write on the first line due to truncation, or if the Java side actually rounds it.
Throw errors instead of doing this if y is less than 2 (or set cursor pos to 0). But using the window API is better

Edited by Konlab, 19 October 2015 - 02:25 PM.


#14 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 19 October 2015 - 10:32 PM

View PostKonlab, on 19 October 2015 - 02:24 PM, said:

Throw errors instead of doing this if y is less than 2 (or set cursor pos to 0). But using the window API is better
For something simplistic, i would agree with you there, however my solution works on normal computers as well as if someone were to use the TLCO it would still work.

#15 valithor

  • Members
  • 1,053 posts

Posted 19 October 2015 - 11:19 PM

View PostDragon53535, on 19 October 2015 - 10:32 PM, said:

View PostKonlab, on 19 October 2015 - 02:24 PM, said:

Throw errors instead of doing this if y is less than 2 (or set cursor pos to 0). But using the window API is better
For something simplistic, i would agree with you there, however my solution works on normal computers as well as if someone were to use the TLCO it would still work.

Throwing errors would be a horrible solution. The entire point of this is to just remove the ability to write to the first line, without changing any funcitonality, which throwing errors would.

The only problem with only changing term.setCursorPos is then anything that uses term.getCursorPos would be 1 line off (in setCursorPos line 2 would be treated as line 1, while in getCursorPos line 2 is treated as line 2).

Either way it doesn't matter. The windows solution has been mentioned numerous times as the best solution, so there really shouldn't be any reason to continue to discuss another one.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users