Anonymous

Notcurses: Difference between revisions

From dankwiki
 
(43 intermediate revisions by the same user not shown)
Line 8: Line 8:
I published a coherent textbook, "[https://www.amazon.com/dp/B086PNVNC9 Hacking the Planet! with Notcurses]", in April 2020. More details are available [[Hacking_The_Planet!_with_Notcurses|here]].
I published a coherent textbook, "[https://www.amazon.com/dp/B086PNVNC9 Hacking the Planet! with Notcurses]", in April 2020. More details are available [[Hacking_The_Planet!_with_Notcurses|here]].


I recorded a [[DANKTECH]] video, "[https://www.youtube.com/watch?v=mOmMcFXdd6k Console sex with Notcurses]" as a gentle intro (its demo has been superseded by the [https://www.youtube.com/watch?v=cYhZ7myXyyg 1.7.5 demo]). You can run this same demo on your local machine with <tt>[https://nick-black.com/notcurses/notcurses-demo.1.html notcurses-demo]</tt>.
I recorded a [[DANKTECH]] video, "[https://www.youtube.com/watch?v=mOmMcFXdd6k Console sex with Notcurses]" as a gentle intro (its demo has been superseded by the [https://www.youtube.com/watch?v=dcjkezf1ARY NOTCURSES III demo]). You can run this same demo on your local machine with <tt>[https://nick-black.com/notcurses/notcurses-demo.1.html notcurses-demo]</tt>.


==Features==
==Features==
* Advanced and extensive runtime querying for terminal capabilities
* Optional use of "alternate screen" where available (<tt>enter_ca_mode</tt>/<tt>exit_ca_mode</tt> terminfo capabilities)
* Optional use of "alternate screen" where available (<tt>enter_ca_mode</tt>/<tt>exit_ca_mode</tt> terminfo capabilities)
* All APIs use 24-bit 8bpc RGB color natively
* All APIs use 24-bit 8bpc RGB color natively
Line 18: Line 19:
** [[#Sprites|Sprites!]]
** [[#Sprites|Sprites!]]
* Full support for [[#Unicode|Unicode]], including wide glyphs and bidirectional text
* Full support for [[#Unicode|Unicode]], including wide glyphs and bidirectional text
** Composed keys (number pad, etc.) are mapped into [https://unicode.org/charts/PDF/U100000.pdf Private Supplementary Area B]
** Composed keys (number pad, etc.) are mapped outside the defined Unicode regions
* Image/video support via ffmpeg
* Image/video support via ffmpeg or OpenImageIO
* Subregion fade in/out
* Subregion fade in/out, text pulsing
* [[#Linear_interpolation|Linear interpolation]] for coloring geometric objects
* [[#Linear_interpolation|Linear interpolation]] for coloring geometric objects
* Multiple [[#Blitters|blitters]], rotation, and arbitrary scaling
* Multiple cell and pixel [[#Blitters|blitters]], rotation, and arbitrary scaling


==Rendering==
==Rendering==
[[File:Notcurses-structures.png|Data structures of a Notcurses context|thumb|right]]
[[File:Notcurses-Model.png|Data structures of a Notcurses context|thumb|right]]
The vast majority of functions draw to <tt>ncplane</tt> objects. A partial order (currently a total order) always exists over the planes. There is always at least one plane, the "standard plane". This plane cannot be resized, deleted, moved relative to the visible area, or reparented. Whenever notcurses updates its idea of the visible area's dimensions, it will resize the standard plane (references to the standard plane are <b>not</b> invalidated). Planes may otherwise be any size (invisible regions will not be rendered, and count only against memory), and can be moved to any position relative to the visible area. All planes, including the standard plane, can be freely moved along the z axis.
The vast majority of functions draw to <tt>ncplane</tt> objects. A partial order (currently a total order) always exists over the planes. There is always at least one plane, the "standard plane". This plane cannot be resized, deleted, moved relative to the visible area, or reparented. Whenever notcurses updates its idea of the visible area's dimensions, it will resize the standard plane (references to the standard plane are <b>not</b> invalidated). Planes may otherwise be any size (invisible regions will not be rendered, and count only against memory), and can be moved to any position relative to the visible area. All planes, including the standard plane, can be freely moved along the z axis.


Line 46: Line 47:


==Unicode==
==Unicode==
notcurses understands Unicode wide characters, and accounts for them. It is not possible to split the colors or styling of a wide glyph. It is not possible to print half of a glyph. It is not possible to print a narrow glyph over half of a wide glyph without obliterating the other half. These are all terminal emulator limitations.
Notcurses understands Unicode wide characters, and accounts for them. It is not possible to split the colors or styling of a wide glyph. It is not possible to print half of a glyph. It is not possible to print a narrow glyph over half of a wide glyph without obliterating the other half. These are all terminal emulator limitations.


Whether and how a given Unicode codepoint will be rendered depends almost entirely on font support. In general, <i>with sufficient fonts</i>, emoji and other pictographs will be properly rendered as expected. The Linux console has particularly limited fonts, and most characters beyond ASCII are not reliable in that environment. Certain Unicode glyphs are used by notcurses for drawing. Failure to render these glyphs reasonably will have a negative impact on notcurses functionality. Most important of these are the [https://unicode.org/charts/PDF/U2500.pdf Box Drawing Characters], the [https://unicode.org/charts/PDF/U2580.pdf Block Elements], and the [https://unicode.org/charts/PDF/U2800.pdf Braille Patterns].
Whether and how a given Unicode codepoint will be rendered depends almost entirely on font support. In general, <i>with sufficient fonts</i>, emoji and other pictographs will be properly rendered as expected. The Linux console has particularly limited fonts, and most characters beyond ASCII are not reliable in that environment. Certain Unicode glyphs are used by notcurses for drawing. Failure to render these glyphs reasonably will have a negative impact on notcurses functionality. Most important of these are the [https://unicode.org/charts/PDF/U2500.pdf Box Drawing Characters], the [https://unicode.org/charts/PDF/U2580.pdf Block Elements], and the [https://unicode.org/charts/PDF/U2800.pdf Braille Patterns].
Line 79: Line 80:
| Uses Braille characters, which have spotty font support.
| Uses Braille characters, which have spotty font support.
|-
|-
| <tt>NCBLITTER_SIXEL</tt>
| <tt>NCBLITTER_PIXEL</tt>
| 6x1->1
| variable->1
| Not yet implemented.
| Pixel blitter (see below)
|-  
|-  
|}
|}


[[File:Worldmap-sexblitter..png|800px|center]]
[[File:Worldmap-sexblitter..png|800px|center]]
===Pixel blitters===
[[File:pixel-orca.png|thumb|right|Ramble on, orca]]
Some terminals support pixel graphics, including the [[Sixel]] system pioneered by DEC. Notcurses can employ pixel graphics using the <tt>NCBLIT_PIXEL</tt> blitter.
* Sixel: xterm, mlterm, Alacritty (outstanding patch), WezTerm, foot, contour
* Kitty supports its own method (which is also supported by WezTerm)
* as does ITerm2 (which is also supported by WezTerm)
* the Linux framebuffer console supports its own graphics (via memory map)
Notcurses does not currently output ReGIS vector graphics, nor the iTerm2 protocol.
Some timings from notcurses 2.3.17, taken 2021-08-28 using:
{| class="wikitable"
|+ <tt>ncplayer -bpixel ../data/notcursesIII.mkv -d0 -t0 -q</tt>
! term
! version
! pgeom
! cgeom
! times
|-
| mlterm
| 3.9.0
| 880x1406
| 80x61
| 1m5.142s 1m.3.731s 1m3.631s
|-
| XTerm
| 368
| 880x1403
| 88x74
| 55.655s 55.433s 55.841s
|-
| alacritty
| 0.13.1
| 880x1400
| 88x70
| 55.716s 55.902s 55.709s
|-
| kitty
| 0.23.1
| 880x1440
| 88x70
| 33.179s 33.477s 33.385s
|-
| kitty
| 0.19.3
|880x1440
|88x70
| 54.722s 54.473s 54.867s
|-
|}


==Input==
==Input==
Notcurses provides input from keyboards and mice. Single Unicode codepoints are received from the keyboard, directly encoded as <tt>char32_t</tt>s. The input system must deal with numerous keyboard signals which do not map to Unicode code points. This includes the keypad arrows and function keys. These "synthesized" codepoints are enumerated in <tt>notcurses.h</tt>, and mapped into the [https://unicode.org/charts/PDF/U100000.pdf Supplementary Private Use Area-B] (U+100000..U+10FFFD). Mouse button events are similarly mapped into the SPUA-B.
Notcurses provides input from keyboards and mice. Single Unicode codepoints are received from the keyboard, directly encoded as <tt>char32_t</tt>s. The input system must deal with numerous keyboard signals which do not map to Unicode code points. This includes the keypad arrows and function keys. These "synthesized" codepoints are enumerated in <tt>notcurses.h</tt>, and mapped into the [https://unicode.org/charts/PDF/U100000.pdf Supplementary Private Use Area-B] (U+100000..U+10FFFD). Mouse button events are similarly mapped into the SPUA-B.


All events carry a <tt>ncinput</tt> structure with them. For mouse events, the x and y coordinates are reported within this struct. For all events, modifiers (e.g. "Alt") are carried as bools in this struct.
All events carry a <tt>ncinput</tt> structure with them. For mouse events, the x and y coordinates are reported within this struct. For all events, modifiers (e.g. "Alt") are carried as the <tt>modifiers</tt> bitfield in this struct.


==Transparency/Contrasting==
==Transparency/Contrasting==
Line 121: Line 175:


==Terminal emulators==
==Terminal emulators==
More information is available from the source tree in [https://github.com/dankamongmen/notcurses/blob/master/TERMINALS.md TERMINALS.md].
The two primary environmental factors affecting notcurses performance are the terminal emulator and the configured fonts.
The two primary environmental factors affecting notcurses performance are the terminal emulator and the configured fonts.


Line 206: Line 262:


===Notes on particular terminals===
===Notes on particular terminals===
The [https://github.com/dankamongmen/notcurses/blob/master/TERMINALS.md TERMINALS.md] document in Notcurses is (hopefully) well worth checking out.


* [https://invisible-island.net/xterm/ xterm], the first and (in many ways) the best.
* [https://invisible-island.net/xterm/ xterm], the first and (in many ways) the best.
Line 216: Line 273:
===Screen multiplexers===
===Screen multiplexers===
* <tt>screen</tt>: i've yet to see anything but a mess in screen
* <tt>screen</tt>: i've yet to see anything but a mess in screen
* <tt>tmux</tt>: i've only seen 256 colors work in tmux
* <tt>tmux</tt>: works decently well, aside from consuming bitmaps
* <tt>mosh</tt>: we look like shit in mosh and i wish we didn't


===Linux [[Consoles|console]]===
===Linux [[Consoles|console]]===
Line 226: Line 284:
====kmscon====
====kmscon====


==Releases==
==Major Releases==
 
{| class="wikitable"
{| class="wikitable"
! Release !! Date !! Key features
! Release !! Date !! Key features
|-
| [https://github.com/dankamongmen/notcurses/releases/tag/v3.0.0 3.0.0] || 2021-12-01
| New input system, kitty keyboard/GPM/XTMODKEYS support
|-
| [https://github.com/dankamongmen/notcurses/releases/tag/v2.4.0 2.4.0] || 2021-09-06
| Microsoft Windows and macOS support, Linux framebuffer graphics, "CLI mode"
|-
| [https://github.com/dankamongmen/notcurses/releases/tag/v2.3.0 2.3.0] || 2021-05-09
| Tree selector, tabbed interface, pixel blitting
|-
| [https://github.com/dankamongmen/notcurses/releases/tag/v2.2.0 2.2.0] || 2021-02-08
| libreadline, progress bars, notcurses-core extraction
|-
| [https://github.com/dankamongmen/notcurses/releases/tag/v2.1.0 2.1.0] || 2020-12-13
| Sexblitter, ncneofetch
|-
|-
| [https://github.com/dankamongmen/notcurses/releases/tag/v2.0.0 2.0.0] || 2020-10-12
| [https://github.com/dankamongmen/notcurses/releases/tag/v2.0.0 2.0.0] || 2020-10-12
| Stable API! Semantic versioning is in effect henceforth.
| Stable API!
|-
|-
| [https://github.com/dankamongmen/notcurses/releases/tag/v1.7.0 1.7.0] || 2020-08-30
| [https://github.com/dankamongmen/notcurses/releases/tag/v1.7.0 1.7.0] || 2020-08-30
Line 276: Line 348:


==See Also==
==See Also==
* [[outcurses]], my effects and widgets library for [[Ncurses]]
* The [https://vt100.net/emu/dec_ansi_parser Paul Williams] automaton for lexing DECspeak
* [https://invisible-island.net/xterm/ctlseqs/ctlseqs.html XTerm] control sequences
* [https://sw.kovidgoyal.net/kitty/protocol-extensions.html Kitty-specific] functionality
* [https://iterm2.com/documentation-escape-codes.html iTerm2 extension] escape sequences
* [https://jexer.sourceforge.io/ Jexer], a Java library of similar power
* [https://wezfurlong.org/wezterm/escape-sequences.html Wezterm extension] escape sequences
* [[outcurses]], my earlier effects/widgets library for [[Ncurses]]


[[File:Notcurses-0.4.0-bling.png|640px|center|Contact sheet from Notcurses 0.4.0 demo]]
[[File:Notcurses-0.4.0-bling.png|640px|center|Contact sheet from Notcurses 0.4.0 demo]]
[[CATEGORY: Terminals]]
[[CATEGORY: Projects]]