输入提示始终在底部 [英] Input prompt always at the bottom

查看:70
本文介绍了输入提示始终在底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.您看,我已经创建了这个简单的聊天服务器.在客户端,由于它是聊天服务器,所以我不断要求用户输入.关键是,我的输入提示是>",如果您在下图中看到,它会与所有正在打印的消息(在这种情况下,是在客户端发送的消息后面)啮合在一起.我的问题是,我能做到吗这样提示符>"总是位于终端的底部/新行吗?

I have a problem. You see, I've created this simple chat server. On the client side, since its a chat server, I'm continuously asking the user for input. The thing is, my input prompt is ">", and if you see in the picture below, it gets meshed with all the messages being printed (in this case behind the message sent by the client) My question is, can I make it so that the prompt ">" is always at the bottom/new line of the terminal?

推荐答案

有几种选择:

  • 您可以使用 ANSI转义序列编写一个简单的版本,但这很快就会成为痛苦.
  • 您可以使用标准库中的 curses 模块,它抽象出单个终端的细节,并且比尝试仅使用转义序列要容易得多.
  • 您可以使用基于 curses 构建的更高级别的框架,例如 urwid npyscreen .
  • You can write a simple version using ANSI escape sequences yourself, but this will quickly become a pain.
  • You can use the curses module from the standard library, which abstracts away the specifics of inidividual terminals, and is less of a pain than trying to use escape sequences only.
  • You can use a higher level framework built on top of curses, like urwid or npyscreen.

我个人会选择最后一个.

I'd personally go with the last option.

这篇关于输入提示始终在底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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