无法更改 pty/N 上的终端大小(适用于 ttyN) [英] Can't change terminal size on pty/N (works on ttyN)

查看:43
本文介绍了无法更改 pty/N 上的终端大小(适用于 ttyN)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 next 更改终端大小:
<代码>rc = ioctl(fd, TIOCSWINSZ, &ws);
当我在 linux 文本终端(通过 Alt-Ctrl-F1 切换)下运行它时,结果是我希望看到的.ioctl syscall 给出的范围内的整个我的输入和输出.
但是当我通过 SSH 连接到 localhost 并运行相同的程序时,它只能部分工作.我的意思是我不能输入比 ioctl 设置的终端大小更宽的命令,但是输出可以跨越 ioctl 给定的终端边界,并且输入可以占用更多由 ioctl 设置的行.之后也没有自动回车和换行.
当我直接运行程序时,我看到的唯一区别是它在终端/dev/ttyN 上运行,它的主编号是 5,当我通过 SSH 运行程序时,它使用/dev/pts/N 作为终端,主编号是 136.所以,据我所知,这是由于终端的不同而发生的.
我的问题:
1. 正确吗?是终端驱动的原因吗?
2. 我该如何解决?我需要通过 SSH 实现与本地 tty 终端相同的行为.

谢谢!

I use the next to change terminal size:
rc = ioctl(fd, TIOCSWINSZ, &ws);
When I run this under linux text terminal (switching by Alt-Ctrl-F1), the result is that I expect to see. The whole my input and output within ranges given by ioctl syscall.
But when I connect to localhost by SSH, and run the same program, it works only partly. I mean that I can't input command wider than terminal size set by ioctl, but the output can cross the borders of terminal given by ioctl, and input can take more rows that set by ioctl. Also there is no auto carriage return and new line after that.
The only difference that I see when I run program directly it run on the terminal /dev/ttyN, and it's major number is 5, and when I run program via SSH it use /dev/pts/N as terminal, with major number 136. So, as I understood, it happens due the difference in terminals.
My questions:
1. Is that correct? Is the reason in terminal drivers?
2. How do I fix it? I need the same behaviour via SSH like in local tty terminal.

Thanks!

推荐答案

通常 TIOCSWINSZ 被 tty master 使用(比如 xterm,Linux 控制台本身等)...) 告诉内核驱动程序终端实际有多大.在 tty slave 上运行的程序(即应用程序本身)使用 TIOCGWINSZ 来查询终端的大小.大多数 tty 驱动程序不支持以其他方式推动它;通常,您不能从应用程序调用 tty 从站上的 TIOCSWINSZ 并让主站更改其大小.

Usually TIOCSWINSZ is used by the tty master (such as xterm, the Linux console itself, etc...) to tell the kernel driver how big the terminal actually is. The program running on the tty slave (i.e. the application itself) uses TIOCGWINSZ to query the size of the terminal. Most tty drivers don't support pushing it the other way; you can't in general call TIOCSWINSZ on the tty slave from the application and get the master to change its size.

某些终端,例如 xterm 确实支持转义序列以请求它们调整大小,但这只是一个字节转义序列,而不是 ioctl() 命令.

Some terminals, such as xterm do support escape sequences to request them to resize, but this is just a byte escape sequence, and not an ioctl() command.

如果您希望应用程序强制终端的大小,那么可移植地没有办法做到这一点.不可移植的是,您可以应用一些特殊技巧,例如尝试 TIOCSWINSZ 或发送 xterm 转义序列.

If you want the application to force the size of the terminal, then portably there is no way to do this. Unportably, you can apply a few special tricks like attempting TIOCSWINSZ or sending the xterm escape sequence.

这篇关于无法更改 pty/N 上的终端大小(适用于 ttyN)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