将向上/向下箭头作为 Unix 程序的输入 [英] Taking up/down arrow as input to a program in Unix

查看:33
本文介绍了将向上/向下箭头作为 Unix 程序的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现我自己的外壳.但是为了支持命令历史记录,我需要像在标准 shell 中一样使用监视向上/向下箭头键.请告诉我如何将箭头键作为输入处理,或者这些键是否会产生信号?请详细说明.

I am implementing my own shell. But to supprt for command history, I need to use monitor up/down arrow key as in standard shells. Please tell me how to handle arrow keys as input or does these keys generate signals? Please elaborate.

推荐答案

箭头和其他特殊键向您发送特殊字符串,这些字符串取决于正在使用或模拟的终端.为了最简单地处理这个问题,您可以使用一个库,例如 术语上限.更简单的是,考虑到您声明的目的(命令历史支持),将使用 readline,这基本上是为您完成的(并让用户自定义他们在链接到同一库的许多应用程序中首选工作模式的各个方面).

Arrows and other special keys send you special strings that depend on the terminal being used or emulated. To deal with this most simply, you could use a library such as termcap. Even simpler, given your stated purpose (command history support), would be to use readline, which basically does it for you (and lets the user customize aspects of their preferred mode of working across the many applications that link to the same library).

这篇关于将向上/向下箭头作为 Unix 程序的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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