9front - general discussion about 9front
 help / color / mirror / Atom feed
From: "Steve Simon" <steve@quintile.net>
To: 9front@9front.org
Subject: [9front] patch ssh.c extract window resolution
Date: Tue, 2 Feb 2021 11:39:12 +0000	[thread overview]
Message-ID: <b4fb45bc407b184b10c920161f7d6946@quintile.net> (raw)

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
> 

             reply	other threads:[~2021-02-02 20:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 11:39 Steve Simon [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b4fb45bc407b184b10c920161f7d6946@quintile.net \
    --to=steve@quintile.net \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).