7 ms·
This seems complicated and error prone. Although I can see the advantages of this approach, it really makes me wonder whether the designers chose the right abst
by amelius 10y ago
This seems complicated and error prone. Although I can see the advantages of this approach, it really makes me wonder whether the designers chose the right abstractions.
Also, the fact that I can type "cat binary-file" and mess up my terminal settings tells me that they didn't clearly separated concerns.
- MaulingMonkey 10y ago> This seems complicated and error prone. Although I can see the advantages of this approach, it really makes me wonder whether the designers chose the right abstractions. Keep in mind that many of the original tty devices were teleprinters, and the physical actions of the printer head upon being commanded to backspace would involve moving the actual printer head back a character - potentially using an eraser head - and then potentially moving the pointer head back again once more if that advanced the head. It's perhaps complicated an error prone, but it's also the optimal movement of the printer head. You do not want to bake "complicated and error prone" into the peripherals of the time. You had no firmware. I'm not sure if you even had a proper ROM, necessarily. So you do it on the software side. There's no abstraction here per se - but a 1:1 mapping of commands to common sets of physical hardware actions. That's not even a bad thing - what exactly would the abstraction gain you back then? You might abstract the escape codes to use for a given terminal via a terminfo or termcap database, to support multiple devices, but the core actions were always the same. Hopefully you're not still using teleprinters in production - but someone is. And the VDUs that replaced teleprinters reused the same control mechanisms - keeps the complexity and thus unit price down, easier to retrofit / make backwards compatible with software expecting teleprinters, etc... I know at least one place still using fairly dumb VDUs in production, and these sequences are the simplest fastest commands you can send them to effectively implement "backspace". If you ape the same logic in your latest and greatest single-page javascript webpage "app", and you're not writing a terminal emulator, it might be the wrong abstraction. It's sane for ttys though. > Also, the fact that I can type "cat binary-file" and mess up my terminal settings tells me that they didn't clearly separated concerns. It's a gun with the potential to be a footgun. Benefits, drawbacks. Writing a shell script that wants to read passwords? cat a file which disables input echoing. After invoking readline, cat a different file to re-enable it. "Feature". Want to cobble together a quick script to use your laser printer to print barcodes? Create a binary file that creates the barcode you want, cat it, pipe that through sed a few times to replace the number, and then pipe straight to the appropriate /dev/ttyXY. I've actually seen this, fixed this, and updated this. Figuring out the correct keyboard inputs to give vi was 'fun'. "Feature". If you don't want to mess up your terminal, "view" or "vi" is likely the correct command - not cat.
- aap_ 10y ago> Writing a shell script that wants to read passwords? cat a file which disables input echoing. After invoking readline, cat a different file to re-enable it. "Feature". Sending control characters to the tty won't do that. Input echo is done in the kernel and you need an ioctl to disable it.
- MaulingMonkey 10y ago> Sending control characters to the tty won't do that Several terminals have support for, and escape codes to manage, local input echo: http://www.vt100.net/docs/vt102-ug/chapter5.html#S5.5.2.13 http://www.vt100.net/docs/vt102-ug/chapter5.html#S5.5.2.13 If the kernel is operating under the assumption that the device is operating under local input echo mode (e.g. the ioctl has already been invoked to disable kernel input echo, as the terminal is assumed to be handling it), sending escape codes to the tty will do that. EDIT: In case my air quotes around "Feature" weren't enough of a hint, I'm not actually recommending anyone do this.
- digi_owl 10y ago> Keep in mind that many of the original tty devices were teleprinters All of them were, tty is short for teletype after all.
- icebraining 10y agoIf the shell didn't allow cat to send commands to it (which may mess it up), it also wouldn't allow ncurses and such from using colours and other advanced features. It'd be a failure to separate concerns if the shell detect and treated cat output differently.
- lmm 10y ago> If the shell didn't allow cat to send commands to it (which may mess it up), it also wouldn't allow ncurses and such from using colours and other advanced features. But control commands shouldn't be commingled with general input/output. That's how you get security bugs like the recent bash CGI vulnerability. There should be an interface that allows ncurses etc. to use colours, but it should be via a distinct control channel, not "magic" sequences embedded in normal data.
- jstimpfle 10y agoMy answer to Ao7bei3s is also for you. Try to make a better design. You will (very likely) fail.
- Ao7bei3s 10y agoTerminal control could (and should) have been out of band, e.g. via ioctls on the fds of the tty between shell and subprocess, instead of in-band via "special characters", which usually (always?) hint at bad design (compare e.g. with SQL injection). As an example on how to do it right, consider how commands like "git diff" determine whether to paginate/colorize their output: they call the isatty(fd) stdlib function on stdout, which uses ioctl TIOCGETA to get terminal properties. Iff that fails, there's no TTY on the other end of the fd and "git diff" just writes the raw output. If only there even was a clean, consistently implemented, well-documented protocol... but there is not - few tools properly escape their output, and you can't get much right without a terminfo database, even with you can't get consistent results, and the protocol is a mess.
- jstimpfle 10y agoOOB is almost always a terrible idea. Urgent data like interrupts, as used in TCP (basically Unix signals over network), might be an exception. IOCTL's are a pain. Those who don't understand Unix are doomed to reinvent it, poorly. You should try to implement it the way you think it should be. The problem you will notice: "content" and "presentation" can't be easily separated because it's important when changes in presentation take effect. Also one man's presentation is the next man's content. They are just not independent streams, period. It's actually great that you can capture streams including control characters and replay them later. It works pretty well, especially these days where there aren't many competing instruction sets anymore. Even in HTML you need to tag elements with class names inline. (And the HTML approach could never work for general purpose terminals -- as opposed to crippled, specialized ones, like Mathematica / Jupyter notebooks). -- > If only there even was a clean, consistently implemented, well-documented protocol... but there is not - few tools properly escape their output, and you can't get much right without a terminfo database, even with you can't get consistent results, and the protocol is a mess. You can go GUI. But many of the programs you want to use aren't available for GUI, guess why... isatty() is a hack, but it's convenient and has very low false positives. If you filter output into another program before sending it to the terminal, the hack falls flat. You then need to provide a means for the user to be explicit, like `git diff --color=always`.
- throwawayish 10y agoThis is legacy built on legacy built to work with minimal CPU cycles on existing hardware designed to be compatible with hardware from the 40s. Yes, concerns aren't separated ;) A much more recent and far superior design can be found in Windows NT, where things like coloring are done entirely through an ioctl-equivalent (whereas Unix has amounts of in-band signaling, while some later extension use tty_ioctl).
- netheril96 10y agoYet the Windows command line is barely usable, with the horrible support of unicode and the unbearable performance.
- WayneBro 10y agoThat's because Microsoft took over the entire world of computing by selling easy to use GUI tools instead of command line tools.
- digi_owl 10y agonah, what they did was a masterstroke of contract work that allowed them to be the de-facto compatibility layer for every two bit IBM PC clone out there. The rest is history.
- WayneBro 10y agoPffft, it takes a lot more than a contract to maintain an empire the size of Microsoft. Their tech beats OSS in many areas and there is definitely a reason that people continually pay to use it.
- jstimpfle 10y agoioctls are terrible. I've never used the "Windows NT design" but how would they implement e.g. tunnelling through SSH or a serial connection?
- kps 10y ago
- jstimpfle 10y agoThey did choose the right abstractions. It was a great success. You can't separate concerns that you can't clearly define. What cat does is what you tell it to do. If you need escaping -- well, do it (base64 or whatever).
- eru 10y agoFor me this seems like something that shouldn't be handled in a kernel these days.
- JdeBP 10y agoThe binary file problem is nothing to do with abstractions and concerns, because it goes away if, as the designers of mosh did, one decides that one's terminal will not implement ISO 2022 character set switching.