home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 241,911 of 243,242   
   Michael Sanders to All   
   click_link()   
   12 Nov 25 14:23:24   
   
   From: porkchop@invalid.foo   
      
   #include    
   #include    
   #include    
      
   /*   
    * click_link() - Michael Sanders 2025   
    *   
    * returns a pointer to a clickable character array if the user's   
    * terminal supports it & heads up: you must free() the pointer   
    *   
    * enjoy!   
    *   
    */   
      
   char *click_link(const char *txt, const char *url) {   
       const char *GREEN         = "\033[92m";   
       const char *RESET         = "\033[0m";   
       const char *fmt_url = "\033]8;;%s\033\\\033[92m%s\033[0m\033]8;;\033\\";   
       const char *fmt_fallback  = "\033[92m%s\033[0m (%s)";   
      
       const char *term_program = getenv("TERM_PROGRAM");   
       const char *vte_version  = getenv("VTE_VERSION");   
       const char *term         = getenv("TERM");   
       const char *wt_session   = getenv("WT_SESSION");   
      
       int supported =   
           (term_program && strcmp(term_program, "iTerm.app")  == 0) ||   
           vte_version || (term && strcmp(term, "xterm-kitty") == 0) ||   
           wt_session;   
      
       /* pick format string & estimate required length */   
       size_t len = snprintf(NULL, 0, supported ?   
                    fmt_url : fmt_fallback, url, txt);   
      
       char *out  = malloc(len + 1); if (!out) return NULL;   
      
       snprintf(out, len + 1, supported ? fmt_url : fmt_fallback, url, txt);   
       return out;   
   }   
      
   int main(void) {   
       char *url = click_link("click here", "https://gitlab.com/");   
       if (url) printf("For updates %s\n", url);   
       free(url);   
       return 0;   
   }   
      
   --   
   :wq   
   Mike Sanders   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca