Jump to content




Moving the cursor while read() 'ing. (Login GUI)

computer command lua

2 replies to this topic

#1 VaccinesForAids

  • New Members
  • 1 posts

Posted 21 June 2017 - 04:38 AM

Essentially, I'm trying to incorporate the ability to move the user's cursor back and forth between "User:" and "Pass:" areas of my login page. However i have absolutely no idea or the drive to want to try over and over to accomplish it.

So, here is the code.


os.pullEvent = os.pullEventRaw
os.loadAPI("/.LOGIN/.API/modem")
local modem = modem.modSide()
if modem ~= nil then
  modem = modem
else
  print("No Connection")
  sleep(10)
  os.reboot()
end

function login()
  term.clear()
  term.setTextColor(colors.green)
  print("Encrypted										  ")
  term.setTextColor(colors.red)
  print("												   ")
  print("												   ")
  print("												   ")
  print("												   ")
  print("												   ")
  print("												   ")
  print("												   ")
  print("					User:						  ")
  print("					Pass:						  ")
  print("												   ")
  print("												   ")
  print("												   ")
  print("												   ")
  print("												   ")
  print("												   ")
  print("												   ")
  print("										 Login v2.0")
  User()
end

local function readFile(file)
  local f = fs.open(file, "r")
  local text = f.readAll()
  f.close()
  return text
end

local function listen()
  rednet.open(modem)
  id, message, distance = rednet.receive()
  if message == "true" then
	return true
  elseif message == "false" then
	return false
  else
	return err01
  end
end

local function checkCreds(u, p, id, Sid)
  Sid = tonumber(Sid)
  shell.run("/.LOGIN/.Auth " ..u.. " " ..p.. " " ..id.. " " ..Sid)
  if listen() == true then
	term.clear()
	term.setCursorPos(1,1)
	term.setTextColor(colors.white)
	print("Welcome " ..u)
  else
	User("f")
  end
end

function User(x)
  if x ~= nil then
	term.setCursorPos(1,27)
	term.clearLine()
	term.setCursorPos(30,1)
	term.setTextColor(colors.yellow)
	write("Incorrect Credentials")
	term.setCursorPos(1,9)
	term.clearLine()
	term.setTextColor(colors.red)
	print("					User:						  ")
	term.setCursorPos(1,10)
	term.clearLine()
	print("					Pass:						  ")
	term.setTextColor(colors.green)
	term.setCursorPos(26,9)
	write(" ")
	u = read()
	term.setCursorPos(26,10)
	term.setTextColor(colors.green)
	write(" ")
	p = read("*")
	term.setTextColor(colors.red)
	Sid = tonumber(readFile("/.LOGIN/.id"))
	id = os.getComputerID()
	checkCreds(u, p, id, Sid)
	term.setCursorPos(1,9)
	term.clearLine()
	term.setCursorPos(1,10)
	term.clearLine()
	term.setCursorPos(1,2)
  else
	term.setCursorPos(1,9)
	term.clearLine()
	term.setTextColor(colors.red)
	print("					User:						  ")
	term.setCursorPos(26,9)
	term.setTextColor(colors.green)
	write(" ")
	-- I thought making a new "read()" function would be the best way to go where it decides if the user has pressed a key or input actual text..
	u = read()
	term.setCursorPos(1,10)
	term.clearLine()
	term.setTextColor(colors.red)
	print("					Pass:						  ")
	term.setCursorPos(26,10)
	term.setTextColor(colors.green)
	write(" ")
	-- Same here
	p = read("*")
	Sid = tonumber(readFile("/.LOGIN/.id"))
	id = os.getComputerID()
	checkCreds(u, p, id, Sid)
	term.setCursorPos(1,9)
	term.clearLine()
	term.setCursorPos(1,10)
	term.clearLine()
	term.setCursorPos(1,2)
  end
end

login()


#2 Twijn

  • Members
  • 119 posts

Posted 21 June 2017 - 09:13 PM

The best solution to this would likely just be to just activate the screen with touch events.

Essentially, if someone clicks on "username", start read()'ing at the position of the username, similarly with the password. The only drawback is they'd have to press enter after putting in each field, though that might be fine for your needs, and the only real way to fix that is to make a custom read() function. Moving the cursor when reading is not quite logical, since it'll all be returned in once the read() function is finished.

#3 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 22 June 2017 - 08:23 AM

Some of the GUI frameworks on the forums have text boxes which behave like you are describing. You might want to have a look at one of those.
https://www.google.c...nfo+GUI+textbox





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users