8 ms·
Everything you ever wanted to know about terminals (2018)
- msla 6y agoncurses is a lot more readable than just dropping raw control codes into your source code, and it works, whereas raw control codes might work and often don't.
- deleted 6y ago[deleted]
- laksdjfkasljdf 6y agothat site has great personal branding. recall seeing other articles from lexi halle on the feediverse some time ago and immediately recognized it. great content too.
- kohtatsu 6y agoI was just reading up an ANSI escape sequences a few days ago, this is gold. I adore the format and writing style too.
- floatingatoll 6y agoPreviously: https://news.ycombinator.com/item?id=21601600 https://news.ycombinator.com/item?id=21601600 https://news.ycombinator.com/item?id=18125167 https://news.ycombinator.com/item?id=18125167
- deleted 6y ago[deleted]
- theamk 6y agoThat’s pretty nasty - this article is factually incorrect in probably the worst way: the code will work on author’s computer, but not for other people [0] Not to mention that it is missing “good citizen” features like turning off colors when stdout is not a tty. [0] https://news.ycombinator.com/item?id=18125374 https://news.ycombinator.com/item?id=18125374
- inetknght 6y ago> “good citizen” features like turning off colors when stdout is not a tty. Better solution: do not detect whether your output is a tty or not. Let the user decide they want colors or not by using `--color=always` or `--color=never` or similar. There's few things worse than writing a script and getting different output just because you're no longer running the program interactively.
- anitil 6y agoGah i got bit by this with 'jq'! > $ echo "{}" | jq > {} > $ echo "{}" | jq > out.json > jq - commandline JSON processor [version 1.5-1-a5b5cbe] ... etc ... Turns out when stdout isn't a tty you _must_ specify a filter (in this case '.')
- inetknght 6y agoYup! I had the same problem too. It was 'fixed' in jq 1.6, such that it now assumes `.` is the filter if no program arguments are provided [0]. It happens all the time with anything systemd or networkmanager too [0]: https://github.com/stedolan/jq/releases/tag/jq-1.6 https://github.com/stedolan/jq/releases/tag/jq-1.6
- deleted 6y ago[deleted]
- theamk 6y agoI don't see how this is supposed to work? Let's take "grep" for example -- you want both of these to work, and print color to terminal: grep box file.txt grep box file.txt | grep -v orange-box Having --color=always is nice sometimes, but there is a reason grep has "--color=auto" and it is the default. If we write invisible characters to file, this breaks all sorts of tools, so it is much safer and more predictable to not include them.
- inetknght 6y agoIf I wanted to see just orange-box, then I would do grep --color=always orange-box file.txt But, I don't want to see just orange-box. I want to see orange-box and compare against other cases of box. So I would do: grep --color=always box file.txt | grep --color=always orange-box Without that --color=always, other cases of box will be drowned out by the noise. And if I wanted to write that out to a file then I would do grep --color=never orange-box file.txt > matches.txt Alternatively, I'd add a filter to the file with `ansi2txt` grep --color=always box file.txt | grep --color=always box | ansi2txt > no-color-matches.txt
- miguelmota 6y agoCan barely read the content with that colorscheme.
- ablekh 6y agoThe lack of attention to (or, rather, the complete disregard of) proper capitalization is ridiculous. This is the second post I'm seeing in two days that feature this "style". Quite a disturbing trend, if you ask me.
- 8fGTBjZxBcHq 6y agowhy is it disturbing it reads fine to me
- ablekh 6y agobEcAuSe pRoPer cApItAlIzAtIoN iS iMpOrTaNt fOr rEaDaBiLiTy ;-)
- brian_cloutier 6y agoWhat is ridiculous and disturbing about using lowercase letters at the beginning of your sentences? In a world where this trend continues your eye will become used to it and it will no longer be a distracting shock from what your eye is used to.
- jjoonathan 6y agoIn a world where everyone has terrible body odor, your nose will become used to it and it will no longer be a distracting shock.
- brian_cloutier 6y agoThis analogy doesn't hold. You were born with a sensitivity for body odor, you were not born with any sensitivity for lowercase letters. Do you really mean to imply that sentences which start with lowercase letters are intrinsically visually offensive?
- jjoonathan 6y agoEvery time I've given the benefit of the doubt to someone who opens our interaction by intentionally burning social capital on something frivolous, it has been a mistake.
- titzer 6y agoOh man, they left out the part I was hoping to find out more about! > it's good form to have a function called resize() or similar that you run on program start and later when the terminal window is resized. while there is a horrible way to do this with ANSI escapes, it's better to just bite the bullet and learn how to use ioctls and termios. I wanted to know about the horrible ANSI escape sequences to send that can query the window size. Afaict one has to read from the terminal to get the answer--but these are control sequences that could be inserted into the normal stream--when, where, how?
- pherrephatta 6y agoYou can look at the programmer's guide for the VT100[1], which does a good job of explaining the different ANSI escape codes. To put it simply, you can move the cursor down and to the right. For example, you'd move the cursor 999 lines down, then 999 columns to the right, and then query the cursor's position[2]. You can then read the output through STDOUT and parse it. I'd recommend anyone who's interested in playing around with ANSI and learning how to write a pure terminal-based program to look into the Kilo text editor[3]. That's where I learnt the above instructions. [1] https://vt100.net/docs/vt100-ug/chapter3.html https://vt100.net/docs/vt100-ug/chapter3.html [2] https://vt100.net/docs/vt100-ug/chapter3.html#CPR https://vt100.net/docs/vt100-ug/chapter3.html#CPR [3] https://viewsourcecode.org/snaptoken/kilo/ https://viewsourcecode.org/snaptoken/kilo/
- akira2501 6y agoHorrible escape sequences: man 4 console_codes Horrible console ioctls: man 4 console_ioctl
- ximm 6y agoI recently rewrote my fork of cplay and got fed up with curses. Boy do I wish I had found this article earlier because it describes everything I painfully had to cobble together. This is great! Just one nit: Doing stuff in a signal handler is usually a bad idea because it can interrupt your code at any time. The usual work around is a trick called "self-pipe". https://ldpreload.com/blog/signalfd-is-useless https://ldpreload.com/blog/signalfd-is-useless For anyone interested, I created a library in the process: https://github.com/xi/boon https://github.com/xi/boon (It takes some inspiration from react but bare with me, I think it actually makes sense.)
- spicybright 6y agoInteresting, but I wish it was less emotionally charged. But very cool using macros to make an easy styling "language"!
- Chris2048 6y agoWhat's this stuff about: > also, i'm a) a nobody and b) a woman. nothing i wrote would ever gain any traction; any project designed to supplant ncurses needs to come from someone who's actually known to the FOSS community. and a maintainer who isn't a cripple. Did ncurses gain popularity because of the identity of its maintainer(s)?! I was of the impression that it's whoever gets there first.