加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – vi命令行中的输入模式Matlab?

发布时间:2020-12-16 20:46:02 所属栏目:百科 来源:网络整理
导读:我在?/ .inputrc中有这些行: set editing-mode vi set keymap vi 这允许我在使用GNU readlines进行文本输入的每个程序中使用vi键绑定.示例:python,irb,sftp,bash,sqlite3等.它使命令行的工作变得轻而易举. Matlab不使用readline,但是在调试或交互式工作时,
我在?/ .inputrc中有这些行:
set editing-mode vi 
set keymap vi

这允许我在使用GNU readlines进行文本输入的每个程序中使用vi键绑定.示例:python,irb,sftp,bash,sqlite3等.它使命令行的工作变得轻而易举. Matlab不使用readline,但是在调试或交互式工作时,vi键绑定将是惊人的.有现有的解决方案吗?

我倾向于从命令行使用matlab -nosplash -nodesktop,这让我想到:是否可以编写一个使用readline并将输入传递给matlab的包装器? (如果我必须实现这一点,我可能更喜欢在Ruby中这样做.)

更新:

谢谢您的帮助.这几乎工作:

# See also: http://bogojoker.com/readline/
require 'readline'

puts 'Starting Matlab...'
io = IO.popen('matlab -nosplash -nodesktop 2>&1','w+')

while input_line = Readline.readline('>> ',true)
  io.puts input_line
  puts io.gets
end

但是它一次只能从Matlab读取一行(因为我正在使用get).任何关于如何获得所有东西的想法,直到下一次等待输入?以下是发生的情况(我在>>提示符下输入内容):

Starting Matlab...
>> 1

>> 2
                            < M A T L A B (R) >
>> 3
                  Copyright 1984-2009 The MathWorks,Inc.
>> 4
                 Version 7.8.0.347 (R2009a) 32-bit (glnx86)
>> 5
                             February 12,2009
>> 6

>> 7

>> 8
  To get started,type one of these: helpwin,helpdesk,or demo.
>> 9
  For product information,visit www.mathworks.com.
>> 0

>> 1
>> 
>> 2
ans =
>> 3

>> 4
     1
>> 5

>> 6
>> 
>> 7
ans =
>> 8

>> 9
     2
>> 0

>> 1
>> 
>> 2
ans =
>> 3

>> 4
     3

解决方法

是的,这应该很容易.这只是一般的“打开一个进程并绑定到其stdin和stdout”的特殊情况,这并不困难.

谷歌搜索发现,IO.popen()是Ruby的正确的一块,在这里有一个更多的细节:http://groups.google.com/group/ruby-talk-google/browse_thread/thread/0bbf0a3f1668184c.希望,这足以让你开始!

更新:看起来你几乎与你的包装.您需要完成的是在Matlab要求输入时才识别,并且仅向用户询问输入.我建议尝试这个伪代码:

while input_line = Readline.readline('>> ',true)
  io.puts input_line
  while ((output_line = io.gets) != '>> ')  // Loop until we get a prompt.
    puts io.gets
  end
end

这是不正确的,因为您需要在要求第一个输入行之前进行一次内部循环,但它应该给您一个想法.您也可能需要调整正在寻找的提示文本.

更新2:好的,所以我们也需要解释一个事实,没有任何EOL后提示,所以io.gets将挂起.这是一个修订版本,它使用一个事实,你可以给一个空白行到Matlab提示符,它只会给你一个提示,而不做任何事情.我重新排列了循环,使事情变得更清晰一点,虽然这意味着你现在必须添加逻辑,以便在完成任务后才能确定.

while [not done]   // figure this out somehow
  io.puts blank_line                        // This will answer the first
                                            // prompt we get.
  while ((output_line = io.gets) != '>> ')  // Loop until we get a prompt.
    puts io.gets                            // This won't hang,since the
  end                                       // prompt will get the blank
                                            // line we just sent.

  input_line = Readline.readline('>> ',true)  // Get something,feed it
  io.puts input_line                           // to the next prompt.

  output_line = io.gets   // This will eat the prompt that corresponds to
                          // the line we just fed in.
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读