diff options
| author | salmonik <raisersoft@proton.me> | 2026-02-06 02:14:51 +0100 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-02-06 02:14:51 +0100 |
| commit | 931e5010d51d1640c61034ada767715a544fa40b (patch) | |
| tree | 46bd0b5c046a4aaf14c7a571425a745d2d12be2b /st.c | |
| parent | scrollback (diff) | |
| download | st-931e5010d51d1640c61034ada767715a544fa40b.tar.gz st-931e5010d51d1640c61034ada767715a544fa40b.zip | |
apply scrollback patch and urlclick patch
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 92 |
1 files changed, 92 insertions, 0 deletions
| @@ -652,6 +652,98 @@ getsel(void) | |||
| 652 | return str; | 652 | return str; |
| 653 | } | 653 | } |
| 654 | 654 | ||
| 655 | char * | ||
| 656 | strstrany(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 | |||
| 666 | void | ||
| 667 | highlighturls(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 | |||
| 691 | void | ||
| 692 | unhighlighturls(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 | |||
| 707 | void | ||
| 708 | followurl(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 | |||
| 655 | void | 747 | void |
| 656 | selclear(void) | 748 | selclear(void) |
| 657 | { | 749 | { |
