In a previous post I used the ‘syntax’ gem to process text into tags which could then be tagged with terminal colour codes.
There’s a plugin which already does all of this called coderay, I will combine this with highline (to control the input and output and maybe create an interface too)
e = Editor.new
# now for a bit of monkey typing
monkey = <<MONKEY
# now try to monkey patch user input
usermonkeysay = ask("Monkey do?")
One thing you might have noticed is that I have a function called getBinding in the ‘Editor’ class, what this does is return a handle to the current class to modify that class programmatically.
When we have the binding, we can do evil things on that class. I mean ‘eval’, but rather than a straight up eval you can do an eval within the context of that class.
And in ruby you can eval this inside of the context of the class
Something like a ‘def’ in the context of the binding will let you run that function later on using the binding.
What does this mean?
A text editor which took advantage of this (something like diakonos, redcar maybe) would be able to provide user friendly commands such as open, save, gotoLine, regex, replace, column(x,y, w, h), select(x,y,w,h), copy, paste.
This would provide a clear level of abstraction between a command mode and text entry in editors.
My plan is to have a 3 pane editor with a readonly text view, a text entry box and a command box.