My build of the simple terminal from suckless.org.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

110 lignes
2.9 KiB

  1. From be408247f1c1ff8ccf7ab128b126f54d19bd4392 Mon Sep 17 00:00:00 2001
  2. From: Michael Buch <michaelbuch12@gmail.com>
  3. Date: Sat, 2 Feb 2019 14:20:52 +0000
  4. Subject: [PATCH] Port the copyurl patch to the 0.8.1 st release. Mainly fix
  5. usage of depracted selcopy
  6. ---
  7. config.def.h | 1 +
  8. st.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  9. st.h | 1 +
  10. 3 files changed, 64 insertions(+)
  11. diff --git a/config.def.h b/config.def.h
  12. index 82b1b09..cbe923e 100644
  13. --- a/config.def.h
  14. +++ b/config.def.h
  15. @@ -178,6 +178,7 @@ static Shortcut shortcuts[] = {
  16. { TERMMOD, XK_Y, selpaste, {.i = 0} },
  17. { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
  18. { TERMMOD, XK_I, iso14755, {.i = 0} },
  19. + { MODKEY, XK_l, copyurl, {.i = 0} },
  20. };
  21. /*
  22. diff --git a/st.c b/st.c
  23. index 46c954b..476eb31 100644
  24. --- a/st.c
  25. +++ b/st.c
  26. @@ -2616,3 +2616,65 @@ redraw(void)
  27. tfulldirt();
  28. draw();
  29. }
  30. +
  31. +/* select and copy the previous url on screen (do nothing if there's no url).
  32. + * known bug: doesn't handle urls that span multiple lines (wontfix)
  33. + * known bug: only finds first url on line (mightfix)
  34. + */
  35. +void
  36. +copyurl(const Arg *arg) {
  37. + /* () and [] can appear in urls, but excluding them here will reduce false
  38. + * positives when figuring out where a given url ends.
  39. + */
  40. + static char URLCHARS[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  41. + "abcdefghijklmnopqrstuvwxyz"
  42. + "0123456789-._~:/?#@!$&'*+,;=%";
  43. +
  44. + int i, row, startrow;
  45. + char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */
  46. + char *c, *match = NULL;
  47. +
  48. + row = (sel.ob.x >= 0 && sel.nb.y > 0) ? sel.nb.y-1 : term.bot;
  49. + LIMIT(row, term.top, term.bot);
  50. + startrow = row;
  51. +
  52. + /* find the start of the last url before selection */
  53. + do {
  54. + for (i = 0; i < term.col; ++i) {
  55. + if (term.line[row][i].u > 127) /* assume ascii */
  56. + continue;
  57. + linestr[i] = term.line[row][i].u;
  58. + }
  59. + linestr[term.col] = '\0';
  60. + if ((match = strstr(linestr, "http://"))
  61. + || (match = strstr(linestr, "https://")))
  62. + break;
  63. + if (--row < term.top)
  64. + row = term.bot;
  65. + } while (row != startrow);
  66. +
  67. + if (match) {
  68. + /* must happen before trim */
  69. + selclear();
  70. + sel.ob.x = strlen(linestr) - strlen(match);
  71. +
  72. + /* trim the rest of the line from the url match */
  73. + for (c = match; *c != '\0'; ++c)
  74. + if (!strchr(URLCHARS, *c)) {
  75. + *c = '\0';
  76. + break;
  77. + }
  78. +
  79. + /* select and copy */
  80. + sel.mode = 1;
  81. + sel.type = SEL_REGULAR;
  82. + sel.oe.x = sel.ob.x + strlen(match)-1;
  83. + sel.ob.y = sel.oe.y = row;
  84. + selnormalize();
  85. + tsetdirt(sel.nb.y, sel.ne.y);
  86. + xsetsel(getsel());
  87. + xclipcopy();
  88. + }
  89. +
  90. + free(linestr);
  91. +}
  92. diff --git a/st.h b/st.h
  93. index dac64d8..5a58f8f 100644
  94. --- a/st.h
  95. +++ b/st.h
  96. @@ -85,6 +85,7 @@ void printscreen(const Arg *);
  97. void printsel(const Arg *);
  98. void sendbreak(const Arg *);
  99. void toggleprinter(const Arg *);
  100. +void copyurl(const Arg *);
  101. int tattrset(int);
  102. void tnew(int, int);
  103. --
  104. 2.20.1