On 4 April 2011 16:18, Bryan Bennett bbenn...@gmail.com wrote:
While I understand wanting applications to adhere to the Unix
Philosophy, it seems to me that inputting and outputting text
is what a terminal essentially does and copying pasting is
just a small extension of that role. I'd like to see a sane
way of copying pasting with the keyboard, rather than
relying on the mouse for that.
How about something similar to Vimperator's edit-textbox idea?
You hit a key-combo, and the terminal writes what is visible on the
screen to a temporary file, then fires up $EDITOR on said file. You
delete what you don't want, then the rest is inserted into X's
selection.
I've knocked together a quick patch, attached, along with a whitespace
patch that removes trailing whitespace. At the moment, the key-combo
is middle mouse.
The patch is a bit of a bodge too - it doesn't support unicode
characters properly and for the system() call to work, SIGCHLD is reset
temporarily, which could be a problem if the shell dies mid-selection
edit. I'm open to suggestions. Avoid system() entirely?
Also, I wasn't sure how to open $EDITOR in st's terminal itself, if
people are interested I'll give it a go, but for the moment it just
fires up another st to host the editor.
Cheers,
Rob.
diff -r fe61798f04a5 st.c
--- a/st.c Sun Apr 03 21:40:33 2011 +0200
+++ b/st.c Tue Apr 05 13:04:11 2011 +0100
@@ -45,7 +45,7 @@
#define MIN(a, b) ((a) (b) ? (a) : (b))
#define MAX(a, b) ((a) (b) ? (b) : (a))
#define LEN(a) (sizeof(a) / sizeof(a[0]))
-#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
+#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
#define BETWEEN(x, a, b) ((a) = (x) (x) = (b))
#define LIMIT(x, a, b)(x) = (x) (a) ? (a) : (x) (b) ? (b) : (x)
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
@@ -57,7 +57,7 @@
CURSOR_SAVE, CURSOR_LOAD };
enum { CURSOR_DEFAULT = 0, CURSOR_HIDE = 1, CURSOR_WRAPNEXT = 2 };
enum { GLYPH_SET=1, GLYPH_DIRTY=2 };
-enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8,
+enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8,
MODE_CRLF=16 };
enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 };
enum { SCREEN_UPDATE, SCREEN_REDRAW };
@@ -96,7 +96,7 @@
/* Internal representation of the screen */
typedef struct {
- int row; /* nb row */
+ int row; /* nb row */
int col; /* nb col */
Line* line; /* screen */
Line* alt; /* alternate screen */
@@ -125,7 +125,7 @@
int ch; /* char height */
int cw; /* char width */
char state; /* focus, redraw, visible */
-} XWindow;
+} XWindow;
typedef struct {
KeySym k;
@@ -340,7 +340,7 @@
else if((*c1(B7|B6|B5)) == (B7|B6) b == 1)
return 0;
else if((*c1(B7|B6|B5|B4)) == (B7|B6|B5)
- ((b == 1) ||
+ ((b == 1) ||
((b == 2) (*c2(B7|B6)) == B7)))
return 0;
else if((*c1(B7|B6|B5|B4|B3)) == (B7|B6|B5|B4)
@@ -362,7 +362,7 @@
return 2;
else if ((c(B7|B6|B5|B4)) == (B7|B6|B5))
return 3;
- else
+ else
return 4;
}
@@ -376,20 +376,20 @@
sel.xtarget = XA_STRING;
}
-static inline int
+static inline int
selected(int x, int y) {
if(sel.ey == y sel.by == y) {
int bx = MIN(sel.bx, sel.ex);
int ex = MAX(sel.bx, sel.ex);
return BETWEEN(x, bx, ex);
}
- return ((sel.b.y yy sel.e.y) || (y==sel.e.y x=sel.e.x))
+ return ((sel.b.y yy sel.e.y) || (y==sel.e.y x=sel.e.x))
|| (y==sel.b.y x=sel.b.x (x=sel.e.x || sel.b.y!=sel.e.y));
}
void
getbuttoninfo(XEvent *e, int *b, int *x, int *y) {
- if(b)
+ if(b)
*b = e-xbutton.button;
*x = (e-xbutton.x - BORDER)/xw.cw;
@@ -560,7 +560,7 @@
exit(EXIT_FAILURE);
}
-void
+void
sigchld(int a) {
int stat = 0;
if(waitpid(pid, stat, 0) 0)
@@ -574,7 +574,7 @@
void
ttynew(void) {
int m, s;
-
+
/* seems to work fine on linux, openbsd and freebsd */
struct winsize w = {term.row, term.col, 0, 0};
if(openpty(m, s, NULL, NULL, w) 0)
@@ -613,7 +613,7 @@
void
ttyread(void) {
static char buf[BUFSIZ];
- static int buflen = 0;
+ static int buflen = 0;
char *ptr;
char s[UTF_SIZ];
int charsize; /* size of utf8 char in bytes */
@@ -669,11 +669,11 @@
void
treset(void) {
term.c = (TCursor){{
- .mode = ATTR_NULL,
- .fg = DefaultFG,
+ .mode = ATTR_NULL,
+ .fg = DefaultFG,
.bg = DefaultBG
}, .x = 0, .y = 0, .state = CURSOR_DEFAULT};
-
+
term.top = 0, term.bot = term.row - 1;
term.mode = MODE_WRAP;
tclearregion(0, 0, term.col-1, term.row-1);
@@ -705,11 +705,11 @@
tscrolldown(int orig, int n) {
int i;
Line temp;
-
+
LIMIT(n, 0, term.bot-orig+1);
tclearregion(0, term.bot-n+1, term.col-1, term.bot);
-
+
for(i = term.bot; i = orig+n; i--) {
temp = term.line[i];
term.line[i] = term.line[i-n];
@@ -722,12 +722,12 @@
int i;
Line temp;
LIMIT(n, 0, term.bot-orig+1);
-
+
tclearregion(0, orig, term.col-1, orig+n-1);
-
- for(i = orig; i = term.bot-n; i++) {
+
+ for(i = orig; i =