News for hackers. Stuff that matters.
Re:ANSI escape codes (2019) by 112233 on Wednesday February 03, 2021 @08:26AM (#26013384)
In my horrible opinion, you can have a fairly portable terminal application without using the abomination that is libncurses, just straight escape codes / control sequences.

Main reason is that most of current terminal emulators are actually xterm emulators: they support a good subset of xterm features. Also, the exceedingly strange console that was in Windows 95 is finally out. What quirks and differences are left, can easily be detected at runtime, no need for $TERM and terminfo/termcap

Re:ANSI escape codes (2019) by chasil on Wednesday February 03, 2021 @11:06AM (#26014943)
This is my korn-shell fragment that I use to set up color codes. Everything but the final print is posix-compliant (change it to a printf to run under bash).

    N='\033[' x=30

    for a in Bl R G Y B M C W # 4-bit Black Red Green Yellow Blue Magenta Cyan White
    do eval $a='$N'"'"$((   x  ))"m'" \
           b$a='$N'"'"$((60+x  ))"m'" \
        ${a}bg='$N'"'"$((10+x  ))"m'" \
       b${a}bg='$N'"'"$((70+x++))"m'"      # bX=bright Xbg=background bXbg=brgt bgnd
    done

    N=$N'0m' x=0

    print $bB'This is bright blue.'$N
Re:ANSI escape codes (2019) by JNRowe on Wednesday February 03, 2021 @02:28PM (#26018002)
This is one of the many cool things that zsh comes with out of the box. It ships an autoload-able colors¹ script that does largely the same thing as your fragment, but you know it available wherever zsh is.

In much the same way it comes with both a termcap² and terminfo³ module, allowing you to easily avoid hardcoding system specific escapes in to your config.

¹ https://github.com/zsh-users/zsh/blob/master/Functions/Misc/...

² http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-...

³ http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-...

Re:ANSI escape codes (2019) by samatman on Wednesday February 03, 2021 @02:24PM (#26017960)
Agreed.

We made two decisions early on: xterm is the only terminal protocol, and UTF-8 is the only encoding. This has spared us unending amounts of pain, because we don't abstract over these things. There is a bit of divergence between xterm implementations, but for what we do, not much: if you want to print images there are a few strategies, none of them universal, and the closest (sixel) isn't great imho.

We've also found that, with a modern terminal, a lot of what curses brings to the table isn't necessary. While we did divide the terminal up into zones, and only repaint changed zones, we shouldn't have bothered: as long as you hide the cursor when you start a paint, and show it after you put it back, filling the entire screen with a complex/colorful xterm pattern happens within one refresh, so no flicker.

There is certainly no need to calculate a minimal delta change and only print that, on a reasonably modern system (anything from the last ten years will do).

Re:ANSI escape codes (2019) by ygra on Wednesday February 03, 2021 @10:59AM (#26014808)
> the exceedingly strange console that was in Windows 95

That only ever tried to be a terminal emulator when ansi.sys had been loaded. But it's been gone for quite a while now. The Windows console host on the other hand only gained terminal emulator capabilities in somewhat recent Windows 10 versions.

Re:ANSI escape codes (2019) by otabdeveloper4 on Wednesday February 03, 2021 @03:01PM (#26018409)
This.

There is no reason to use terminfo or libncurses in 2021.

Re:ANSI escape codes (2019) by chasil on Wednesday February 03, 2021 @04:14PM (#26019205)
The funny thing is that termcap and vi were not created for a DEC terminal.

They were created specifically for the Lear Siegler ADM-3A, which predates the VT100. The work was done entirely by Bill Joy, who later joined Sun Microsystems.

https://jbcrawford.us/history/computers/adm3a

Re:ANSI escape codes (2019) by blueflow on Wednesday February 03, 2021 @03:51PM (#26018934)
How would you check if a incoming escape sequence is the F1 key pressed by the user?
Re:ANSI escape codes (2019) by otabdeveloper4 on Thursday February 04, 2021 @12:27AM (#26022912)
Just assume your the terminal is a vt220, a.k.a. xterm.