Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <ctype.h>
4 #include <draw.h>
5 #include <thread.h>
6 #include <mouse.h>
7 #include <cursor.h>
8 #include <keyboard.h>
9 #include <frame.h>
10 #include <plumb.h>
11 #include <termios.h>
12 #include <sys/termios.h>
13 #ifdef __linux__
14 #include <pty.h>
15 #endif
17 #define fatal sysfatal
19 typedef struct Text Text;
20 typedef struct Readbuf Readbuf;
22 enum
23 {
24 /* these are chosen to use malloc()'s properties well */
25 HiWater = 640000, /* max size of history */
26 LoWater = 330000, /* min size of history after max'ed */
27 };
29 /* various geometric paramters */
30 enum
31 {
32 Scrollwid = 12, /* width of scroll bar */
33 Scrollgap = 4, /* gap right of scroll bar */
34 Maxtab = 4,
35 };
37 enum
38 {
39 Cut,
40 Paste,
41 Snarf,
42 Send,
43 Scroll,
44 Plumb,
45 };
48 #define SCROLLKEY Kdown
49 #define ESC 0x1B
50 #define CUT 0x18 /* ctrl-x */
51 #define COPY 0x03 /* crtl-c */
52 #define PASTE 0x16 /* crtl-v */
53 #define BACKSCROLLKEY Kup
55 #define READBUFSIZE 8192
57 struct Text
58 {
59 Frame *f; /* frame ofr terminal */
60 Mouse m;
61 uint nr; /* num of runes in term */
62 Rune *r; /* runes for term */
63 uint nraw; /* num of runes in raw buffer */
64 Rune *raw; /* raw buffer */
65 uint org; /* first rune on the screen */
66 uint q0; /* start of selection region */
67 uint q1; /* end of selection region */
68 uint qh; /* unix point */
69 int npart; /* partial runes read from console */
70 char part[UTFmax];
71 int nsnarf; /* snarf buffer */
72 Rune *snarf;
73 };
75 struct Readbuf
76 {
77 short n; /* # bytes in buf */
78 uchar data[READBUFSIZE]; /* data bytes */
79 };
81 void mouse(void);
82 void domenu2(int);
83 void loop(void);
84 void geom(void);
85 void fill(void);
86 void tcheck(void);
87 void updatesel(void);
88 void doreshape(void);
89 void rcstart(int fd[2], int, char**);
90 void runewrite(Rune*, int);
91 void consread(void);
92 void conswrite(char*, int);
93 int bswidth(Rune c);
94 void cut(void);
95 void paste(Rune*, int, int);
96 void snarfupdate(void);
97 void snarf(void);
98 void show(uint);
99 void key(Rune);
100 void setorigin(uint org, int exact);
101 uint line2q(uint);
102 uint backnl(uint, uint);
103 int cansee(uint);
104 uint backnl(uint, uint);
105 void addraw(Rune*, int);
106 void mselect(void);
107 void doubleclick(uint *q0, uint *q1);
108 int clickmatch(int cl, int cr, int dir, uint *q);
109 Rune *strrune(Rune *s, Rune c);
110 int consready(void);
111 Rectangle scrpos(Rectangle r, ulong p0, ulong p1, ulong tot);
112 void scrdraw(void);
113 void scroll(int);
114 void hostproc(void *arg);
115 void hoststart(void);
116 int getchildwd(int, char*, int);
117 void plumbstart(void);
118 void plumb(uint, uint);
119 void plumbclick(uint*, uint*);
120 int getpts(int fd[], char *slave);
122 #define runemalloc(n) malloc((n)*sizeof(Rune))
123 #define runerealloc(a, n) realloc(a, (n)*sizeof(Rune))
124 #define runemove(a, b, n) memmove(a, b, (n)*sizeof(Rune))