[RFC PATCH v6] Input/Output Terminal Abstraction

Grant Erickson <[email protected]> Wed, 3 Apr 2024 10:22:08 -0700
Newsgroups dev.linux.lists.ell
Message-ID <[email protected]>
This expands on Marcel Holtman's 2023-12-22 RFCv4 patch for an
input/output terminal abstraction.

Substantive changes from the v5 version:

  * Add an 'l_term_is_acquired' introspection function.
    
    This adds an 'l_term_is_acquired' introspection function that
    indicates whether the terminal has acquired and modified the TTY
    settings for the input and output descriptors associated with the
    terminal.

  * Rename 'l_term_{open,close}'.
    
    This renames 'l_term_{open,close}' to 'l_term_{acquire,release}' since
    this aligns more closely with what is happening with the underlying
    file descriptors. In particular, those descriptors are not being
    opened or closed. Rather, their TTY parameters are being saved and
    altered on 'open' (now 'acquire') and restored on 'close' (now
    'release'). At no point are the descriptors being transformed with the
    'open' or 'close' system calls.

  * Return error on writes if the output descriptor is invalid.
    
    This returns -EBADF for 'putnstr' and 'vdprintf' if the output
    descriptor for the terminal is invalid.

  * Do not return -EPERM for 'putnstr' and 'vprint' if not running.
    
    If the 'is_running' flag is not asserted there is no need to return
    -EPERM since it is still valid to write to the terminal when it is not
    running (or acquired in the new parlance).

Substantive changes from the v4 version:

  * Return status is 'int' rather than 'bool' with 0 as success and <
    0 as failure where the failures are negated POSIX error
    numbers. This removes the need for system integrators to intuit
    their own errors on a previously-false Boolean return status.

  * Makes 'l_term_set_{input,output}' public functions.

  * Adds observer functions for the terminal rows and columns.

  * Adds a modifier function for the terminal bounds.

  * Adds:

      - l_term_io_func_t
      - l_term_set_io_handler
      - l_term_process
      - l_term_io_callback

    Collectively, these make the abstraction run loop adaptable with a
    default callback that can be easily used with ELL's run loop,
    'l_term_io_callback'.

  * Adds 'l_term_[v]print' which complete the output interface.

    Of course, its always possible to perform this outside of an atop
    the existing functions; however, this eliminates integrators from
    having to manage the buffers necessary to do this.

This has proven to work well with the RFCv4 l_edit interfaces and the
corresponding demo-{cli,edit} applications.

Grant Erickson (8):
  term: Initial revision.
  ell: Add include directive for 'ell/term.h'.
  ell/Makefile: Added 'term.[ch]' to HEADERS and SOURCES.
  term: Added 'l_term_*' symbols.
  ell/term: Do not return -EPERM for 'putnstr' and 'vprint' if not
    running.
  ell/term: Return error on writes if the output descriptor is invalid.
  ell/edit: Rename 'l_term_{open,close}'.
  ell/term: Add an 'l_term_is_acquired' introspection function.

 Makefile.am |   2 +
 ell/ell.h   |   1 +
 ell/ell.sym |  22 +++
 ell/term.c  | 501 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 ell/term.h  |  71 ++++++++
 5 files changed, 597 insertions(+)
 create mode 100644 ell/term.c
 create mode 100644 ell/term.h

-- 
2.42.0