top | item 38761708

Ptext: A Nano-like text editor built with pure C

147 points| asicsp | 2 years ago |github.com | reply

66 comments

order
[+] JonChesterfield|2 years ago|reply
Cool. Compiled easily, made a binary that does look like a text editor, let me make new files and edit an existing one. Only linked against libc, about a thousand lines of C.

So yeah, that is indeed a working text editor that doesn't link against ncurses and the like. Smaller than I would have expected it to be.

[+] kamranjon|2 years ago|reply
Most of that is probably attributable to being based on Kilo: https://github.com/antirez/kilo - a tiny text editor written by antirez who notably also created Redis. Antirez has a bunch of really interesting side projects if you dig into their github repo.
[+] linhns|2 years ago|reply
Yep. Fit for my sole purpose of using other editors: Editing vim Makefile when I decide to recompile.
[+] pjmlp|2 years ago|reply
Not really pure C, plenty of #include that aren't part of ISO C standard.

Pure UNIX/POSIX C, more likely.

[+] djur|2 years ago|reply
"Pure C" doesn't really mean anything, but if it did mean something it would mean "only C", not "only standard C", wouldn't it?
[+] halayli|2 years ago|reply
they aren't part of whatever standard yet they are still pure C. Pure C is not a well defined term but it refers to the fact that only the C language was used for the project. Which C version and whether other libs have been used is not part of the term.
[+] teo_zero|2 years ago|reply
I'll not enter the pure-C vs. non-pure-C debate, but this heavily depends on a Unix-like OS and VT100-like terminal. Forget to compile it for Windows, for example.

Very nice project, well organized, with a terse style. Comments are missing but not necessary.

[+] Underphil|2 years ago|reply
Is it a reasonably common thing for Windows users to operate a text editor from a terminal? (Outside of WSL)
[+] schemescape|2 years ago|reply
I’ve been wanting to make a library for Pico-like interfaces, with the commands and key combinations listed at the bottom of the screen.

I thought something like that must exist, but I haven’t found it yet…

[+] Aloha|2 years ago|reply
I'd love something like this that could be called from sh like dialog can.
[+] WesolyKubeczek|2 years ago|reply
I guess it’s hardcoded to run in something shaped like xterm or better.
[+] nine_k|2 years ago|reply
Now that hardware terminals are gone, it's a very safe bet.

But xterm is,way rich, it supports esoteric advanced stuff like sixels, etc. For a basic text editor, without split windows, colors, and such, a subset of VT-52 capabilities may suffice.

[+] MobiusHorizons|2 years ago|reply
My guess would be it targets VT-100, but it wouldn't have to be hardcoded, non-curses applications can still make use of the terminfo database to determine the capabilities of whatever terminal they are attached to.
[+] 6R1M0R4CL3|2 years ago|reply
read the code. and i liked doing that. while i do mostly java, c++ and rust. there is an elegant beauty in pure C code.
[+] mogoh|2 years ago|reply
pure? Is nano not pure enough?
[+] queuebert|2 years ago|reply
Too bloated. The ultimate goal will be "planck" with zero lines of code. :-)
[+] tyingq|2 years ago|reply
It seems like the author is trying to say "no dependencies other than libc, not even ncurses".
[+] nittanymount|2 years ago|reply
cool, maybe, like to sharpen C skills with a side project ?
[+] tekla|2 years ago|reply
We call that vim
[+] nox100|2 years ago|reply

[deleted]

[+] stevekemp|2 years ago|reply
Like many I appreciated seeing Antirez's kilo project, and went my own direction with a trivial fork: adding support for an embedded lua scripting language, allowing multiple buffers, and flexible syntax highlighting for different languages, etc.

For me one of the challenges was getting UTF8 support, since I live in Finland and am exposed to ä, ö, and other characters. It was a fun learning experience, even though I never intended it to become a "real editor" and I continue to use emacs on a daily basis.

Quickly looking over the (closed) bug reports I see the discussion I had with myself back in 2016 which largely caused me to rewrite the core in C++ so I could take advantage of modern facilities to make UTF8 work more easily:

https://github.com/skx/kilua/issues/49

[+] pharrington|2 years ago|reply
I think you're reading intent that isn't there with this project. The author states its a WIP, and is writing it as a learning experience for building text interfaces without ncurses.
[+] JonChesterfield|2 years ago|reply
Can unicode be implemented in a thousand lines or so of C?