I'm creating a simple text editor script (please be kind ) that can do text wrapping for messages. I've made some progress (although it is far for an elegant solution). My thought process was to store each line (40 characters) in an array. So that the text can be read in either 40 or 80 columns by either displaying one or two arrays next to each other. (i.e. PRINT b$(X$) or PRINT b$(X%)+" "+b$(X%+1).
I have the wrap portion working...however if backspace is pressed on the preceeding line then it all goes wrong. I've tried fixing this a few different ways but can't get it quite right and my brain is now a bit fried.
I'm looking for a few pointers on how to fix the backsapce issue so that it will delete the previous character (without spliting subsequent lines) or if the cursor position is the start of a line will return the cursor position to the end of the previous line for editing.
Code: Select all
120 M$=""
130 b$(X%)=""
131 S%=0
140 REPEAT
150 a$=INKEY$(3000)
160 IF a$="" VDU7:PROCstatus(" INACTIVITY WARNING"):a$=INKEY$(1000)
170 IF a$="" THEN PROCdc
181 IF a$=CHR$13 THEN PRINT ';:a$=INKEY$(3000):IF a$="/" THEN PRINT a$:PROCco
182 IF a$=CHR$13 THEN PRINT ';
190 IF ASC(a$) <> 8 THEN M$=M$+a$
200 IF ASC(a$) = 8 THEN PROCbk
210 IF LEN (a$)>0 THEN PRINT a$;
240 IF LEN(M$)=40 THEN b$(X%)=M$:Y%=X%:X%=X%+1:M$="":IF RIGHT$(b$(Y%),1)<>CHR$20 THEN PROCwrap
241 IF a$=CHR$13 THEN b$(X%)=M$:X%=X%+1:a$="":M$=""
260 UNTIL X%=41 OR EMSG%=TRUE
270 END
280 DEFPROCwrap
290 REPEAT:S%=S%+1:sp$=LEFT$(RIGHT$(b$(Y%),S%),1):UNTIL sp$=" ":M$=RIGHT$(b$(Y%),(S%-1)):b$(Y%)=LEFT$(b$(Y%),(40-S%)):VDU11:VDU13:PRINT b$(Y%);:FOR I%=1 TO (40-LEN(b$(Y%))):PRINT" ";:NEXT I%:S%=0:PRINT M$;:L%=41
300 ENDPROC
310 DEFPROCco
320 a$=INKEY$(3000):PRINT a$;
330 IF a$ = "S" THEN PRINT "SAVED":EMSG%=TRUE
340 ENDPROC
350 DEFPROCbk
360 IF ASC(a$) = 8 AND LEN(M$)>0 THEN M$=LEFT$(M$,(LEN(M$)-1)):ENDPROC
370 IF ASC(a$) = 8 AND LEN(M$)=0 THENVDU11:VDU13:X%=X%-1:M$=RIGHT$(b$(X%),39)
380 ENDPROC