library "dos.library"
declare function xOpen& library
declare function xWrite& library
declare function xRead& library

con$="con:0/0/300/150/test"+chr$(0)
handle&=0
csi$=chr$(155)
buffer$=space$(80)

handle&=xOpen&(sadd(con$),1006)
if handle&=0 then end

ConCLS
ConLOCATE 5,5
ConINPUTSTR "Bitte Name eingeben: ",a$
ConLOCATE 7,5 : ConPRINT "Hallo "+a$
ConLOCATE 12,25 : ConPRINT "Ende mit <Return>"
ConWAIT
if handle& then xClose& handle&
end

sub ConCLS static
	shared handle&
	lout&=xWrite&(handle&,sadd(chr$(12)),1)
end sub

sub ConLOCATE(z%,s%) static
	shared csi$,handle&
	out$=csi$+mid$(str$(z%),2)+";"+mid$(str$(s%),2)+"H"
	l&=len(out$)
	lout&=xWrite&(handle&,sadd(out$),l&)
end sub

sub ConRawINPUTSTR(var$) static
	shared handle&,buffer$
	dim numpars%(20)
	SetCursor 1 : c%=0 : CSImode%=0
	s%=1 : c$=space$(10)
	while c%<>13
		lin&=xRead&(handle&,sadd(c$),1)
		c%=asc(c$)
		if CSImode% then
			if c% >=48 and c%<=57 then
				numpar%=numpar%*10+(c%-48)
			elseif c$=";" then
				numpars%(npptr%)=numpar%
				npptr%=npptr%+1
				numpar%=0
			elseif c$="A" or c$="B" or c$="C" or c$="D" then
				if sflag%=0 then CSImode%=0
			elseif c$="" then
				numpars%(npptr%)=numpar%
				sflag%=0
				CSImode%=0
			elseif c$=" " then
				sflag%=1
			elseif c$="T" or c$="S" or c$="@" then
			elseif c$="?" then
			elseif c$="|" then
				CSImode%=0
			end if
		else
			if (c% and 127) >= 32 then 
				mid$(buffer$,s%,1)=c$
				s%=s%+1
				lout&=xWrite&(handle&,sadd(c$),1)
			else
				if c%=155 then CSImode%=1
				npptr%=0 : numpar%=0
			end if
		end if
	wend
	var$=left$(buffer$,s%)
	SetCursor 0
	erase numpars%
end sub

sub ConINPUTSTR(prompt$,var$) static
	shared handle&,buffer$
	SetCursor 1
	ConPRINT prompt$
	l&=len(buffer$)
	lin&=xRead&(handle&,sadd(buffer$),l&)
	SetCursor 0
	var$=left$(buffer$,lin&)
end sub

sub ConINPUTNUM(prompt$,var) static
	buf$=""
	ConINPUTSTR prompt$,buf$
	var=val(buf$)
end sub

sub ConPRINT(text$) static
	shared handle&
	l&=len(text$)
	if l& then lout&=xWrite&(handle&,sadd(text$),l&)
end sub

sub LF static : ConPRINT chr$(13)+chr$(10) : end sub

sub SetItalic(bool%) static
	shared csi$
	if bool% ConPRINT csi$+"3m" else ConPRINT csi$+"23m"
end sub

sub SetBold(bool%) static
	shared csi$
	if bool% ConPRINT csi$+"1m" else ConPRINT csi$+"22m"
end sub

sub SetUnderline(bool%) static
	shared csi$
	if bool% ConPRINT csi$+"4m" else ConPRINT csi$+"24m"
end sub

sub SetInvers(bool%) static
	shared csi$
	if bool% ConPRINT csi$+"7m" else ConPRINT csi$+"27m"
end sub

sub ConCOLOR(bg%,fg%) static
	shared csi$
	ConPRINT csi$+"3"+mid$(str$(fg%),2)+"m"
	ConPRINT csi$+"4"+mid$(str$(bg%),2)+"m"
end sub

sub SetCursor(bool%) static
	shared csi$
	if bool% then out$=csi$+" p" else out$=csi$+"0 p"
	ConPRINT out$
end sub

sub ConWAIT static
	shared handle&,buffer$
	lin&=xRead&(handle&,sadd(buffer$),1)
end sub

sub ConRESET static : ConPRINT chr$(27)+"c" : end sub
