My attempt at an input function for console apps..

BlitzMax Forums/BlitzMax Programming/My attempt at an input function for console apps..

plash(Posted 2007) [#1]
has a bit of a problem...

	While Not AppTerminate()
		Local inp:String = InputA$("")
		
		If inp <> Null
			WriteStdout "~q" + inp + "~q"
		EndIf
		
		Delay 1
	Wend
	
Function InputA$( prompt$=">" )
	Global status:Int = 0
	Global str$,buf:Byte[1024],p:Int,n:Byte
	
	If status = 0
		StandardIOStream.WriteString prompt
		StandardIOStream.Flush
	EndIf
	
	  status = 1
		If StandardIOStream.Read( Varptr n,1 )<>1 status=-1
		If n=0 status=-1
		If n=10 status=-1
		If n=13 status=-1
		buf[p]=n ; p:+1
		If p<>buf.length status=-1
		str:+String.FromBytes(buf,p)
		p=0
		
	If status=-1
		DebugLog ""
		If p str:+String.FromBytes(buf,p)
		Local tstr$ = str
		status=0 ; str$=Null ; p=0 ; n=0 ; buf=Null 
		buf = New Byte[1024]
		Return str
	EndIf
	
	Return Null
	
End Function


What am I doing wrong here?


plash(Posted 2007) [#2]
Oh, and here is the code that the original Input function calls.

'IN BRL.STANDARDIO LINE 56
Function Input$( prompt$=">" )
	StandardIOStream.WriteString prompt
	StandardIOStream.Flush
    Return StandardIOStream.ReadLine()
End Function

'IN BRL.STREAM LINE 380
Method ReadLine$()
		Local str$,buf:Byte[1024],p
		Repeat
			Local n:Byte
			If Read( Varptr n,1 )<>1 Exit
			If n=0 Exit
			If n=10 Exit
			If n=13 Continue
			buf[p]=n ; p:+1
			If p<>buf.length Continue
			str:+String.FromBytes(buf,p)
			p=0
		Forever
		If p str:+String.FromBytes(buf,p)
		Return str
	End Method



plash(Posted 2007) [#3]
Aww comon, theres gotta be some IO genius out there..


plash(Posted 2007) [#4]
I've gone through BRL.Blitz(ReadStdIn/WriteStdOut) and BRL.StandardIO(StandardIOStream.ReadLine/Print), successfully communicated between apps, but there doesn't seem to be any command that doesn't stick the program in a loop.

EDIT: Brucey, when is Curses gonna be finished? :((


Brucey(Posted 2007) [#5]
when is Curses gonna be finished? :((

Once I get most of wxMax out of the way - which is going well :-)