**NeoUI** (`libneoui.so` + `/usr/include/neoui.h`) is the native `240x320` QVGA graphical user interface SDK for **Bananarchy Linux**, paired with **NeoNet** (`neonet.yab`), a `libcurl` + POSIX socket C FFI networking library for Yabasic.
1. A **C-compatible FFI (`neoui_*`)** designed for both C programs and foreign-function interfaces (such as **Yabasic**`frnfn_call` / `frnfn_call$`, LuaJIT FFI, Janet, Python `ctypes`, etc.).
2. A **C++20 SDK (`namespace bananarchy`)** providing `ThemeSpec`, `PluginTheme`, `NeoWindow`, and direct Pango/Xft/image helpers used across all 14 built-in Bananarchy DWM plugins.
3. A **Yabasic UI wrapper library (`neoui.yab`)** preinstalled in `/home/user/Projects/neoui.yab` (and symlinked at `/usr/lib/neoui.yab`), paired with a full showcase application (`/home/user/Projects/neoui_demo.yab`).
4. A **Yabasic networking wrapper library (`neonet.yab`)** preinstalled in `/home/user/Projects/neonet.yab` (and symlinked at `/usr/lib/neonet.yab`), wrapping `libcurl.so.4` and musl `libc` via `libffi` for one-line HTTP/HTTPS requests with custom headers as well as raw TCP, TLS, and UDP socket data exchange, paired with a combined NeoNet + NeoUI demo application (`/home/user/Projects/neonet_demo.yab`).
| `/usr/lib/neoui.yab` | `overlay/rootfs/usr/lib/neoui.yab` | Symlink to `/home/user/Projects/neoui.yab` so `import neoui` works from any working directory |
| `/home/user/Projects/neoui_demo.yab` | `overlay/rootfs/home/user/Projects/neoui_demo.yab` | Interactive 3-tab Yabasic showcase demonstrating all NeoUI widgets, multi-tap input, custom drawing, modals, and live theme reload |
| `/usr/lib/neonet.yab` | `overlay/rootfs/usr/lib/neonet.yab` | Symlink to `/home/user/Projects/neonet.yab` so `import neonet` works from any working directory |
- **Zero-flicker offscreen double buffering**: every NeoUI window (`240x296` at `X=0, Y=24`, directly below the 24px `dwm` top status bar) renders into an offscreen X11 `Pixmap` during `neoui_begin_frame()` .. `neoui_end_frame()` and copies the completed frame to the visible window in a single `XCopyArea` call.
- **Automatic `.Xresources` / `.xth` theme resolution**: NeoUI automatically parses the active theme from X11 `RESOURCE_MANAGER` and `~/.Xresources`, derives 29 semantic color tokens and 4 proportional Pango font sizes (`Small`, `Main`, `Icon`, `Large` scaled from `theme.baseFontSize`), and hot-reloads on the fly whenever `RELOAD_THEME` arrives on `/tmp/dwm_plugin_<app_name>.fifo` or `.Xresources` changes on disk.
- **FFI-safe return types**: every `extern "C"` function in `neoui.h` returns `int` (`int32`), `uint32_t` (`uint32`), or `const char*` (`string`)—never `void`—so FFI callers like Yabasic's `frnfn_call` work without `void`-return restrictions.
Any widget parameter accepting `icon_str` (or `neoui_icon(name)`) resolves the following symbolic names to their Nerd Font UTF-8 codepoints (or passes raw UTF-8 strings through unchanged):
When `#include <neoui.h>` is compiled under C++, it also exposes the `bananarchy` namespace used by Bananarchy's native DWM plugins (`src/dwm-plugins/*.cpp` and `src/xdrawer/xdrawer.cpp`).
-`std::string formatMultiTapBar(prefix, table, activeIdx, makeUpper, maxItems = 7, maxChars = 21)`: formats a scrolling candidate bar window centered around `activeIdx` so long symbol sequences (such as the 33-character `1` key table) never overflow the `240px` viewport.
-`std::string tailFitPangoText(layout, text, maxWidthPx)`: returns the UTF-8 suffix of `text` that fits within `maxWidthPx`.
-`bool loadImageRgb24(path, &outRgb, &outW, &outH)`: decodes JPEG (`libjpeg-turbo`), PNG (`libpng`), or other formats (`ffmpeg` fallback) into 24-bit RGB.
-`void scaleRgb24ToBgrxCanvas(srcRgb, srcW, srcH, dstBgrx, canvasW, canvasH, bgPixel, scaleMode)`: scales 24-bit RGB into a 32-bit BGRX `XImage` buffer (`NEO_SCALE_FIT`, `NEO_SCALE_FILL`, or `NEO_SCALE_STRETCH`).
-`void downscaleViewfinder800x600To240x180(srcRgb, dstBgrx, zoomFactor)`: rotates the raw `800x600``GC2395` camera frame 90 degrees clockwise and samples the centered 4:3 region (`600x450`) into the `240x180` viewfinder buffer.
Bananarchy includes `/home/user/Projects/neoui.yab` (symlinked to `/usr/lib/neoui.yab`), which wraps every C FFI function in `/usr/lib/libneoui.so` using Yabasic's native `libffi` foreign function interface (`frnfn_call` and `frnfn_call$`).
- **From the file manager (`xfiles`)**: navigate to `/home/user/Projects/`, highlight `neoui_demo.yab` (or your own `.yab` file), and press **Center `OK` (`Return`)**.
Because `/usr/lib/neoui.yab` is symlinked to `/home/user/Projects/neoui.yab`, any `.yab` script in any directory can import `neoui` with a single line:
```yabasic
import neoui
```
- All exported subroutines can be called directly (e.g. `neoui_init("myapp", 0)`, `neoui_draw_header(...)`) or qualified with `neoui.` (`neoui.neoui_init(...)`).
- All module constants are accessed with the `neoui.` prefix (e.g. `neoui.TEXT_YELLOW`, `neoui.FONT_MAIN`, `neoui.COLOR_ACCENT`, `neoui.EV_KEY_PRESS`, `neoui.KEY_OK`).
## 6. NeoNet networking SDK reference for Yabasic (`neonet.yab`)
**NeoNet** (`/home/user/Projects/neonet.yab`, symlinked at `/usr/lib/neonet.yab`) is the native networking library for Yabasic on Bananarchy Linux. It wraps `/usr/lib/libcurl.so.4` (`OpenSSL`, `nghttp2`, `zlib`, `brotli`, `zstd`, `c-ares`) and musl `libc` (`open_memstream`, `getaddrinfo`, `socket`, `connect`, `send`, `recv`, `poll`) via Yabasic's native `libffi` interface (`frnfn_call`, `frnfn_call$`, and `frnbf_*`).
### 6.1 Importing `neonet.yab` and running the demo
Because `/usr/lib/neonet.yab` is symlinked to `/home/user/Projects/neonet.yab`, any Yabasic program can import both `neoui` and `neonet`:
```yabasic
import neoui
import neonet
```
- **From the file manager (`xfiles`)**: navigate to `/home/user/Projects/`, highlight `neonet_demo.yab`, and press **Center `OK` (`Return`)**.
- **From a terminal or SSH**:
```bash
DISPLAY=:0 yabasic ~/Projects/neonet_demo.yab
```
### 6.2 Module constants (`neonet.*`)
| Yabasic constant | Value | Description |
| :--- | :--- | :--- |
| `neonet.PROTO_TCP` | `1` | Raw TCP socket via `libcurl` (`CURLOPT_CONNECT_ONLY`) |
| `neonet.PROTO_TLS` | `2` | TLS-encrypted socket via `libcurl` (`CURLOPT_CONNECT_ONLY` with ALPN disabled for raw TLS protocols) |
| `neonet.CURLE_AGAIN` | `81` | Non-blocking socket would block |
### 6.3 Exported Yabasic functions in `neonet.yab`
#### 1. Lifecycle, version, and configuration
- `neonet_init()`: initializes `libcurl` (`curl_global_init`) and resets the socket table; returns `1` on success (`0` on error). Automatically called on first use if omitted.
- `neonet_cleanup()`: closes all active sockets, clears queued custom headers, and calls `curl_global_cleanup()`.
- `neonet_version$()`: returns the `libcurl` and TLS/compression runtime version string (e.g. `"libcurl/8.23.0 OpenSSL/3.5.9 ..."`).
- `neonet_strerror$(curl_code)`: returns the human-readable error message for `curl_code`.
- `neonet_set_timeout(timeout_ms)`: sets the overall transfer timeout in milliseconds (default `15000`).
- `neonet_set_connect_timeout(connect_timeout_ms)`: sets the connection timeout in milliseconds (default `8000`).
- `neonet_set_user_agent(ua$)`: sets the default `User-Agent` header (default `"Bananarchy-NeoNet/1.0 (libcurl)"`).
- `neonet_set_max_redirects(max_redirs)`: sets the maximum number of redirects to follow (default `10`).
- `neonet_set_insecure(insecure)`: when `1`, disables TLS peer and hostname certificate checks (`CURLOPT_SSL_VERIFYPEER = 0`, `CURLOPT_SSL_VERIFYHOST = 0`); when `0` (default), enforces strict verification.
- `neonet_set_proxy(proxy_url$)`: sets an HTTP or SOCKS proxy URL (e.g. `"socks5h://127.0.0.1:9050"`, or `""` to disable).
- `neonet_set_basic_auth(user_pwd$)`: sets HTTP Basic authentication credentials (`"user:password"`, or `""` to disable).
#### 2. Custom request headers and URL encoding
- `neonet_clear_headers()`: clears all persistent custom HTTP headers added via `neonet_add_header()`.
- `neonet_add_header(header_line$)`: appends a persistent custom header (e.g. `"Authorization: Bearer my_token"` or `"X-Api-Key: 12345"`) sent with subsequent HTTP/HTTPS requests.
- `neonet_url_encode$(text$)`: percent-encodes `text$` via `curl_easy_escape`.
- `neonet_url_decode$(text$)`: decodes percent-encoded `text$` via `curl_easy_unescape`.
#### 3. HTTP and HTTPS request functions
*(Inline `headers$` arguments accept `""` for none, or multiple headers separated by `|` or `\n`, e.g. `"Accept: application/json|X-Client: Bananarchy"`, which are merged with any persistent headers from `neonet_add_header()`.)*
- `neonet_get$(url$)`: performs an HTTP/HTTPS `GET` request and returns the response body string.
- `neonet_get_ex$(url$, headers$)`: performs an HTTP/HTTPS `GET` request with inline custom headers and returns the response body string.
- `neonet_post$(url$, body$, content_type$, headers$)`: performs an HTTP/HTTPS `POST` request with `body$`, optional `content_type$` (e.g. `"application/json"`), and optional `headers$`, returning the response body string.
- `neonet_put$(url$, body$, content_type$, headers$)`: performs an HTTP/HTTPS `PUT` request and returns the response body string.
- `neonet_patch$(url$, body$, content_type$, headers$)`: performs an HTTP/HTTPS `PATCH` request and returns the response body string.
- `neonet_delete$(url$, headers$)`: performs an HTTP/HTTPS `DELETE` request and returns the response body string.
- `neonet_head(url$, headers$)`: performs an HTTP/HTTPS `HEAD` request (`CURLOPT_NOBODY = 1`) and returns the HTTP status code (`200`, `404`, etc.), populating `neonet_response_headers$()`.
- `neonet_request$(method$, url$, body$, headers$)`: general-purpose HTTP/HTTPS request for any verb (`"GET"`, `"POST"`, `"PUT"`, `"PATCH"`, `"DELETE"`, `"HEAD"`, `"OPTIONS"`), request body, and custom headers.
- `neonet_download(url$, dest_path$, headers$)`: downloads `url$` directly to `dest_path$` on disk; returns `1` on HTTP `2xx`/`3xx` success or `0` on error.
#### 4. HTTP response metadata and header inspection
- `neonet_status()`: returns the HTTP status code from the last transfer (e.g. `200`, `201`, `404`, `500`, or `0` on transport failure).
- `neonet_last_code()`: returns the `CURLcode` from the last operation (`0` = `CURLE_OK`).
- `neonet_error$()`: returns `""` on success, or the human-readable error string on failure.
- `neonet_body$()`: returns the last response body string.
- `neonet_body_len()`: returns the byte length of the last response body.
- `neonet_response_headers$()`: returns the raw HTTP response header block from the last transfer.
- `neonet_header$(name$)`: performs a case-insensitive lookup of a response header from the last transfer (e.g. `neonet_header$("content-type")`, `neonet_header$("server")`, `neonet_header$("date")`).
- `neonet_content_type$()`: returns `CURLINFO_CONTENT_TYPE` from `libcurl`.
- `neonet_effective_url$()`: returns the final effective URL after redirects (`CURLINFO_EFFECTIVE_URL`).
- `neonet_primary_ip$()`: returns the remote server IP address (`CURLINFO_PRIMARY_IP`).
#### 5. TCP, TLS, and UDP socket data exchange
- **Session-based socket functions**:
- `neonet_connect(proto, host$, port)`: opens a socket with protocol `neonet.PROTO_TCP`, `neonet.PROTO_TLS`, or `neonet.PROTO_UDP` to `host$:port`; returns a socket handle `sock_id >= 0` on success or `-1` on error.
- `neonet_tcp_connect(host$, port)`: shorthand for `neonet_connect(neonet.PROTO_TCP, host$, port)`.
- `neonet_tls_connect(host$, port)`: shorthand for `neonet_connect(neonet.PROTO_TLS, host$, port)`.
- `neonet_udp_open(host$, port)`: shorthand for `neonet_connect(neonet.PROTO_UDP, host$, port)`.
- `neonet_send(sock_id, data$)`: sends string `data$` over `sock_id`; returns the number of bytes sent (`>= 0`) or `-1` on error.
- `neonet_send_bytes(sock_id, frn_buf$, byte_len)`: sends `byte_len` raw bytes from a Yabasic foreign buffer (`frnbf_alloc$`) over `sock_id`; returns bytes sent or `-1` on error.
- `neonet_recv$(sock_id, max_bytes, timeout_ms)`: waits up to `timeout_ms` and reads up to `max_bytes` bytes as a string (`neonet_last_len()` returns the byte count).
- `neonet_recv_all$(sock_id, max_bytes, timeout_ms)`: reads chunks from a TCP/TLS stream until EOF, `max_bytes`, or idle timeout, and returns the combined string.
- `neonet_recv_bytes(sock_id, frn_buf$, max_bytes, timeout_ms)`: waits up to `timeout_ms` and reads up to `max_bytes` raw bytes into foreign buffer `frn_buf$`, returning the number of bytes read (`> 0`), `0` on EOF/timeout, or `-1` on error.
- `neonet_last_len()`: returns the byte count transferred by the most recent socket or HTTP operation.
- `neonet_close(sock_id)`: closes socket `sock_id` and releases its slot.
- **One-shot socket exchange and DNS helpers**:
- `neonet_tcp_exchange$(host$, port, payload$, timeout_ms)`: connects via TCP, sends `payload$`, reads the response, closes the socket, and returns the response string.
- `neonet_tls_exchange$(host$, port, payload$, timeout_ms)`: connects via TLS, sends `payload$`, reads the response, closes the socket, and returns the response string.
- `neonet_udp_exchange$(host$, port, payload$, timeout_ms)`: sends a UDP datagram `payload$` to `host$:port`, waits up to `timeout_ms` for a reply datagram, closes the socket, and returns the reply string.
- `neonet_system_dns$()`: returns the primary `nameserver` IP address from `/etc/resolv.conf` (fallback `"1.1.1.1"`).
- `neonet_udp_dns_a$(dns_server$, domain$, timeout_ms)`: sends a binary RFC 1035 UDP DNS A-record query to `dns_server$:53` (or the system DNS if `dns_server$ = ""`) and returns the resolved IPv4 address string.