* [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
* Re: [9front] patch ssh.c extract window resolution
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 21:09 ` ori
0 siblings, 2 replies; 5+ messages in thread
From: kvik @ 2021-02-02 18:24 UTC (permalink / raw)
To: 9front
> sz = stringsize(f, "0");
This is going to be quite wrong for variable width fonts.
It seems that we could avoid this code (also in mc, etc.) if rio
provided these metrics in a per-window file.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [9front] patch ssh.c extract window resolution
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
1 sibling, 1 reply; 5+ messages in thread
From: Steve Simon @ 2021-02-02 19:56 UTC (permalink / raw)
To: 9front
hi all
i realise i didn't say this patch is of use.
when i ssh onto unix or osx i don't use vt(1).
i really like using rio to generate commands using cut and paste, send etc. i like my unix to look and feel like plan9
this means the environment variables ssh expects from vt dont exist. as a result some unix apps like ls and man don’t format their output correctly. this patch allows them to work as expected
re: variable width fonts
as you say, window width has no meaning under these circumstances, however if the app uses tabs you can still get sane formatting.
-Steve
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [9front] patch ssh.c extract window resolution
2021-02-02 18:24 ` kvik
2021-02-02 19:56 ` Steve Simon
@ 2021-02-02 21:09 ` ori
1 sibling, 0 replies; 5+ messages in thread
From: ori @ 2021-02-02 21:09 UTC (permalink / raw)
To: 9front
Quoth kvik@a-b.xyz:
>
> It seems that we could avoid this code (also in mc, etc.) if rio
> provided these metrics in a per-window file.
>
I don't think that rio should be providing metrics that make no
sense if you use a variable width font. Not sure how I feel
about making ssh provide them either, though.
Since ssh uses getenv and interrupts, perhaps this can go into
a program outside of ssh that runs in the same env?
setsize ssh yourhost
where sizehack() is essentially:
void
threadmain(int arc, char **argv)
{
pid = spawn(argv+1, argc-1);
while(1){
recv(mc->resizec, nil);
sz = windowsize();
setenv(...);
write("/proc/%d/note", pid, "interrupt");
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [9front] patch ssh.c extract window resolution
2021-02-02 19:56 ` Steve Simon
@ 2021-02-02 22:06 ` Lyndon Nerenberg
0 siblings, 0 replies; 5+ messages in thread
From: Lyndon Nerenberg @ 2021-02-02 22:06 UTC (permalink / raw)
To: 9front, Steve Simon
[-- Attachment #1: Type: text/plain, Size: 650 bytes --]
> this means the environment variables ssh expects from vt dont exist. as =
a re=3D
> sult some unix apps like ls and man don=3DE2=3D80=3D99t format their out=
put correc=3D
> tly. this patch allows them to work as expected
In my UNIX .env (only sourced for "interactive" shells), if $TERM
is unset I set TERM=3Ddumb, PAGER=3D'col -b', and EDITOR=3Ded. That seems
to get around most of the terminal-related issues. And if you need
more than 80 columns of output, setting cols via stty(1) will take
care of that for programs that pay attention.
I also have a tiny UNIX program that prints column rulers, to help
with this sort of thing.
--lyndon
[-- Attachment #2.1: Type: text/plain, Size: 380 bytes --]
from postmaster@1ess:
The following attachment had content that we can't
prove to be harmless. To avoid possible automatic
execution, we changed the content headers.
The original header was:
Content-Type: text/x-c; name="ruler.c"; charset="us-ascii"
Content-Description: ruler.c
Content-Disposition: attachment; filename="ruler.c"
Content-Transfer-Encoding: quoted-printable
[-- Attachment #2.2: ruler.c.suspect --]
[-- Type: application/octet-stream, Size: 874 bytes --]
/* ruler [cols] -- print a column-count ruler */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
int
main (int argc, char **argv)
{
int cols, rows, i, j, skip;
char *buf, *p;
cols = -1;
if (argc > 1) {
cols = atoi(argv[1]);
if (cols == 0)
exit(1);
}
if (cols == -1) {
struct winsize ws;
if (ioctl(0, TIOCGWINSZ, &ws) == -1)
exit(1);
if (ws.ws_col > 0)
cols = ws.ws_col;
}
if (cols <= 0)
cols = 80;
buf = malloc(cols + 1);
if (buf == NULL) {
fprintf(stderr, "out of memory");
exit(1);
}
rows = log10(cols);
for (i = rows; i >= 0 ; i--) {
skip = pow(10, i);
p = buf;
for (j = 1; j <= cols; j++) {
if (j % skip)
*p++ = ' ';
else
sprintf(p++, "%d", (j / skip) % 10);
}
buf[cols] = '\0';
printf("%s\n", buf);
}
exit(0);
}
^ 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).