Here's something really basic that I just threw together. It only runs on Windows, I would get versions of this working for Mac and Linux if I had the time...or a Mac.
Edit: Fixed a couple issues grabbing the command line, removed the test output.
Edit 2: Added a Mac to my development environment, realized that I can use built-in MaxGUI commands to do the same thing I was doing with a Windows message (EM_GETSEL), so this should run anywhere now. I still need to test on the Mac though.
Not sure if this bug showed up with this change or not, but I was getting an extraneous newline when re-running a command from the history (move the cursor up to a command you entered before and hit enter: it's executed again). Fixed that.
Probably no one cares about this bit of code but it's very useful to me. The stuff I'm building around this will be more interesting once it's done.
Edit: Fixed a couple issues grabbing the command line, removed the test output.
Edit 2: Added a Mac to my development environment, realized that I can use built-in MaxGUI commands to do the same thing I was doing with a Windows message (EM_GETSEL), so this should run anywhere now. I still need to test on the Mac though.
Not sure if this bug showed up with this change or not, but I was getting an extraneous newline when re-running a command from the history (move the cursor up to a command you entered before and hit enter: it's executed again). Fixed that.
Probably no one cares about this bit of code but it's very useful to me. The stuff I'm building around this will be more interesting once it's done.
SuperStrict AppTitle = "Console" Global ConsoleWindow:TGadget Global Console:TGadget ConsoleWindow = CreateWindow("EditWindow", 0, 0, 400, 400, Desktop(), WINDOW_TITLEBAR|WINDOW_RESIZABLE) Console = CreateTextArea(0, 0, 392, 376, ConsoleWindow, 0) SetGadgetLayout Console, 1, 1, 1, 1 SetGadgetFilter Console, outputfilter, Null ActivateGadget(Console) write "Test1" write "Test2" Repeat Select WaitEvent() Case EVENT_GADGETACTION Select EventSource() EndSelect Case EVENT_WINDOWCLOSE Exit EndSelect Forever Function Write(sLine:String) AddTextAreaText(Console, sLine + "~n") EndFunction Function TextAreaSelLine:Int(textarea:TGadget) Local start:Int start = TextAreaChar(textarea, TextAreaCursor(textarea, TEXTAREA_LINES)) Return TextAreaLine(textarea, start) EndFunction Function OutputFilter:Int(event:TEvent, context:Object) Local line:Int, start:Int, stop:Int, sCmd:String Select event.id Case EVENT_KEYDOWN If Event.Data = 13 Then Return 0 Case EVENT_KEYCHAR If Event.Data = 13 Then ' Enter line = TextAreaSelLine(Console) start = TextAreaChar(Console, line) stop = TextAreaChar(Console, line+1) If stop = TextAreaLen(Console) Then Write "" Else stop :- 1 End If sCmd = TextAreaText(Console)[start..stop] Command(sCmd) Return 0 End If EndSelect Return 1 EndFunction Function Command(sCmd:String) Select sCmd Case "exit" End Default Write "Unknown command: '" + sCmd + "'" EndSelect EndFunction