簡體   English   中英

如何從node.js REPL啟動vi或emacs之類的編輯器?

[英]How to launch editor like vi or emacs from node.js REPL?

我想從node.js REPL中啟動vi或emacs之類的編輯器。

到目前為止,我已經嘗試了兩種方法:

  1. 節點插件

    這是我的editor.cc樣子:

     const char *tempFile = "TEMP_FILE"; // File to be opened with the editor Handle<Value> launchEditor (const Arguments& args) { const char *editor = "vi"; Local<String> buffer; pid_t pid = fork(); if (pid == 0) { execlp(editor, editor, tempFile, NULL); // Exit with "command-not-found" if above fails. exit(127); } else { waitpid(pid, 0, 0); char *fileContent = readTempFile(); // Simple file IO code to read file. buffer = String::New(fileContent); free(fileContent); } return buffer; } // MAKE IT A NODE MODULE void Init(Handle<Object> target) { target->Set(String::NewSymbol("editor"), FunctionTemplate::New(launchEditor)->GetFunction()); } NODE_MODULE(editor, Init) 

    當我擁有節點v0.6.12(與node-waf編譯)時,此方法有效,但是當我將節點更新至v0.8.1時,此代碼停止工作(與node-gyp gyp編譯)。 編輯器根本沒有出現,並且文件內容已讀取並返回(使用emacs),或者編輯器作為后台進程運行(使用vi)! 我需要更改使其與0.8.1一起使用嗎?

    即使將編輯器作為后台進程啟動,我也可以從代碼本身將其帶到前台嗎?

  2. Child_process模塊

     spawn = require('child_process').spawn; editor = spawn('emacs', ['TEMP_FILE']); 

    但這不能正常工作。 使用emacs,它顯示錯誤input is not a tty而vi提供了一個奇怪的界面。

有人可以提供上述任何解決方案的幫助,還是可以提出其他可行的解決方案?

大約一周前,我偶然發現了一個,您應該嘗試一下: node-editor

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM