This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
KinoftheFlames's profile picture

[v0.3] ed - The in-game IDE

Started by KinoftheFlames, 21 September 2012 - 02:55 AM
KinoftheFlames #1
Posted 21 September 2012 - 04:55 AM
ed - The in-game IDE

Attention
I stopped working on this project a few months ago when I started into college again. I really enjoyed working on it, but I have no specific intent on returning to work on it in the future. So if anyone wants to take the reigns, help yourself!

Backstory
From the moment I started using ComputerCraft I found many functions of the mod quirky and maybe a little frustrating, but the native editting program (edit) was unacceptable. Even for a monochrome text program with no mouse support and limited visibility there was still massive areas needing improvement. So I mostly coded in Notepad++ while I learned lua and the CC apis. Until I realized I need a new project and I know enough now to write MY OWN edit program. So, here it is.

For those of you wondering, IDE stands for "Integrated Development Environment".
If you have any suggestions for improvements, feel free to post them in this thread. :)/>/>

Download
Direct: http://pastebin.com/D1S03niy
Adfly: http://adf.ly/D7lKX
To install, turn on http use in your ComputerCraft config file and use the pastebin command (i.e. pastebin get D1S03niy ed).

Previous version downloads:
Spoilerv0.2.1
Direct: http://pastebin.com/1fezqbQf
Adfly: http://adf.ly/D9Qcl

Features
- In-editor program execution, with debugger
- Customizable interface including line numbers and status bar that is saved across sessions
- Many improvements to movement controls and automatic text insertion
- One button saving, exiting, and running
- Support for turtles and terminals with custom screen sizes
- …and more to come!

Screenshots
Spoiler


How to use
SpoilerJust like the native edit program, it runs with a single paramater, the file you wish to edit. In example, "ed myFile" without quotations.

Controls:
F1 - Menu
F3 - Save
F4 - Exit
F5 - Run
F6 - Run with arguments
F12 - Help

Planned Features
Spoiler- *Movement hotkeys such as Ctrl+Home/End/arrows
- *Hotkey to duplicate lines
- *Selecting text
- **Copying text
- An auto-save / file-recovery feature
- Auto-updater
- Find and replace
- Goto line
- Auto-complete
- Printer support
- A clean, customizable interface
- Quitting without saving handling, and pressing quit button again to override
- An options menu to change visual and functional preferences
- Running the program being edited without exiting the IDE
- Minor debugging features
- Page Up and Page Down support
- Insertion/overlay toggle for typing
- Auto tabbing

*These features may or may not require detecting multiple keys pressed at once, and therefore depend on ComputerCraft's ability to recognize multiple key presses at once.
**Dependent on Minecraft's and ComputerCraft's ability to support it.

Changelog
Spoilerv0.3 - 9/25/12
This feels like a big update to me, because a couple major goals were reached, and ed is officially over 1,000 lines of code! Woo!

Disclaimer:
Until I can think of a good way to represent menus in the turtle's screen, consider ed to be terminal-only support.
You can still do most things on turtles, but menu text will run off screen and you won't be able to see what settings you are changing.
However you are still able to edit the settings manually by opening up the settings file after going into the settings menu once to generate the file.

Changes:
- Added insertion/overwrite toggle
- Added status bar (optional) with the following information (which is all optional):
– Current line number
– Total line count (off by default)
– Insert/overwrite toggle display
- Added debugging. The file no longer needs to be force-saved to run it, and if there are any run-time errors ed will move the cursor to the error line and display the error.
- You can now run ed from ed as recursively as you'd like and everything should work properly (yo dawg!)
- Added auto-tabbing
- Trying to edit files in non-existant directories now creates those directories
- Added settings menu, you can finally customize the UI without editing the code!.
– Press F1 to access it, then use the arrow keys and space/enter to interact.
- Settings will automatically save on menu exit and load with the program - change it once and you're good! Settings are saved to ".ed_settings" and will overwrite all files and directories (sorry!)
- Added help screen (F12) that shows users the controls. By default "F12 = help" is shown in the status bar so no one is left wondering how to save, exit, etc, their first time.

v0.2.1 - 9/23/12
SpoilerThis is a very minor update to fix a visual bug with the new version, CC 1.42, which will now be the solely supported version.
I tried to allow exiting the running programs by pressing F4, but it's not feasible to do without user-assistance (which doesn't really seem worth it).
If you want to exit a running program, you can still use Ctrl+T if your program allows it, and it will return cleanly to the IDE.
And in case you didn't know, pasting is already natively supported by the system, so it works in this IDE. The only reason it doesn't work in edit is because they have a Ctrl toggled menu.

