2012-11-01 47 views
5

此問題Node.js prompt '>' can not show in eshell解決了節點repl的問題,但是當您從npm調用節點時,該解決方案不起作用。npm在emacs下無法正確顯示提示符eshell

例如,如果我讓

$ 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 

或者,如果你有一個的package.json有 「腳本」:{ 「開始」: 「節點」}

$ npm start 
npm WARN package.json [email protected] No README.md file found! 
> node 

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

我知道這一個可以使用「start」來解決:「env NODE_NO_READLINE = 1個節點」,但是到處寫這個不是一個尋找解決方案。也許包的其他用戶不使用emacs並需要以其他方式設置env var。

我有一個別名NPM設置NODE_NO_READLINE = 1,但同樣的結果

alias npm='env NODE_NO_READLINE=1 npm' 

回答

4

這是通信情報模式過濾所述特殊字符許多殼前端使用上色文本嘗試。如果您曾通過Emacs與shell程序進行交互,則您可能熟悉「使用啞終端或Emacs終端」等消息。有些人可以檢測到使用了Emacs或啞終端,並且不會發送那些無法解釋的字符,但Node不會這樣做。無論如何,你可以使用這樣的東西:

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

某處在你的.emacs。

Stackoverflow將不會正確地複製控制字符,正則表達式中的第一個字符(在引號之後和斜線之前)是^[字符。您可以通過執行來輸入它在Emacs中輸入的內容C-q 0 3 3接下來輸入的任何內容都會導致控制字符被插入到當前緩衝區中。

+1

您的解決方案適用於shell,但不適用於eshell。 eshell使用eshell-output-filter-functions使用類似的方法進行過濾(add-to-list 'shell-output-filter-functions'(lambda() (save-excursion (replace-regexp「\\ [0-9] + [GKJ]」 「」 無 \t \t ESHELL-最後輸出啓動 \t \t ESHELL-最後輸出端)))) 作品,但速度慢。我在想什麼是如何告訴npm使用NODE_NO_READLINE = 1 –

+0

我得到: > console.log('是這種切割出奇怪的方式?') console.lo('是這個cuttin東西出奇怪的方式?') 這停止特殊字符,但我不再有克。 comint特殊字符格式看起來像是什麼樣的正則表達式? – Mittenchops

+0

正則表達式必須是「\ 033 \\ [[0-9] + [GK]」爲mw工作基於http://stackoverflow.com/questions/13862471/using-node-js-with-js-comint -in-emacs – pellekrogholt