node.js - npm在emacs eshell下不能正确显示提示

标签 node.js emacs npm

这个问题Node.js prompt '>' can not show in eshell解决 Node repl 的问题,但是当您从 npm 调用 Node 时,该解决方案不起作用。

举个例子如果我做

$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
^[[1G^[[0Jname: (nodo1) ^[[15G

或者如果你有一个带有“scripts”的package.json:{“start”:“node”

$ npm start
npm WARN package.json nodo1@0.0.1 No README.md file found!
> node

^[[1G^[[0J> ^[[3G

我知道可以使用“start”解决这个问题:“env NODE_NO_READLINE=1 node”,但是到处写这个不是一个找到的解决方案。也许该包的其他用户不使用 emacs,需要以其他方式设置环境变量。

我尝试使用 npm 的别名设置 NODE_NO_READLINE=1 但结果相同

alias npm='env NODE_NO_READLINE=1 npm'

最佳答案

这是过滤许多 shell 前端用来为文本着色的特殊字符的 comint 模式。如果您曾经通过 Emacs 与 shell 程序交互,您可能熟悉诸如“使用哑终端或 Emacs 终端”之类的消息。有些可以检测到使用了 Emacs 或哑终端,并且不会发送那些无法解释的字符,但 Node 不会这样做。无论如何,你可以使用这样的东西:

(add-to-list
         'comint-preoutput-filter-functions
         (lambda (output)
           (replace-regexp-in-string "\\[[0-9]+[GK]" "" output)))

在你的 .emacs 中的某个地方。

Stackoverflow 不会正确复制控制字符,正则表达式中的第一个字符(在引号之后和斜杠之前)是 ^[ 字符。您可以通过执行 C-q 0 3 3 在 Emacs 中输入它,您接下来键入的任何内容都会导致控制字符插入当前缓冲区。

关于node.js - npm在emacs eshell下不能正确显示提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13185729/

相关文章:

emacs - 删除段落中换行符的规范命令是什么?

node.js - 在 Node 中导入扩展模块

windows - 如何在 Windows 上的 Node.js 中运行 hello.js 文件?

node.js - Jenkins 构建失败 - 错误 : not found: make

emacs - Emacs 24.4.1 中的下标未正确显示

php - 如何在 emacs 中添加 php 模式 Hook

Laravel Mix npm run 开发报错

node.js - 如何升级npm版本到最新? Ubuntu显示安装成功但不升级版本

ruby-on-rails - Rails、Ember、Redis、nginx 和 docker

javascript - socket.io聊天示例代码中fn()的含义