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

Editable Print.

Started by Left, 11 March 2013 - 07:14 PM
Left #1
Posted 11 March 2013 - 08:14 PM
Like the edit program how can I print something that can then be edited?
oeed #2
Posted 11 March 2013 - 08:41 PM
By print do you mean on screen print or paper print?
Left #3
Posted 11 March 2013 - 08:43 PM
Print on screen then be able to edit it…. Like the program edit.
immibis #4
Posted 11 March 2013 - 08:50 PM
You can do it by copying the edit program into your program
oeed #5
Posted 11 March 2013 - 09:13 PM
Print only draws text to the screen. Making it editable is not a trivial task. I recommend you take a look at edit. What do you need this for?
Kryptanyte #6
Posted 11 March 2013 - 09:30 PM
I am also interested in this, for like a config file, so you don't have to go into the config file to change options.
oeed #7
Posted 11 March 2013 - 09:43 PM
So basically you want to make something simliar to the adress bar on your browser?
Kryptanyte #8
Posted 11 March 2013 - 10:22 PM
Yeah
ikke009 #9
Posted 11 March 2013 - 10:27 PM
I believe this has been asked before about a week ago.. Im on my tablet right now so i cant look it up easily for you, but i suggest using the search button and see what you can find
Left #10
Posted 11 March 2013 - 10:45 PM
I looked at the edit program and it seems to just return lines. I dont know how this works
theoriginalbit #11
Posted 11 March 2013 - 10:49 PM
This isn't all the code, and its really basic, but here is the start of what you need to do

local function editableInput( initial, mask )
  local sx, sy = term.getCursorPos()
  while true do
	local event, param = os.pullEvent()
	if event == 'key' then
	  if param == key.backspace then
		initial = initial:sub( 1, #initial - 1 )
	  end
	elseif event == 'char' then
	  initial = initial..param
	end
  end
  term.setCursorPos(sx,sy)
  if mask then
	write( string.rep( mask, #initial )..' ' )
  else
	write( initial..' ' )
  end
end
Kryptanyte #12
Posted 11 March 2013 - 11:16 PM
@TOB What exactly is the mask? Like I see where is it used, but don't fully understand what it is.
theoriginalbit #13
Posted 11 March 2013 - 11:20 PM
@TOB What exactly is the mask? Like I see where is it used, but don't fully understand what it is.
Its like when you do read( '*' ) for password input. it "masks" the input.
Kryptanyte #14
Posted 11 March 2013 - 11:33 PM
Oh, I see thank you
theoriginalbit #15
Posted 11 March 2013 - 11:35 PM
no problems.
GopherAtl #16
Posted 12 March 2013 - 03:27 AM
if all you want is a single line of editable input, basically read() that can be pre-loaded with a value, you can simply queue an up arrow key event before calling read, and pass the initial value in a table as the 2nd argument to read, as so:


os.queueEvent("key",keys.up)
read(nil, { "initial value" })