- Now compatible with and supporting CC 1.42 (may not work with previous versions)
- Added message shown when file is saving
- Now resets program settings after program execution
- Now able to run programs with arguments, press F6 to do so
–Note that running the IDE from itself will not exit cleanly at the momnent; see http://www.computerc...-still-running/

v0.2 - 9/22/12
SpoilerI'm glad to have finally gotten to some of the more fun stuff, which is part of what is listed below. Also it should be noted that there's a lot of customizability already available if you're willing to poke around in the variables at the top of the code. I won't be adding the settings in-program until I've made a menu system of some sort.

Changes:
- Refactored and simplified code to reduce possible errors
- Added message display at the bottom for general information (e.g. program saved, program execution success/failure)
- Added exit without saving confirmation
- Added in-editor program execution (F5)
- Added tab support (more annoying to implement than you'd think…)
- Added page up and page down support
- Changed exit code to return true if exiting normally or false if due to an error

v0.1 - 9/20/12
SpoilerThere's a LOT still to do, so far I think I've written a program comparable to edit. This initial post is just to get the program out there, since I've already had people steal the code on CC servers. It is not guaranteed to be bug free; if there are any bugs please let me know.

Features added:
- Line display on left side
- One-button saving and exitting
rickydaan #2
Posted 21 September 2012 - 08:31 PM
Looks nice
Need someone helping you at this program?
hego555 #3
Posted 21 September 2012 - 09:28 PM
Be nice if computercraft allowed colors, syntex hi-lighting would be nice!
KinoftheFlames #4
Posted 22 September 2012 - 09:42 AM
Looks nice
Need someone helping you at this program?

Thanks! I think I'll go solo for now, as I've never worked in a team before or publicly released code or a program before, so I'm trying to take it one step at a time. :P/>/>
Shazz #5
Posted 22 September 2012 - 01:50 PM
This is one of the reasons why Dan200 should add colour coding for the terminals and monitors.
rickydaan #6
Posted 22 September 2012 - 03:13 PM
On what server do you play?
KinoftheFlames #7
Posted 22 September 2012 - 08:12 PM
On what server do you play?
I play on CCNet (EpicCoderz) Server mostly
Jahmaican #8
Posted 23 September 2012 - 11:44 AM
I'm not sure if showing all line numbers is actually a good idea, because default terminal is only 80 characters wide (even less when using a turtle), and here you waste 4 when working with average 100+ lines file. Showing only current line as in default editor would work fine for me, so maybe you should let users switch between these 2 options?

Also, when debugging fails, cursor could be automagically set in the line where error occured.

Other than that, I love it.
KinoftheFlames #9
Posted 23 September 2012 - 10:35 PM
I'm not sure if showing all line numbers is actually a good idea, because default terminal is only 80 characters wide (even less when using a turtle), and here you waste 4 when working with average 100+ lines file. Showing only current line as in default editor would work fine for me, so maybe you should let users switch between these 2 options?
That's been suggested before, so I'll probably work on that next. I probably won't have the menu out before then, so you'll have to change the setting variable in ed's file.

Also, when debugging fails, cursor could be automagically set in the line where error occured.
I would LOVE to do that, the problem is that the error you see when a program fails is just a print to the screen. None of that information is passed back via variables. There's also, as far as I know, no way to read current characters on the terminal. If you find a way around either of these, I'd be more than happy to add that to ed.

Thanks for your support! :P/>/>
faubiguy #10
Posted 24 September 2012 - 12:25 AM
Also, when debugging fails, cursor could be automagically set in the line where error occured.
I would LOVE to do that, the problem is that the error you see when a program fails is just a print to the screen. None of that information is passed back via variables. There's also, as far as I know, no way to read current characters on the terminal. If you find a way around either of these, I'd be more than happy to add that to ed.

Thanks for your support! :)/>/>

Getting the error message is possible if instead of shell.run, you use a new function, a modified version of os.run:

function runProg( sProgram, ... ) --sProgram is a string containing the current text. Any other arguments are arguments to the program.
	local tArgs = { ... }
	local fnFile, err = loadstring( sProgram )
	if fnFile then
		local tEnv = {["shell"] = shell}
		setmetatable( tEnv, { __index = _G } )
		setfenv( fnFile, tEnv )
		local ok, err = pcall( function()
			fnFile( unpack( tArgs ) )
		end )
		if not ok then
			if err and err ~= "" then
				print( err )
						errorText = err -- errorText is the variable where you want the error
			end
			return false
		end
		errorText = "" -- error value set to "" on successful execution
		return true
	end
	if err and err ~= "" then
		print( err )
				errorText = err -- Again replace errorText with the variable where you want the error
	end
	return false
end

