Hi. Finally got it working, so I only need cleanup, optimization etc.
Just thought I'd post a working sample which only checks/colorcodes the last string the user wrote.
I'll post a clean example in the Code Archives once I got it sorted out.
Just thought I'd give something back since I got so much (and quick) help on the subject :)
If, then, else, end are colored white, and =, <, > are colored green. Just as an example.
Edit: Changing lines with the mouse goes very wrong. Will fix later :)
Just thought I'd post a working sample which only checks/colorcodes the last string the user wrote.
I'll post a clean example in the Code Archives once I got it sorted out.
Just thought I'd give something back since I got so much (and quick) help on the subject :)
If, then, else, end are colored white, and =, <, > are colored green. Just as an example.
Edit: Changing lines with the mouse goes very wrong. Will fix later :)
SuperStrict Local MyWindow:TGadget=CreateWindow("Syntax highlighting", 0,0,640,480) Global MyText:TGadget=CreateTextArea(0,0,GadgetWidth(MyWindow),GadgetHeight(MyWindow),MyWindow) SetGadgetLayout MyText,2,2,2,2 Local GUIFont:TGuiFont=LoadGuiFont( "Courier New",12) SetTextAreaFont(MyText,GUIFont) SetTextAreaColor(MyText,1,81,107,True) SetTextAreaColor(MyText,255,255,50,False) Global Keywords:String[] = ["print","if", "then", "else", "end"] Global Operators:String[] = ["=", "<", ">"] Local cursorpos:Int Function IsKeyword:Int(test:String) test = test.tolower() For Local i:Int = 0 To Keywords.length-1 If Keywords[i].tolower() = test Then Return True End If Next Return False End Function Function IsOperator:Int(test:String) test = test.tolower() For Local i:Int = 0 To Operators.length-1 If Operators[i].tolower() = test Then Return True End If Next Return False End Function Repeat WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_GADGETSELECT cursorpos=TextAreaCursor(MyText) End Select Local CurLine:String = TextAreaText(MyText, TextAreaLine(MyText, cursorpos), 1, TEXTAREA_LINES) Local LastWord:String = CurLine[CurLine.findLast(" ")..CurLine.length] LastWord = LastWord.trim() If (IsKeyword(LastWord)) FormatTextAreaText(MyText,255,255,255,0,Cursorpos-LastWord.length,LastWord.length) Else If (IsOperator(LastWord)) FormatTextAreaText(MyText, 50, 255, 50,0,Cursorpos-LastWord.length,LastWord.length) Else FormatTextAreaText(MyText,255,255,50,0,Cursorpos-LastWord.length,LastWord.length) End If SetStatusText MyWindow, LastWord Forever End