9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] patch ssh.c extract window resolution
@ 2021-02-02 11:39 Steve Simon
  2021-02-02 18:24 ` kvik
  0 siblings, 1 reply; 5+ messages in thread
From: Steve Simon @ 2021-02-02 11:39 UTC (permalink / raw)
  To: 9front

changes to ssh.c to extract the current window resolution,
LINES and COLS still have precidence.

I use this as I ssh to osx without running vt(1) - I want the rio
line editing experience and have no need of cursor addressing.

I am not sure I like pulling draw.h into ssh to do this,
but I like a pipe to an external program even less.

Does not track window changes (that feels a complexity too far).

-Steve

yesterday -d ssh.c
diff /n/dump/2021/0202/sys/src/cmd/ssh.c /sys/src/cmd/ssh.c
6a7
> #include <draw.h>
307c308
< 		sysfatal("write: %r");
---
> 		sysfatal("sendpkt write fmt=%s #=%d: %r", fmt, n);
1165a1167,1188
> 
> static Point
> fontsize(void)
> {
> 	Font *f;
> 	Point sz;
> 	char *fontname;
> 
> 	if((fontname = getenv("font")) == nil)
> 		return Pt(8, 12);
> 
> 	if((f = openfont(nil, fontname)) == nil){
> 		fprint(2, "%s: %s cannot open - %r\n", argv0, fontname);
> 		free(fontname);
> 		return Pt(8, 12);
> 	}
> 	sz = stringsize(f, "0");
> 	freefont(f);
> 	free(fontname);
> 	return sz;
> }
> 
1166a1190,1233
> screensize(void)
> {
> 	int n, wfd;
> 	Point sz;
> 	char *a[6], buf[64];
> 
> 	if((wfd = open("/dev/wctl", OREAD)) < 0){
> 		return;
> 	}
> 
> 	/* wait for event, but don't care what it says */
> 	if((n = read(wfd, buf, sizeof buf)) < 0){
> 		fprint(2, "%s: /dev/wctl read failed - %r\n", argv0);
> 		close(wfd);
> 		return;
> 	}
> 	close(wfd);
> 
> 	buf[n-1] = 0;
> 	if((n = tokenize(buf, a, nelem(a))) < 4){
> 		fprint(2, "%s: /dev/wctl too few tokens (%d<4)\n", argv0, n);
> 		return;
> 	}
> 
> 	sz = fontsize();
> 
> 	/* This code lifted from mc.c, and is correct for rio(1) windows.
> 	 *
> 	 * 4 pixels left edge
> 	 * 1 pixels gap
> 	 * 12 pixels scrollbar
> 	 * 4 pixels gap
> 	 * text
> 	 * 4 pixels right edge
> 	 *
> 	 * 4 pixels top and bottom edges
> 	 */
> 	tty.ypixels = atoi(a[3]) - atoi(a[1]);
> 	tty.xpixels = atoi(a[2]) - atoi(a[0]);
> 	tty.lines = (tty.ypixels - (4+4)) / sz.y;
> 	tty.cols = (tty.xpixels - (4+1+12+4+4)) / sz.x;
> }
> 
> void
1170a1238,1239
> 	screensize();
> 
1186a1256
> 	fprint(2, "'%s' %d %d, %d %d \n", tty.term, tty.cols, tty.lines, tty.xpixels, tty.ypixels);
1410a1481
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-03  0:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 11:39 [9front] patch ssh.c extract window resolution Steve Simon
2021-02-02 18:24 ` kvik
2021-02-02 19:56   ` Steve Simon
2021-02-02 22:06     ` Lyndon Nerenberg
2021-02-02 21:09   ` ori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).