1. 35
  1.  

  2. 18

    (n.b. there’s another escape, “\x1b47h”, with deceptively similar effects as 1049, but it’s behavior is subtly broken on some terminals (such as xterm) and it outright doesn’t work on others (such as kitty). “\x1b[?1049h” has the correct effects everywhere, tho.)

    That’s not true. It won’t work on the OpenBSD or Linux consoles, the Emacs AnsiTerm package, etc. There are still a lot of terminal emulators in widespread use that don’t support a lot of things.

    yes, ncurses supplies features like window-drawing and region invalidation (to avoid terminal flicker) that are much harder to implement yourself.

    In other words, ncurses is still very useful. One of the most interesting parts of (n)curses is how well it optimizes redisplay. It determines the lengths of various control sequences supported by the terminal and attempts to calculate a minimum update sequence for the terminal.

    The “supported by the terminal” part is important because not every terminal supports, say, HPA or VPA (Horizontal/Vertical Position Absolute). They’re common enough that you might think you could use them but popular terminals RXVT either don’t support them, support them incorrectly, or only added correct support fairly recently.

    There’s also fundamental differences in things like what happens if you print a tab. Are tab stops evenly spaced? Can you move them? Do the spaces tabbed over get erased, or stay the same?

    And don’t even get me started on what happens if you print a character in the final column of the screen. Most modern terminals emulate the VT100’s “xenl” glitch, which means that the cursor “goes off the edge of the screen” when you print to the last column. The upshot is that you can thus write to the lower-right corner of the screen without triggering a scroll….but that won’t work on a lot of still-in-use terminals like the FreeBSD cons25 driver, any terminal claiming “ansi-generic” compatibility, Cygwin, etc.

    What happens to the background color of the screen when you clear it or a portion of it? Does the screen get cleared with the background color, or does it revert to whatever the default color is? On xterms, the background color is retained. On many others, the background color is lost.

    (Does the terminal even have the concept of “no background color”? Some do, some don’t!)

    Don’t get me wrong, I think ncurses is in some ways a little long in the tooth, but I think it’s incorrect to say that it’s outlived its usefulness or that things have stabilized enough in the terminal world to allow as many assumptions about supported control sequences (and their behavior) as you might think.

    1. 2

      still-in-use terminals like the FreeBSD cons25 driver

      I guess it’s safe to say that no one’s going to run your new hipster application on the system console on a pre-2009 version of FreeBSD.

      This is literally like the “should new web apps support IE8” situation :)

      1. 3

        Not if you write software which may be used by someone who may be in that situation? How are you supposed to know?

        1. 1

          Running weird ancient versions of things is pretty common, particularly in enterprise situations where some independent part of the company is theoretically supposed to approve every upgrade of system software.

          Where I work, we have a lot of third party code that’s under active development where we’re stuck on 15+ year old versions because of compatibility with other (often proprietary) third party code that stopped being developed in the mid-90s. Until recently, we were running a 2.4 kernel everywhere because we weren’t allowed to upgrade.

          1. 2

            Did you mean to respond to the person above me? We seem to be agreeing here :)

            1. 3

              Sorry, yeah – I agree with you :)

    2. 7

      Either I am reading this completely wrong or there suggested solution here makes things worse than what it tries to displace. The ncurses abstraction at least opens up for providing a non-terminal encumbered backend even if the API is rigid, limited and ugly. Having clients themselves dip into the dark abyss of escape sequences is much more damaging.

      1. 5

        Either I am also wrong, or you are correct.

        One of the things that curses gives you is optimal redraw. I used to use a gopher client over a 1200 baud connection – when I would page down, the gopher client would only update the parts of the screen that had changed from the previous page. This is all due to the magic of curses:

        In order to update the screen optimally, it is necessary for the routines to know what the screen currently looks like and what the programmer wants it to look like next. For this purpose, a data type (structure) named WINDOW is defined… Note, therefore, that changing something on a window does not change the terminal. Actual updates to the terminal screen are made only by calling refresh() or wrefresh(). This allows the programmer to maintain several different ideas of what a portion of the terminal screen should look like. Also, changes can be made to windows in any order, without regard to motion efficiency. Then, at will, the programmer can effectively say “make it look like this”, and the package will execute the changes in an optimal way.

        (https://docs.freebsd.org/44doc/psd/19.curses/paper.pdf)

        1. 3

          The ncurses abstraction at least opens up for providing a non-terminal encumbered backend

          Well… all these years of both ncurses and GUI toolkits existing, and looks like no one has done this.

          1. 3

            I prototyped it about a year ago as part of https://github.com/letoram/arcan/wiki/tui, learned a few things in the process, will eventually go back to it when there aren’t higher priorities on the list.

          2. 3

            this would allow us to write formatting commands like fmt(underline with bright with no italic), which translates into > \x1b[4;1;23m at compile time.

            This seems better than ncurses in almost every way.

            1. 2

              ncurses isn’t just a way to say ‘make this underlined and bright but not italic’. It’s so much more than that.

          3. 5

            I think there is a lot of room still between TUIs & GUIs. TUIs shouldn’t have to be restricted to characters only IMO (although that would admittedly imply losing compatibility with terminals), also TUIs shouldn’t need to mimick GUIs, going as far as rendering drop down menus, window borders etc. Ideally there should be a generic canvas app that renders UIs for professional/experienced users that are not restricted to character display, and be mostly key driven (i.e. such apps would require some time investement upfront to gain more productivity benefits later [although context sensitive help for possible key combinations would be ideal]). These apps should should be composable and easy to customize/extend (think of an ‘edit source’ option instead of merely ‘view source’).

            1. 11

              One example of such UIs is GUI version of Emacs. It’s mostly text-based, but without downsides of terminals and with ability to draw pictures and set multiple fonts.

              Each time I tried keyboard-oriented UIs, but made of native widgets (for example Total Commander, IDEs), I had lots of problems and had to use mouse anyway. Focus changed wildly, there was bad indication where focus is, there were hundreds of tab stops.

              I think it would be cool to have GUI toolkit like Electron, but with terminal-like drawing (but with multiple fonts and images) instead of web browser.

              1. 1

                Exactly, a very lightweight and fast Electron like toolkit that is optimized for UIs for professionals that isn’t restricted to text-only. It could be cell-based for example (more like a spreadsheet instead of arbitrary x, y positions) but still allow for bitmap images and 3D renderings within a cell range. And it wouldn’t need a ‘toolkit’ with buttons, dropdowns, navbars and the like, because everything is keyboard-driven (with context sensitive help for keybindings in a specific UI state).

                Good point about (GUI) Emacs though.

                1. 10

                  Exactly, a very lightweight and fast Electron like toolkit that is optimized for UIs for professionals that isn’t restricted to text-only

                  Emacs?

              2. 2

                One of the older ones were NLP-like schemes that let you just say what you wanted to do in a restricted subset of English. They were often used in databases but sometimes outside. So, you didn’t need menus, hierarchies, etc. Just a keypress to activate a text field followed by the command.

                Just throwing it in there as an example of an alternative. Such NLP schemes aren’t always appropriate.

                1. 1

                  Interesting, do you have examples of or links to such alternatives? I am curious to learn more about it.

                  1. 1

                    They’re not in my bookmarks. I studied them a long time ago as part of AI research. A quick Google gives this project as an example of the kind of steps involved. Obviously, you wouldn’t use Java for the terminal version. :)

              3. 6

                Overall there is a lot of depth in this post and contains a great amount of detail about terminal I/O. I can understand the author’s hatred of ncurses, but just the sheer length of the post kinda shows the point of needing some level of abstraction when starting on a TUI projects, just due to the sheer number of gotchas between different terminal types. Are there any alternative / more modern libraries in existence?

                From a meta-post perceptive, things I don’t like: sentences aren’t capitalized. The author uses correct code blocks, syntax highlighting, most of it seems correctly proofread/edited, and yet she has chosen to not capitalize the first word of each sentence.

                Maybe I’m just nitpicky here, or maybe she’s trying to start a trend in the way language so be directed. After all at one time English use to capitalize all nouns (like German still does), and we use to indent paragraphs (which has been replaced with block formatting, except in novels). So maybe this is just the next thing.

                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.

                She shouldn’t shoot herself down here. I don’t really don’t think there’s a lot of evidence to support this “open source is hostel to women” idea that has been gaining traction. A lot of projects big and small have that Contributors Code of Conduct (or something based off of it) on them now. Are we still seeing backlash against women for being women? Are there any specific examples? (I’m not trying to troll; I really want to see real examples that don’t involve simply trying to get a CoC added to a project or removal of words like master/slave).

                The fact is, a lot of projects never gain traction in the OSS community. It’s difficult to make something people would use and to get other people to use your shit. A lot of big OSS libraries and projects today are backed by huge investment by big industry, or are supported by people in academia who can work on them between research and classes. That’s a bigger meta problem in the way we think of open source today.

                1. 3

                  I’m a nobody is of course not actually a reason to not do something. I’m a woman is especially not a reason to not do something. The idea that you need to be established for a project to gain traction is reasonable and maybe she doesn’t like being directly in the limelight.

                  After all if every woman had the attitude of “I’m a woman, therefore my project would not be well received” and that caused them not to start then no woman could ever be successful. It’s definitely not the right frame of mind even if it were true (and I’m not saying it’s not or that it is). I think it’s absurd to say that no discrimination happens in OSS, especially considering how recent the push to CoC has been and how much push back there has been. However I also think it’s absurd to say that one could never have a successful project as a woman as obviously women have lead successful OSS projects.

                  I don’t think saying “She shouldn’t shoot herself down” is very effective. We should try and evaluate what pressures make people feel this way and how we can help them overcome them. On boarding is something that is almost universally bad in OSS, and could be improved irrespective of gender. Saturn for F# is a good counterexample. https://github.com/SaturnFramework/Saturn . With it are words of encouragement, clear and direct expectations, and clear documentation. It’s missing a code of conduct which I think could help someone feel a little bit more secure about contributing, but otherwise pretty good. Those words of encouragement at the beginning help set a tone and example about how you’ll be treated when you contribute, and if you’re sharing your hard work to see what this thing can become it’s important that the culture around it is positive enough that you don’t feel punished for doing so.

                  1. 2

                    I don’t think saying “She shouldn’t shoot herself down” is very effective.

                    We know a lot of what pressures make people think that way. Her other essays, if some are about her, indicate she might have more pressures than most people. In any case, the negative attitude of “I shouldn’t even try because I believe X” coupled with dropping that into a write-up she put a lot of time into are both No No’s in general. It’s common in pep talk, therapy, self-help books, guides on entrepreneurship… everything about getting ahead despite challenges… to avoid thinking like that.

                    If the guidance includes others, they’ll also tell you not to whine to or accuse strangers by default since vast majority won’t be cool with that. I mean, let’s look at it it. The communities most likely to be giving her that much shit will not care if she writes that in her blog post. They’ll laugh. The ones who wouldn’t would be anywhere from concerned to wondering if she’s overly negative or having psychological problems. In other words, even many of them might think she’s just a pain to work with given she’s dropping stuff like that in middle of tech write-ups and most women aren’t.

                    It doesn’t matter which light I look at it. It’s some defeatist, over-projecting BS in her mind which isn’t going to help her if it’s true for projects she deals with or false for others where she looks like a downer. Showing some sympathy on top of discouraging such negative thinking or outbursts is a good piece of advice. It’s also common sense for a lot of people struggling in my area, esp minorities. Got to keep your head up and clear pressing forward they’d say. Well, the ones that aren’t in a slump or wanting to just quit.

                    Btw, that said, I totally agree with you that a welcoming community with good onboarding and support is a good thing. It will definitely help in general. It can also be a relief for these types of people. I’m just saying it’s general advice of all kinds of people to combat these negative, self-reinforcing beliefs and practices. They’re bad habits.

                    1. 2

                      I guess what I was trying to say and be clear I didn’t mean it quite so strongly as it came off, is that individual advice isn’t a solution to the systemic problem. I know you weren’t claiming it was and if I phrased it like a refutation that’s my mistake. I just saw the moment as an opportunity to talk about broader strategies that can help accommodate large groups instead of focusing on individuals. You’re right though we do broadly speaking know the problem. I also agree that no matter what the reality is, believing you can’t is never in your favor. Helping a person move past that mindset of “I can’t so I shouldn’t” is very important.

                      1. 1

                        Thanks for clarifying. That makes sense. I think we’re in agreement.

                    2. 0

                      think it’s absurd to say that no discrimination happens in OSS, especially considering how recent the push to CoC has been and how much push back there has been.

                      A lot of the push back on CoCs is that there doesn’t seem to be any evidence that they’re actually necessary, that there is any discrimination that needs to be addressed. I’m not sure I could discriminate against women even if I wanted to, I don’t know which ones are women! The only people in open source projects’ whose gender I’ve even noticed are people with obviously gendered names: if someone’s username is adam1423 (not a real example) then it’s obviously a guy, but otherwise I don’t even think about it, they’re just a person.

                      On boarding is something that is almost universally bad in OSS, and could be improved irrespective of gender. Saturn for F# is a good counterexample. https://github.com/SaturnFramework/Saturn . With it are words of encouragement, clear and direct expectations, and clear documentation.

                      I don’t think there’s much extra here that isn’t in most projects. A lot of projects I’ve seen (that are of decent size, at least) have some sort of ‘CONTRIBUTING’ file. I think people mistake documentation existing and documentation being rendered as HTML on GitHub. GitHub is not the only website out there for open source. There are a lot of resources on the internet. Most of the things mentioned in that file for Saturn are common to basically every project anyway.

                      People often don’t care about onboarding because it doesn’t actually matter to them whether you start contributing to their project.

                    3. 4

                      “She shouldn’t shoot herself down here.”

                      With her saying that, she has a negative attitude that casts every project in the same, discriminating light. She might be a pain in the ass to work with. That comment alone might get her ignored if a person reading a contribution saw it before. There’s others that would try to pull her in to help her out. I just think people should avoid saying stuff like that by default since politically-focused negativity is immediate turn off for many potential collaborators. Person A has it, Person B doesn’t, and so path of least effort and headaches is going with Person B.

                      “The fact is, a lot of projects never gain traction in the OSS community. It’s difficult to make something people would use and to get other people to use your shit.”

                      This right here is something to remember about introducing any new idea or practice. The default response is apathy. There’s an entire site dedicated to strategies for countering apathy to new products. Most that make it talk about how hard it was. There’s others that just took off but that’s rare. So, if wondering about negative responses, the first variable to eliminate (somehow) should be apathy. Most people just won’t give a shit.

                      1. 1

                        From a meta-post perceptive, things I don’t like: sentences aren’t capitalized. The author uses correct code blocks, syntax highlighting, most of it seems correctly proofread/edited, and yet she has chosen to not capitalize the first word of each sentence.

                        Maybe I’m just nitpicky here, or maybe she’s trying to start a trend in the way language so be directed. After all at one time English use to capitalize all nouns (like German still does), and we use to indent paragraphs (which has been replaced with block formatting, except in novels). So maybe this is just the next thing.

                        Like the CSS feedback from @johnaj, you are being nitpicky.

                        1. 2

                          I don’t understand why you’re dragging me into whatever discussion you are having. I merely informed the author that her HTML wasn’t written properly – breaking popular things like reader mode – so that she could fix it.

                          I haven’t read the entire article yet, but I think it is interesting so far.

                          1. 2

                            You were actually informing Lobsters that her HTML was broken. Usually I’d say send it to their comment box, email, or whatever. I didn’t see anything listed. Perhaps they don’t want to be contacted.

                            Anyway, probably best to tell just the author that kind of stuff since we can’t change it. If there’s no contact, then I’d say don’t even mention it since you’re just griping to us about what they are doing with their own site. Goes nowhere.

                            1. 3

                              Yeah, that’s true. I just don’t think it was pedantic. The page was difficult for me to read. I hoped the author would be on Lobste.rs and see it, which isn’t unusual, but I guess that isn’t the case here.

                          2. 1

                            I don’t think it’s nitpicking to criticise an article for not using capital letters or being formatted in a way that makes it hard to read. When I opened the article, I immediately closed it again instinctively. I didn’t read any of it. I literally opened it, saw it was light-on-dark low-constrast nearly-unformatted text and closed it, instinctively.

                            I’ve since read it, but I’ve found I do this a lot. If I open something and it’s badly formatted in this kind of way I unconsciously/instinctively close it within a few hundred milliseconds.

                        2. 2

                          despite what ncurses wants you to believe, you do not have to define “”“color pairs””” with each foreground-background pair you’re going to use

                          As someone who never actually touched ncurses as a developer: wat.

                          there should be a modern library to replace curses using the capabilities outlined here

                          People are definitely building these! Not 100% sure about how clean and pure-ANSI they are (seems like most of them do use terminfo, at least), but I know some libraries Without An Ncurses Dependency:

                          termion is a pure-Rust one, and Cursive can use it as a backend (though it’s not the default). tui-rs uses termion by default. termui claims to be pure Go. vty seems to be pure Haskell (idk why ncurses installation is mentioned for NixOS).

                          being compatible only with ANSI-capable terminals is a feature, not a bug, go the fuck away. terminfo is a fucking joke. nobody needs to target obscure dumb terminals from 1983 anymore.

                          Oh yeah. Terminfo causes all kinds of problems. But wait, it’s not just terminfo, there’s also termcap, and I think there’s some kind of abstraction/indirection that uses one of these depending on platform (err maybe that is ncurses, and we have two versions of ncurses, base and ports), and on FreeBSD you can easily end up with some programs looking in terminfo and others looking in termcap! awesome!

                          1. 4

                            As someone who never actually touched ncurses as a developer: wat.

                            “independent foreground and background colours” is a feature of the ANSI terminal model. Other, non-ANSI-compatible terminals existed, and some of them did require colour-pairs to be defined. Since it’s easy to emulate color-pairs on an ANSI terminal and impossible to implment the ANSI model on a color-pair terminal, well, ncurses went with the portable option.

                            Terminfo causes all kinds of problems. But wait, it’s not just terminfo, there’s also termcap, and I think there’s some kind of abstraction/indirection that uses one of these depending on platform (err maybe that is ncurses, and we have two versions of ncurses, base and ports), and on FreeBSD you can easily end up with some programs looking in terminfo and others looking in termcap! awesome!

                            termcap was invented by Bill Joy for BSD Unix, terminfo was invented later for System V Unix to fix a bunch of perceived problems with termcap. These days, ncurses implements the termcap APIs on top of the terminfo database, so they’re always in sync … but if you’re using a BSD, you might be using the historical curses library instead of ncurses.

                          2. 2

                            To the author: If you’re going to design your website like that, please make it readable with CSS disabled (and with “reader modes”). Use <pre> instead of <code> with { display: block; white-space: pre-wrap }. The design isn’t bad, but it doesn’t appeal to everyone.

                            1. 4

                              That entire color choice is freaking my eyes out, combined with each sentence being a non-capitalized paragraph I found it tough to read.

                              1. 2

                                i love the style of the site fwiw

                                1. 2

                                  please make it readable with CSS disabled

                                  Not a lot of sites are doing that anymore. :(

                                  1. 3

                                    To be fair, HTML was built for single documents, and developing anything more complicated requires significant styling. Yet that’s not the case here – this is an almost canonical HTML document, which makes it all the more surprising when it breaks without CSS.

                                2. 1

                                  fsync(1); // otherwise, terminal will only update on newline

                                  Uh…no? This is why return values should be checked – observing the EINVAL that this results in might have avoided this confusion.

                                  1. 1

                                    The really weird thing about ncurses to me is that there are basically no alternatives to it in C. There have been a few recent libraries I’ve seen that try to be an alternative, but a lot of them are built on ncurses, and those that aren’t all seem to be written in other languages and for other languages: I at least remember seeing ones for Go, Haskell and Rust.

                                    Yet it’s not like ncurses is nice. I can understand not writing an alternative implementation of something that everyone likes. But who likes interacting with ncurses? Nobody. It’s an awful API. It does really useful things, it’s incredibly portable and all that. But it’s also a crap API.