summaryrefslogtreecommitdiffstats
path: root/st.c
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-02-06 02:14:51 +0100
committersalmonik <raisersoft@proton.me>2026-02-06 02:14:51 +0100
commit931e5010d51d1640c61034ada767715a544fa40b (patch)
tree46bd0b5c046a4aaf14c7a571425a745d2d12be2b /st.c
parentscrollback (diff)
downloadst-931e5010d51d1640c61034ada767715a544fa40b.tar.gz
st-931e5010d51d1640c61034ada767715a544fa40b.zip
apply scrollback patch and urlclick patch
Diffstat (limited to '')
-rw-r--r--st.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/st.c b/st.c
index 17fc9fb..170a8a8 100644
--- a/st.c
+++ b/st.c
@@ -652,6 +652,98 @@ getsel(void)
652 return str; 652 return str;
653} 653}
654 654
655char *
656strstrany(char* s, char** strs) {
657 char *match;
658 for (int i = 0; strs[i]; i++) {
659 if ((match = strstr(s, strs[i]))) {
660 return match;
661 }
662 }
663 return NULL;
664}
665
666void
667highlighturls(void)
668{
669 char *match;
670 char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */
671 for (int i = 0; i < term.row; i++) {
672 Line line = TLINE(i);
673 int url_start = -1;
674 for (int j = 0; j < term.col; j++) {
675 if (line[j].u < 127) {
676 linestr[j] = line[j].u;
677 }
678 linestr[term.col] = '\0';
679 }
680 while ((match = strstrany(linestr + url_start + 1, urlprefixes))) {
681 url_start = match - linestr;
682 for (int c = url_start; c < term.col && strchr(urlchars, linestr[c]); c++) {
683 line[c].mode |= ATTR_URL;
684 tsetdirt(i, c);
685 }
686 }
687 }
688 free(linestr);
689}
690
691void
692unhighlighturls(void)
693{
694 for (int i = 0; i < term.row; i++) {
695 Line line = TLINE(i);
696 for (int j = 0; j < term.col; j++) {
697 Glyph* g = &line[j];
698 if (g->mode & ATTR_URL) {
699 g->mode &= ~ATTR_URL;
700 tsetdirt(i, j);
701 }
702 }
703 }
704 return;
705}
706
707void
708followurl(int x, int y) {
709 char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */
710 char *match;
711 Line line = TLINE(x);
712 for (int i = 0; i < term.col; i++) {
713 if (line[i].u < 127) {
714 linestr[i] = line[i].u;
715 }
716 linestr[term.col] = '\0';
717 }
718 int url_start = -1;
719 while ((match = strstrany(linestr + url_start + 1, urlprefixes))) {
720 url_start = match - linestr;
721 int url_end = url_start;
722 for (int c = url_start; c < term.col && strchr(urlchars, linestr[c]); c++) {
723 url_end++;
724 }
725 if (url_start <= y && y < url_end) {
726 linestr[url_end] = '\0';
727 break;
728 }
729 }
730 if (url_start == -1) {
731 free(linestr);
732 return;
733 }
734
735 pid_t chpid;
736 if ((chpid = fork()) == 0) {
737 if (fork() == 0)
738 execlp(urlhandler, urlhandler, linestr + url_start, NULL);
739 exit(1);
740 }
741 if (chpid > 0)
742 waitpid(chpid, NULL, 0);
743 free(linestr);
744 unhighlighturls();
745}
746
655void 747void
656selclear(void) 748selclear(void)
657{ 749{