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