Curses: Update the comments

This commit is contained in:
Fabian Boehm
2024-06-04 22:23:46 +02:00
parent 90bd8cc02b
commit 3411b72a6d

View File

@@ -1,12 +1,7 @@
//! A wrapper around the system's curses/ncurses library, exposing some lower-level functionality //! A wrapper around the terminfo library to expose the functionality that fish needs.
//! that's not directly exposed in any of the popular ncurses crates. //! Note that this is, on the whole, extremely little, and in practice terminfo
//! //! barely matters anymore. Even the few terminals in use that don't use "xterm-256color"
//! In addition to exposing the C library ffi calls, we also shim around some functionality that's //! do not differ much.
//! only made available via the ncurses headers to C code via macro magic, such as polyfilling
//! missing capability strings to shoe-in missing support for certain terminal sequences.
//!
//! This is intentionally very bare bones and only implements the subset of curses functionality
//! used by fish
use crate::common::ToCString; use crate::common::ToCString;
use crate::FLOGF; use crate::FLOGF;
@@ -16,8 +11,7 @@
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
/// The [`Term`] singleton, providing a façade around the system curses library. Initialized via a /// The [`Term`] singleton. Initialized via a call to [`setup()`] and surfaced to the outside world via [`term()`].
/// successful call to [`setup()`] and surfaced to the outside world via [`term()`].
/// ///
/// It isn't guaranteed that fish will ever be able to successfully call `setup()`, so this must /// It isn't guaranteed that fish will ever be able to successfully call `setup()`, so this must
/// remain an `Option` instead of returning `Term` by default and just panicking if [`term()`] was /// remain an `Option` instead of returning `Term` by default and just panicking if [`term()`] was
@@ -41,9 +35,6 @@ pub fn term() -> Option<Arc<Term>> {
/// The safe wrapper around curses functionality, initialized by a successful call to [`setup()`] /// The safe wrapper around curses functionality, initialized by a successful call to [`setup()`]
/// and obtained thereafter by calls to [`term()`]. /// and obtained thereafter by calls to [`term()`].
///
/// An extant `Term` instance means the curses `TERMINAL *cur_term` pointer is non-null. Any
/// functionality that is normally performed using `cur_term` should be done via `Term` instead.
#[derive(Default)] #[derive(Default)]
pub struct Term { pub struct Term {
// String capabilities. Any Some value is confirmed non-empty. // String capabilities. Any Some value is confirmed non-empty.
@@ -339,16 +330,12 @@ fn new(db: terminfo::Database) -> Self {
} }
} }
/// Calls the curses `setupterm()` function with the provided `$TERM` value `term` (or a null /// Initializes our database with the provided `$TERM` value `term` (or None).
/// pointer in case `term` is null) for the file descriptor `fd`. Returns a reference to the newly /// Returns a reference to the newly initialized [`Term`] singleton on success or `None` if this failed.
/// initialized [`Term`] singleton on success or `None` if this failed.
/// ///
/// The `configure` parameter may be set to a callback that takes an `&mut Term` reference to /// The `configure` parameter may be set to a callback that takes an `&mut Term` reference to
/// override any capabilities before the `Term` is permanently made immutable. /// override any capabilities before the `Term` is permanently made immutable.
/// ///
/// Note that the `errret` parameter is provided to the function, meaning curses will not write
/// error output to stderr in case of failure.
///
/// Any existing references from `curses::term()` will be invalidated by this call! /// Any existing references from `curses::term()` will be invalidated by this call!
pub fn setup<F>(term: Option<&str>, configure: F) -> Option<Arc<Term>> pub fn setup<F>(term: Option<&str>, configure: F) -> Option<Arc<Term>>
where where
@@ -513,7 +500,7 @@ pub fn tparm0(cap: &CStr) -> Option<CString> {
terminfo::expand!(cap).ok().map(|x| x.to_cstring()) terminfo::expand!(cap).ok().map(|x| x.to_cstring())
} }
/// Covers over tparm(). /// Covers over tparm() with one parameter.
pub fn tparm1(cap: &CStr, param1: i32) -> Option<CString> { pub fn tparm1(cap: &CStr, param1: i32) -> Option<CString> {
assert!(!cap.to_bytes().is_empty()); assert!(!cap.to_bytes().is_empty());
let cap = cap.to_bytes(); let cap = cap.to_bytes();