您如何在终端中编辑现有文本(并四处移动光标)? [英] How do you edit existing text (and move the cursor around) in the terminal?

查看:17
本文介绍了您如何在终端中编辑现有文本(并四处移动光标)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经看过这个演示,它打印出一段文本(就像你在输入 some-command --help 时得到的那样),然后它又跳回了几个关键字text 并更改文本颜色,在终端中打印出来之后.

I saw this demo once that printed out a paragraph of text (like you'd get when typing some-command --help), and it then jumped back up to a couple keywords in the text and changed the text color, after it was already printed out in the terminal.

这对我来说似乎很疯狂.他们是怎么做到的?

That seems crazy to me. How did they do that?

开始思考,我猜 stdoutstdin 在技术上是一个IO 流",所以也许这是一个持续性的变量,用于跟踪一个光标?我记得在构建语言解析器时做过类似的事情.

Starting to think about it, I guess stdout and stdin are technically an "IO stream", so maybe that's a persistent variable that keeps track of the position of a cursor? I remember doing something like that when building a language parser.

目标是这样的:假设您在控制台中键入以下内容,它会输出一个空白数组,因为在 Node.js 中,它都是异步的,我们不想每次都在控制台中编写异步函数:

The goal would be this: say you type the following into the console, and it outputs a blank array because in Node.js, it's all async and we don't want to write the async function everytime in the console:

$ node app.js
> App.User.all()
=> []

然后当异步回调执行时,你回去编辑=>;[] 包含结果:

Then when the async callback executes, you go back and edit the => [] to include the result:

$ node app.js
> App.User.all()
=> [#<User id:1>, #<User id:2>...]

至少知道如何实现会很棒,即使还有很多其他问题需要解决(与这个问题无关.我知道你可以定义一个全局回调并执行类似 App.User.all(_c)).

That would be awesome to at least know how to implement, even if there are a lot of other issues to work through (unrelated to this question. And I know you can define a global callback and do something like App.User.all(_c)).

终端输出已打印后如何编辑?

How do you edit the terminal output after it's already been printed?

推荐答案

终于找到了demo":

Finally found that "demo":

定位光标:33[;H33[;f>(将光标放在 L 行和 C 列)

Position the Cursor: 33[<L>;<C>H or 33[<L>;<C>f (puts the cursor at line L and column C)

这篇关于您如何在终端中编辑现有文本(并四处移动光标)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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