Just out of curiosity, what's the smallest source code for a basic text editor you can come up with in any given language. The requirements are the ability to enter text via a keyboard and delete it in some possibly restricted manner.

A few examples:

CAT from Linux

Code:
[,.]


Brainf*ck

Code:
+[-,>+]

Note on the Brainf*ck editor: I tested a few interpreters and all of them seem to use an input buffer to handle the "," command, meaning that basic deletion and editing is possible. However, the individual interpreters can handle inputs slightly differently, so results may vary.

Any other particularly short or beautiful ways to write text editors?
Neither of those count as "text editors" - they just read a line from stdin. The actual editing is thus done by the terminal emulator, NOT the program.

Moreover, you can't edit or delete previous lines.
ed is king.

Code:
tari@osiris$ ls -lh `which ed`
-rwxr-wr-w 1 root root 37k Oct  3  2010 /bin/ed
You could also use the > and >> operators in Bash to store text to a file.
I was going to post a simple C++ cin/cout example, but it looks like the example that I was going to post doesn't count under Kllrnohj's restrictions. Razz
I would think that one in TCL/Tk would be trivial, but I haven't looked up how to do so.
Kllrnohj wrote:
Neither of those count as "text editors" - they just read a line from stdin. The actual editing is thus done by the terminal emulator, NOT the program.

Moreover, you can't edit or delete previous lines.


Fair enough. Here's the brainf*ck with deletion added.


Code:
+[-,>,----------[++++++++++>][-][<]<[>+>+<<-]+>-[<+>-]>>>>+++++++[<+++++++++>-]<[<++>-]<<[>-<-]>[>>]<<[-]<[-]<+]
If it counts, why not drag a text box onto a blank form in VB, run the application, and call it a day? If it's not considered cheating, it's a winner Wink no code at all.
Ashbad wrote:
If it counts, why not drag a text box onto a blank form in VB, run the application, and call it a day? If it's not considered cheating, it's a winner ;) no code at all.


Unfortunately, VB sucks. Do it the 1337 way:

Code:

import java.awt.*

public class SimpleTextEditor{
      public static void main(string[] args){
           Frame frame= new Frame("Bla, bla, bla");
           frame.setSize(300,300);
           TextArea box= new TextArea();
           frame.add(box);
           frame.show();
     }
}
 
Well, I am writing a text editor in ti basic hefting more features than the ones which were mentioned here. I didn't condense the code for ease of editing, but its about 2500 bytes.
Halterer wrote:
Well, I am writing a text editor in ti basic hefting more features than the ones which were mentioned here. I didn't condense the code for ease of editing, but its about 2500 bytes.
That's great! But rather than hijacking someone else's topic, you should start your own Your Projects topic for the project where you can show off screenshots and status updates, and we can offer feedback and coding help as necessary.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement