PDCursesMod Documentation

repository·master·Indexed 18 days ago

https://github.com/bill-gray/pdcursesmod

A highly portable implementation of the X/Open curses API that extends the original PDCurses project. It provides various rendering backends including traditional terminal/console modes, SDL2, OpenGL 3.3, Linux Framebuffer, DRM, and DOS/DOSVGA. The library supports wide-character (Unicode) and UTF-8 encoding, and includes a suite of demonstration programs.

Tokens
30.9K
Snippets
76
Records
135
Agent score
64%

What's inside PDCursesMod

  1. Overview of PDCursesMod

    master

    PDCursesMod (Public Domain Curses Modified) is an implementation of X/Open curses designed for multiple platforms. It is a modified version of the official PDCurses project that adds several 'flavors' or backends, including Windows GUI, VT-like console, Linux/*BSD framebuffer, DOSVGA, OpenGL, and Plan 9.

    Most programs written for ncurses or the official PDCurses will compile and run with PDCursesMod provided you use the common subset of curses functionality.

  2. Access PDCurses documentation and guides

    master

    PDCurses provides several types of documentation depending on your needs:

    • User's Guide: Provides a basic overview for general usage.
    • Implementor's Guide: Contains information required for porting PDCurses to new platforms.
    • Manual: Detailed documentation for every function and component.
    • History: Project history and evolution.

    For platform-specific instructions (such as DOS, SDL, Windows, X11, or OpenGL), consult the README file located in the corresponding platform directory.

  3. How the curses library works

    master

    The curses library provides a procedural interface for screen-handling and updating via 'windows'. A window is a two-dimensional array of characters representing part or all of a terminal screen.

    Core Workflow:

    1. Manipulation: Use routines like move() and addch() to manipulate the default window, stdscr (which represents the whole screen).
    2. Buffering: Applications add data to the window in any order. The curses package maintains an internal record of what characters are on the screen.
    3. Refreshing: Call the refresh() routine. The library calculates the minimal set of operations required to update the physical terminal to match the window's contents, optimizing for the specific terminal type.

    Window Types:

    • Standard Windows: Created via newwin(). For every routine that manipulates stdscr (e.g., move()), there is a corresponding routine prefixed with w to manipulate a specific window (e.g., wmove()).
    • Pads: Large windows that are bigger than the actual screen size.
    • Partial Windows: Windows that may only be partially visible on the screen.
  4. Naming conventions for implementation functions

    master

    When implementing a port, follow these naming rules to avoid collisions with application code:

    • Public Functions: Required implementation functions must have extern scope.
    • Internal Functions: Any helper functions created as part of your implementation should ideally have static scope.
    • Non-static Helpers: If a helper function cannot be static, it must be prefixed with PDC_ (e.g., PDC_my_helper()).
  5. How Soft Label Keys (SLK) work

    master

    Soft Label Keys (SLK) are a separate window area used for labels. Clicking an SLK returns a function key press (e.g., clicking the leftmost SLK returns KEY_F(1)).

    Initialization

    slk_init(int fmt) must be called before initscr() or newterm(). This call removes 1 or 2 lines from the usable screen to accommodate the SLK window.

    Formats

    • 0: 3-2-3 format
    • 1: 4-4 format
    • 2: 4-4-4 format
    • 3: 4-4-4 format with index line
    • 55: 5-5 format (PDCurses specific)
    • Hexadecimal Format (PDCursesMod extension): You can pass a hex value to slk_init() to specify custom widths. For example, 0x414 results in a 4-1-4 format. Negating the fmt value adds an index line.

    Re-initialization

    In PDCursesMod, you can call slk_init() after initscr() to reset the label format. If you do this, you must reset the label text and call slk_refresh(). Note that you cannot toggle the index line or turn SLK on/off after initscr() has been called.

    int slk_init(int fmt);
    int slk_set(int labnum, const char *label, int justify);
    int slk_refresh(void);
    int slk_noutrefresh(void);
    char *slk_label(int labnum);
    int slk_clear(void);
    int slk_restore(void);
    int slk_touch(void);
    int slk_attron(const chtype attrs);
    int slk_attr_set(const attr_t attrs, short color_pair, void *opts);
    int slk_attroff(const chtype attrs);
    int slk_attr_off(const attr_t attrs, void *opts);
    int slk_color(short color_pair);
    int slk_wset(int labnum, const wchar_t *label, int justify);
    wchar_t *slk_wlabel(int labnum);
  6. Platform limitations and warnings for VT-style sequences

    master

    The VT platform uses a mix of xterm, VT-100, VT-200, and ANSI escape sequences. Users should be aware of the following limitations:

    • Windows 10/11: Use of the VT platform is strongly discouraged on Windows. While partially supported, you are limited to 16 colors (no RGB), mouse support is unreliable, and the console size cannot be determined or set. Use WinGUI or WinCon instead.
    • Key Support: Arrow keys and some function keys are recognized. However, Shift, Ctrl, and Alt modifiers (including arrows) are mostly not correctly identified. Extended keyboard keys (e.g., Browser Back/Forward, Search, Refresh) are not detected.
    • Mouse: Some mouse input is recognized, but it is not guaranteed across all terminals.
    • Clipboard: Clipboard functions are currently completely absent on this platform.
    • Color: Assumes 256 colors are available (16 in NANSI mode), but can use full RGB if the terminal supports it and PDC_VT=RGB is configured.
  7. Configure 16-bit mode fonts

    master

    In 16-bit mode (built with WIDE=Y), PDCurses uses TrueType fonts and 16-bit Unicode (Basic Multilingual Plane) character mapping.

    • Set font path: Use the PDC_FONT_PATH compile-time define or the pdc_ttffont runtime function.
    • Set font size: Use the PDC_FONT_SIZE compile-time define or the pdc_font_size runtime function.
    • Set font via environment variable: PDC_FONT points to a TrueType font.
    • Default font: /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf
  8. Configure 8-bit mode fonts

    master

    In 8-bit mode, the font is a monospaced BMP (32 characters wide by 8 characters tall). The first palette entry is the background, and the last is the foreground.

    • Set font via environment variable: Use PDC_FONT to point to a BMP file.
    • Fallback behavior: If PDC_FONT is not set, PDCurses looks for pdcfont.bmp in the current directory. If that is missing, it uses the built-in font437.h encoding.
  9. Implementing the acs_map data structure

    master

    A PDCurses port must provide acs_map[], a 128-element array of chtypes. This table maps characters to the VT100 Alternate Character Set (ACS).

    Requirements:

    • PDC_transform_line() must use this table. When it encounters a chtype with the A_ALTCHARSET flag set and an A_CHARTEXT value in the range 0-127, it must render the character using the corresponding value from acs_map[] instead of the original value.
    • Any control characters (0-31 and 127) used in acs_map[] must have the A_ALTCHARSET flag set.
    • Implementations should provide suitable values for all ACS_ macros defined in curses.h.
    • Other values in the table should be filled with their own indices (e.g., acs_map['E'] == 'E').
    • The table can be hardwired or populated via PDC_scr_open().
  10. Manage window depth using panels

    master

    The panel API allows you to manage depth relationships between windows. Instead of windows simply overwriting each other, panels can be stacked in a 'deck'. The initial stdscr window sits at the very bottom, beneath all panels.

    Core Workflow:

    1. Create a panel associated with a window using new_panel(WINDOW *win).
    2. Manipulate the deck order using top_panel(), bottom_panel(), panel_above(), or panel_below().
    3. Hide or show panels using hide_panel() and show_panel().
    4. Crucial Step: After manipulating panels, you must call update_panels() to refresh the virtual screen to reflect the new depth relationships, and then call doupdate() to refresh the physical screen.

    Note: Use move_panel() to move a panel; do not use mvwin() on the underlying window, as this can break the panel logic.

    PANEL *new_panel(WINDOW *win);
    void update_panels(void);
    // After update_panels, call doupdate() to see changes
  11. Set background images and icons

    master

    PDCurses for SDL supports optional background images and window icons via environment variables.

    Backgrounds

    Used when start_color() hasn't been called or when a color pair's background is set to -1. The image is tiled to cover the window.

    • Environment variable: PDC_BACKGROUND (defaults to pdcback.bmp).

    Icons

    Sets the window icon via SDL_WM_SetIcon().

    • Environment variable: PDC_ICON (defaults to pdcicon.bmp, then the built-in PDCurses logo).