Ç - 混淆生熟与终端模式? [英] C - Confusion about raw vs. cooked terminal modes?

查看:118
本文介绍了Ç - 混淆生熟与终端模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个聊天客户端成功通信的服务器。我应该修改的行为,这样的提示符下向下移动时接收到另一个聊天消息(即邮件打印上面的提示通过打印 \\ b 擦除提示,打印信息,然后重新打印提示)。

I currently have a chat client that communicates successfully with a server. I am supposed to modify the behavior so that the prompt moves down when another chat message is received (i.e. the messages are printed "above" the prompt by printing \b to erase the prompt, printing the message, and then re-printing the prompt).

我们分别获得了测试客户端测试服务器测试这个功能,目前当用户有一个提示,但没有键入的,他们可以从其他用户接收消息。当他们开始打字,缓冲区中,直到他们键入他们的整个消息,按回车不冲水。

We were given a test client and test server for testing this functionality, and currently when the user has a prompt but nothing typed in, they can receive messages from other users. When they start typing, the buffer doesn't flush until they type their whole message and hit ENTER.

我应该复制这种行为,但的我什么原始模式其实是非常困惑。

I am supposed to replicate this behavior, but I am very confused about what raw mode actually is.

谁能告诉我如何通过原始模式,或控制输入/输出,为什么我上述使用原始模式发生?测试程序的行为

Can anyone tell me how to control input/output via raw mode, or why the behavior of the test programs I described above occurs from using raw mode?

推荐答案

默认情况下,Unix风格的TTY(即控制台)驱动程序将输入熟模式。在这种模式下,它提供了一定量的命令行编辑的。用户可以输入一个线路输入,可能是删除和重新键入它的一些(但并不总是有效),并计划将不会看到它,直到用户点击进入。

By default, Unix-style tty (i.e. console) drivers will take input in "cooked mode". In this mode, it provides a certain amount of command-line editing. The user can type in a line of input, possibly deleting and retyping some of it (but that doesn't always work) and the program won't see it until the user hits enter.

此可能让人回想起通过串行线与计算机连接的硬件终端的天;如果该终端处理的一些低级编辑的,计算机不必。这也给平凡的C程序的一些基本的输入编辑是免费的。

This probably harkens back to the days of hardware terminals connected to the computer via a serial line; if the terminal handles some of the low-level editing, the computer doesn't have to. It also gives trivial C programs some basic input editing for free.

在此相反,原始模式设置了TTY驱动程序,因为它是类型化的每个字符传递给该程序。程序(在Unixish操作系统)都熟模式在默认情况下启动,需要启用原始模式。

In contrast, raw mode sets up the TTY driver to pass every character to the program as it is typed. Programs (on Unixish operating systems) are started in cooked mode by default and need to enable raw mode.

如何做到这一点使用的操作系统之间差异很大,虽然POSIX标准了这个东西,这些天。在Linux上,你可以阅读的termios和tty_ioctl手册页的文档。基本上,你会得到一个数据结构包含tty设置,修改您所关心的部分(具体地说,使原始模式),然后传回。

How to do this used to vary wildly between operating systems, although POSIX has standardized this stuff these days. On Linux, you can read the "termios" and "tty_ioctl" man pages for the documentation. Basically, you get a data structure containing the tty settings, modify the parts you care about (specifically, enabling raw mode) and then pass it back.

另一种可能是只使用ncurses库。它抽象了所有的东西给你。

Another possibility is to just use the ncurses library. It abstracts away all of that stuff for you.

这篇关于Ç - 混淆生熟与终端模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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