Skip to content
pi-c Artifact [1037c8f278]
Login

Artifact [1037c8f278]

Artifact 1037c8f278d0e5ad92a7e8553cb55f752127ca2b370310e871345580f5d11754:


/* /rc ssh and pic rc --ssh (remote.c): how to reach this conversation from
 * a phone over ssh: the ssh command and checks with their fixes; and the QR
 * code /rc and pic rc draw of the phone page's address. */
#ifndef PIC_TUI_REMOTE_H
#define PIC_TUI_REMOTE_H

typedef struct {
    char user[64];
    char host[256];      /* the Tailscale name when Tailscale is up, else the local host name */
    char ip[64];         /* this machine's first Tailscale address, or "" */
    char url[384];       /* ssh://user@ip when there is one (a phone off Tailscale DNS), else ssh://user@host */
    char then[4096];     /* what to run once logged in (cd ... && pic attach -i -c) */
    char command[8192];  /* ssh user@host -t '...': the whole thing, for any ssh client */
    int tailscale;       /* 1: reachable through Tailscale */
    int ssh_on;          /* 1: something listens on port 22 */
} tui_remote;

/* Fills R for the conversation SESSION (NULL or "": the latest, -c) of
 * WORKSPACE, run there with the pic at SELF. Looks the host up (tailscale
 * status, scutil, gethostname) and tries port 22. Dev builds take the
 * lookups from PIC_TEST_RC ("TAILSCALE_NAME|LOCAL_NAME|SSH[|TAILSCALE_IP]":
 * - for no Tailscale, SSH 1 or 0). */
void tui_remote_info(tui_remote *r, const char *self, const char *workspace, const char *session);

/* TEXT as a QR code, two rows of modules per line in half blocks, with a
 * quiet zone of 4. LIGHT_BLOCKS: light modules are the blocks, to be drawn
 * light on dark (the caller colours it); 0: dark modules are the blocks,
 * for a light background. NULL on failure; malloc'd, lines ending in '\n';
 * *rows its line count. */
char *tui_remote_qr(const char *text, int light_blocks, int *rows);

/* The ssh page: the address, what to run, the command, the checks; lines
 * ending in '\n'. */
char *tui_remote_page(const tui_remote *r);

/* A line of a page that is a QR code row starts with this, for the caller
 * to colour white on black. */
#define TUI_REMOTE_QR '\x02'

#endif