Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Autocomplete 这些空间是从哪里来的?_Autocomplete_Terminal_Tcl - Fatal编程技术网

Autocomplete 这些空间是从哪里来的?

Autocomplete 这些空间是从哪里来的?,autocomplete,terminal,tcl,Autocomplete,Terminal,Tcl,我看不出这里有什么…尝试创建一个简单的脚本来获取用户输入,仅限于常规字符(a-z,a-z,0-9和-),并为定义的短语列表自动完成选项卡…它工作,有点 #!/usr/local/scripts/packages/bin/expect set completes { "red one" "blue two" "green three" "four more" } proc enableRaw {{channel stdin}} { exec /bin/stty raw -echo &l

我看不出这里有什么…尝试创建一个简单的脚本来获取用户输入,仅限于常规字符(a-z,a-z,0-9和-),并为定义的短语列表自动完成选项卡…它工作,有点

#!/usr/local/scripts/packages/bin/expect

set completes { "red one" "blue two" "green three" "four more"  }

proc enableRaw {{channel stdin}} {
   exec /bin/stty raw -echo <@$channel
}

proc disableRaw {{channel stdin}} {
   exec /bin/stty -raw echo <@$channel
}

proc complete { partial } {
  global completes
  set index [lsearch $completes "${partial}*"]
  if { $index != -1 } {
    return [lindex $completes $index]
  } else {
    return $partial
  }
}

enableRaw

set c [read stdin 1]
scan $c %c ascii
set word ""
while {$ascii != 10} {
    switch $ascii {
      9 {
        # TAB
        set word [complete $word]
        puts -nonewline "\n$word"
      }
      127 {A
        # BACKSPACE
        puts -nonewline $c
        set word [string range $word 0 [expr [string length $word] - 2]]
      }
      default {
        switch -regex " $c" {
          " [ a-zA-Z0-9\-]" {
            puts -nonewline $c
            set word "$word$c"
          }
          default {}
        }
      }
    }
    flush stdout
    set c [read stdin 1]
    scan $c %c ascii
}

disableRaw
puts "\n>$word<"
#/usr/local/scripts/packages/bin/expect
集合完成{“红色一号”“蓝色二号”“绿色三号”“四号”}
proc enableRaw{{channel stdin}}{

exec/bin/stty raw-echo我认为,因为你在“raw”模式下,除了在完成后的换行符外,您还需要输出回车符。哦,是的,当然,谢谢:-)如果我将\n替换为\r,效果会更好,因此现在制表符在同一行上自动完成:-D@glennjackman是否要添加您的评论作为答案?
bash-3.2$ ./complete_on_tab.exp
red                                    <- tab entered
red one
>red one<
bash-3.2$
bash-3.2$ ./complete_on_tab.exp
red                                    <- tab entered
   red one                             <- why the indent?
>red one<
bash-3.2$