Outcurses: Difference between revisions

No edit summary
No edit summary
Line 205: Line 205:


The natural implication is that, prior to calling a panelreel function, the caller ought take a lock, and this lock ought cover *all material relevant to display, for all tablets*. Only upon return from outcurses can this lock be unlocked. Yes, this is a very coarse locking scheme, with some latency in the critical section. If you need to continue processing events at a high rate while updating the panelreel, collapse them into an intermediate structure, and have your calling thread pull in those data. Or something. The most common effect of failure to do this is empty lines in a tablet.
The natural implication is that, prior to calling a panelreel function, the caller ought take a lock, and this lock ought cover *all material relevant to display, for all tablets*. Only upon return from outcurses can this lock be unlocked. Yes, this is a very coarse locking scheme, with some latency in the critical section. If you need to continue processing events at a high rate while updating the panelreel, collapse them into an intermediate structure, and have your calling thread pull in those data. Or something. The most common effect of failure to do this is empty lines in a tablet.
===Panelreel history/design===
I implemented panelreels as tightly-interwoven UI code in two projects during the early 2010s: [[growlight]] and [[omphalos]]. In both projects, the ncurses code ran to thousand of lines, and rapidly became difficult to maintain (I only resolved [https://github.com/dankamongmen/growlight/issues/23 one bug] in growlight's UI late in 2019). The system did, however, seem both performant and useful, with general applications. I resolved to [https://github.com/dankamongmen/growlight/issues/43 extract] the code from [https://github.com/dankamongmen/omphalos/issues/21 both] projects, unify it, and make it generally available. Both applications were built around a common core, with pluggable UIs defining distinct applications, each registering callbacks defined by their core's interface. Omphalos defined more callbacks than growlight:
<tt>omphalos/ui/ncurses.c<tt> 2019-11-06 (0.99.9~pre):
<pre>
  pctx.iface.packet_read = packet_callback;
  pctx.iface.iface_event = interface_callback;
  pctx.iface.iface_removed = interface_removed_callback;
  pctx.iface.vdiagnostic = vdiag_callback;
  pctx.iface.wireless_event = wireless_callback;
  pctx.iface.srv_event = service_callback;
  pctx.iface.neigh_event = neighbor_callback;
  pctx.iface.host_event = host_callback;
  pctx.iface.network_event = network_callback;
</pre>
<tt>growlight/ncurses.c<tt> 2019-11-06 (1.1.3):
<pre>
  const glightui ui = {
    .vdiag = vdiag,
    .boxinfo = boxinfo,
    .adapter_event = adapter_callback,
    .block_event = block_callback,
    .adapter_free = adapter_free,
    .block_free = block_free,
  };
</pre>
In growlight, the tablet-level object is the adapter, detailed at the first level by the block device. In omphalos, it is the interface, detailed at the first level by L2 hosts. Both divide callbacks between a removal event and an update, while neither requires a distinct creation event.


==Panel animations==
==Panel animations==