You can replace the call to shell.run on line 326 with this:

local progSuccess = runProg(table.concat(tFile, "\n"), unpack(tArguments))

And then if execution fails you can get the error message from the variable you replace errorText with.

EDIT: I forgot to mention that I made it use the data from directly in the editor rather than from a file.
KinoftheFlames #11
Posted 24 September 2012 - 01:21 AM
Wow man! That's awesome! Now there will be legit debugging built in! I'm so excited. Now it just needs a settings menu, hotkeys, text selection…

EDIT: I did some tweaking and I've already got this implemented. If you have a run-time error in your program, it will now go to the line that error was on and display the error message. :P/>/>
faubiguy #12
Posted 24 September 2012 - 03:12 AM
I have a suggestion for this. A find and find-replace feature would be useful, so you might want to think about adding that in a future version.
KinoftheFlames #13
Posted 24 September 2012 - 08:06 AM
If anyone knows how to tell if a timer is dead (that is identify it as having already gone off) please let me know. I won't be able to add timers properly without it.
Xfel #14
Posted 24 September 2012 - 08:30 AM
You should add the other keys supported by text editors:
- Home and End keys to work for navigating to the front/end of a line
- Ctrl+Home/End combination to navigate to the beginning/end of a program
- PgUp/PgDown keys to scroll through program
- the delete key! (is quite self-explaining)

Additionally, a go to line function would be nice.

EDIT:
I forgot, the third important thing: auto intention and eventually a quick code format?
KinoftheFlames #15
Posted 24 September 2012 - 01:48 PM
You should add the other keys supported by text editors:
- Home and End keys to work for navigating to the front/end of a line
- Ctrl+Home/End combination to navigate to the beginning/end of a program
- PgUp/PgDown keys to scroll through program
- the delete key! (is quite self-explaining)

Additionally, a go to line function would be nice.

EDIT:
I forgot, the third important thing: auto intention and eventually a quick code format?

Home/end, page up/down, and delete should already be in the latest release.
Auto indentation is on the way, and the hotkeys you suggested (Ctrl + something) are being looked into to see if they are feasible.
I'll consider adding a goto line though! That's an interesting one I hadn't thought of. :P/>/>
GopherAtl #16
Posted 24 September 2012 - 07:17 PM
only way I know to know when timers are dead, other than pulling the timer event, is to save the time when they're queued and periodically check later to see if more than the intended time has already elapsed. You'll want to wait a bit longer than the length of the timer, in case the events are late (which can happen).
Sebra #17
Posted 24 September 2012 - 08:34 PM
If anyone knows how to tell if a timer is dead (that is identify it as having already gone off) please let me know. I won't be able to add timers properly without it.
My thought is to calculate time after which timer considered dead (provided events queue is empty).
Doubt key combinations available now.
KinoftheFlames #18
Posted 25 September 2012 - 06:20 AM
Just updated to v0.3. A lot of stuff was added, and I can rest easy now knowing that the core stuff I wanted to add in (editor, customizable UI, settings menu, debugger) are all at least started on and have minimum functionality. I need a break haha
stilldabomb #19
Posted 25 September 2012 - 09:12 AM
Just updated to v0.3. A lot of stuff was added, and I can rest easy now knowing that the core stuff I wanted to add in (editor, customizable UI, settings menu, debugger) are all at least started on and have minimum functionality. I need a break haha

Haha, I know the feeling XD
Sebra #20
Posted 25 September 2012 - 03:18 PM
F1 as Help key is too more standard.
KinoftheFlames #21
Posted 26 September 2012 - 03:56 AM
I put up a poll to see what the people who use ed want from it next. There's a lot of directions to take for improvement, so let me know what you'd like out of your IDE! If you have suggestions for additions that aren't listed, leave a post detailing them.
Xfel #22
Posted 12 October 2012 - 09:49 PM
Your poll is missing a feature: syntax highlighting for the new advanced computers!
Jahmaican #23
Posted 06 December 2012 - 01:08 AM
I can see KOTF became inactive (well, just like me - working on my degree) and that's a shame, this program seriously needs further development!
anonimo182 #24
Posted 06 December 2012 - 11:22 AM
I can see KOTF became inactive (well, just like me - working on my degree) and that's a shame, this program seriously needs further development!
Haven't you see that the author haven't connected since october 6? I think he will not develop it anymore… :(/>
KinoftheFlames #25
Posted 06 January 2013 - 07:37 PM
Watup Jahmaican. I got sidetracked when I started back up at school and I didn't have the time to keep up working on ed. Really loved doing it, and I'll probably work on it again when I bounce back to Computercraft but who knows how long that will be? :P/>

Feel free to branch it if you want!