Live data from Hacker News

Writing an editor in less than 1000 lines of code, just for fun

antirez.com

61–70 of 146 posts

Re: Writing an editor in less than 1000 lines of code, just for fun

#61

Earlier quoted context omitted.

Exactly: muscle memory. In your car, do you move the turn signal lever up or down to indicate a right turn? It actually takes longer to answer this question than to do the action in real life. Another example: There are several passwords that I can type instantly, but I wouldn't be able to recite them.

> In your car, do you move the turn signal lever up or down to indicate a right turn? You rotate it the same direction you're about to rotate the wheel. The vi navigation keys have no such convenient correspondence.

The J kinda looks like an arrow pointing down. If you squint.

Re: Writing an editor in less than 1000 lines of code, just for fun

#62

> Let’s say this again, “email client”. The notion of email client itself is gone at this point. Really? Is it lame to be using an email clients these days? I still use an email client (Thunderbird) because I can't stand the thought of all my mail sitting forever on Goggle's or whoever's servers. Yes, I know that they could have secretly archived all of my email the moment it was sent or received, and that my privacy…

I've actually been working on a new email client, and a terminal one at that. Shameless plug: https://github.com/SirCmpwn/aerc

Re: Writing an editor in less than 1000 lines of code, just for fun

#63

If antirez is reading: How much time did this take? From start to finish. :)

The GitHub page states: "The project is in alpha stage and was written in just a few hours taking code from my other two projects, load81 and linenoise."

https://github.com/antirez/kilo

Re: Writing an editor in less than 1000 lines of code, just for fun

#66

> Let’s say this again, “email client”. The notion of email client itself is gone at this point. Really? Is it lame to be using an email clients these days? I still use an email client (Thunderbird) because I can't stand the thought of all my mail sitting forever on Goggle's or whoever's servers. Yes, I know that they could have secretly archived all of my email the moment it was sent or received, and that my privacy…

I've actually been working on a new email client, and a terminal one at that. Shameless plug: https://github.com/SirCmpwn/aerc

Very cool! Going by the acronym, are you trying to make a Stallman-ish IMAP client that works well offline and only needs an occasional Internet connection to sync?

Re: Writing an editor in less than 1000 lines of code, just for fun

#67

Wow! I love this!! Thanks for the post antirez, if just for introducing me to this now indispensable tool ;) asciinema - Record and share your term sessions https://asciinema.org/

Yes, asciinema is a wonderful thing I learned about from this blogpost too. And another one from the asciinema.org: lolcat! Command line forever!

Re: Writing an editor in less than 1000 lines of code, just for fun

#68

Can anyone explain how to do a full-screen UI using only VT100 codes? If I had to write a small editor, I'd probably reach for something like Termbox for display.

You could look at the code to see how it's done, but basically, you send a special sequence of characters that update the screen.

The VT100 (and a lot of terminal emulators these days) use what are called ANSI escape sequences. For instance, to move the cursor, the CUP (CUrsor Position) sequence is used, which is " [ ; H" where is the ESCAPE ASCII character, is the row number (as ASCII, so for row 12, it's the string "12"), is the column number ("40" for column 40) and the rest are the literal characters. So, in hex, it's 1B 5B 31 32 3B 34 30 48 ([12;40H).

There are more sequences (move the cursor up, down, left, right, clear various portions of the screen, change colors, etc).

Conversely, the terminal will send ANSI escape sequences representing certain keys, such as "[A" for the up arrow key, "[D" for the left arrow key and such. It's then just a matter of recognizing these sequences and doing the appropriate thing ("I received [A so the user is moving the cursor up. Update my internal structure to represent that, and send to the terminal [A so it moves the cursor on the screen up").

Re: Writing an editor in less than 1000 lines of code, just for fun

#69
post #63

If antirez is reading: How much time did this take? From start to finish. :)

The GitHub page states: "The project is in alpha stage and was written in just a few hours taking code from my other two projects, load81 and linenoise." https://github.com/antirez/kilo

Yes, thanks for pointing that out. I'm more interested in total time. Not time to write. :)

Re: Writing an editor in less than 1000 lines of code, just for fun

#70
post #41

> Let’s say this again, “email client”. The notion of email client itself is gone at this point. Really? Is it lame to be using an email clients these days? I still use an email client (Thunderbird) because I can't stand the thought of all my mail sitting forever on Goggle's or whoever's servers. Yes, I know that they could have secretly archived all of my email the moment it was sent or received, and that my privacy…

Gmail's web client also non-optionally auto-wraps text before sending, which is very annoying when you're trying to send a patch or part of a log file.

Only in plain text mode, sadly. If you send an HTML message, a plain text version gets included, too, which isn't auto-wrapped. It's encoded as quoted-printable instead, which keeps lines short enough to be legal for SMTP but can be turned back into the original text by the client on the other end.
Post reply on HN