7 ms·
Ptext: A Nano-like text editor built with pure C
- JonChesterfield 3y agoCool. 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 3y agoMost of that is probably attributable to being based on Kilo: https://github.com/antirez/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.
- springogeek 3y agoThere's a "thanks" section at the end of the README which links to it, from what I can see.
- kamranjon 3y agothanks! i'll update my comment
- garbagepatch 3y agoThey also thanks viewsourcecode.org but don't directly link to their excellent tutorial on how to build Kilo yourself: https://viewsourcecode.org/snaptoken/kilo/ https://viewsourcecode.org/snaptoken/kilo/
- torh 3y agoI like the extensive way Antirez has commented the data structures (and the rest of the codebase), something that was missing in the ptext code.
- canadianfella 3y ago[dead]
- rahen 3y agoIndeed. Also the default editor for ELKS (Linux for PC/XT and ATs).
- linhns 3y agoYep. Fit for my sole purpose of using other editors: Editing vim Makefile when I decide to recompile.
- mogoh 3y agopure? Is nano not pure enough?
- tekla 3y agoWe call that vim
- deleted 3y ago[deleted]
- nittanymount 3y agocool, maybe, like to sharpen C skills with a side project ?
- tyingq 3y agoIt seems like the author is trying to say "no dependencies other than libc, not even ncurses".
- lovelyviking 3y agoI decided once to recompile nano on mac os because it has some bug or some color missing. I don’t remember why exactly but I do remember a lot of trouble with dependencies … and then my impression was that this tiny editor - is a monster. It is of course depends with what you compare but still it was shockingly bigger then I was prepared/wanted to see
- schemescape 3y agoI was shocked to discover that the source code distribution for GNU nano is over 3 megabytes. To be fair, it also has more features than I expected, e.g. syntax highlighting. And I’m sure it runs on an obscene number of platforms.
- The_Colonel 3y agoI'm usually not one who complains about bloat, but I think this does not meet expectations set by the name "nano".
- WesolyKubeczek 3y agoI guess it’s hardcoded to run in something shaped like xterm or better.
- nine_k 3y agoNow 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 3y agoMy 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.
- nox100 3y ago[flagged]
- pharrington 3y agoI 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.
- The_Colonel 3y agoThe lack of non-ASCII support is not mentioned on github, so this warning about this basic capability (which is often taken for granted) is certainly useful.
- stevekemp 3y agoLike 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 https://github.com/skx/kilua/issues/49
- JonChesterfield 3y agoCan unicode be implemented in a thousand lines or so of C?
- vidarh 3y agoDefine implementing Unicode. If you want to support rtl/bidi and grapheme clusters and every little detail, probably not. But 99% of the utility for most people is there if you can find the right column, and. move left and right by character instead of byte, and can output UTF8 sequences correctly. In C it's a minor pain, but not impossible.
- schemescape 3y agoI’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 3y agoI'd love something like this that could be called from sh like dialog can.
- gdevenyi 3y agoDon't forget about Micro https://micro-editor.github.io/ https://micro-editor.github.io/
- rahen 3y agoIt's written in Go though, so quite a bit less portability.
- pjmlp 3y agoNot really pure C, plenty of #include that aren't part of ISO C standard. Pure UNIX/POSIX C, more likely.
- djur 3y ago"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?
- pjmlp 3y agoThe programming language C is defined by ISO C, this isn't 1970's any longer. Thus pure C, by definition is what the said standard since 1989 says what the programming language and standard library is supposed to be.
- torstenvl 3y agoThis is objectively untrue, and everyone knows it. A huge amount of C code in the real world goes beyond ISO C. Saying that "C" consists only of what is in the ISO standard is ideological flamewar.
- pjmlp 3y agoThe world is full of impure C. Objectively we have a clickbait title.
- quelsolaar 3y agoYes, and much of what is in the later versions of the C standard haven't been adopted widely by C programmers.
- djur 3y agoUsing system and vendor libraries is part of the C language. We're not talking about language extensions here, we're talking about #include <unistd.h>.
- mise_en_place 3y agoNeat, I am a fan of minimalist text editors. There is also uEmacs: https://github.com/torvalds/uemacs https://github.com/torvalds/uemacs
- teo_zero 3y agoI'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 3y agoIs it a reasonably common thing for Windows users to operate a text editor from a terminal? (Outside of WSL)
- int_19h 3y agoFor power users, sure, for all the same reasons you'd do it on Linux even when running a GUI.
- tompazourek 3y agoSome Windows servers use the Windows Server Core edition and you can manage it only via terminal if you choose to. In those cases, a command line text editor is useful. I'd say it's not super common from my experience. More often I see people using RDP or SMB file shares for file editing.
- teo_zero 3y agoI'd say it's not a reasonably common thing for Windows users to do anything from a terminal.
- deleted 3y ago[deleted]
- 6R1M0R4CL3 3y agoread the code. and i liked doing that. while i do mostly java, c++ and rust. there is an elegant beauty in pure C code.