A Tired Red Editor |
IntroductionRed is a very interesting programming language that I am experimenting with. It is (intentionally) very similar to REBOL. http://www.red-lang.org/REBOL Tutorial A Tired Editor - Written in RedHere is a tiny Red program (only 35 lines) which provides an editor for running Red programs. It is just a bit of fun, not suitable for serious work. It runs on Windows, and maybe GNU/Linux - I have not tried it. Note that - at the time of writing - May 2016 - Red is at version 0.6, and the full range of GUI widgets is not complete (e.g no scrollbars). Progress is ongoing. For info on other Red editors etc, look here. Anyway,here is what tired looks like. There is an editor which lets you open files and edit them. The results go to a console window. ![]() The Tired ManualRun it, overtype ANYNAME at the bottom with your chosen name, and start editing. Click 'Interpret' to execute. Note console window, with results, errors etc. The program is saved automatically before running. Click 'Save' at any time if you want to save the code - you can also choose a new file name. Apologies - no scroll bars yet - but you can do this with the cursor. How to get it, if you are new to Red.Create a folder, called e.g. RedStuff, put all the following files in this folder. From http://www.red-lang.org/p/download.html You will find red-latest.exe for Windows towards the bottom of the page. Run it. It unpacks and compiles itself, for a minute or more. Get the code for tired from this page, store it in a file named tired.red Create a one-line file named tired.bat, with e.g. notepad. It should contain: "red-latest.exe" "tired.red" To run it, double-click tired.bat - - (or you can type it at the command-line, if you know this stuff). Please do not contact me about bugs, enhancements etc. It us just for fun. Tired CodeHere is a txt file - rename it as tired.red Here is the code also: Red ["tired editor - mikeparr@live.com"] ;editor for Red, written in Red - 6 May 2016 ;just a bit of fun, not for serious use. Windows only - CR/LF maniplation! open: function[] [ ;-------- read a file, LF to CRLF needed for Area print["opening " file-name/text] the-text/text: replace/all read to file! file-name/text "^/" "^M^/" ] save-current: function[] [ ;------- write modified copy of area to file print "Saving" text-copy: copy the-text/text replace/all text-copy "^M" "" ;delete all CRs write to file! file-name/text text-copy ] interpret: function[ ][ ;------- interpret the code id the area, saving it save-current print ["Interpreting " file-name/text] do to file! file-name/text ;exec the text in file ] any-name: append get-current-dir "/ANYNAME.red" ;an initial file name for user view[ ;--------- GUI, events ----------- size 600x700 button "Interpret" [interpret] button "Compile" [print ["compile (not implemented yet)" ]] button "Run" [print ["run (not implemented yet)" ]] return ;move down and to left the-text: area 580x600 {Red [ ]^M^/print "Hello World"^M^/ } ; nb CRLF return button "Open: Overtype ANYNAME first: " [open ] file-name: field 200 any-name button "Save Current file" [ print "saving" save-current] ] |