C的
getchar()示例:
#include <stdio.h>void main(){ char ch; ch = getchar(); printf("Input Char Is :%c",ch);}等效:
package mainimport ( "bufio" "fmt" "os")func main() { reader := bufio.NewReader(os.Stdin) input, _ := reader.ReadString('n') fmt.Printf("Input Char Is : %v", string([]byte(input)[0])) // fmt.Printf("You entered: %v", []byte(input))}最后的注释行仅显示当您按下
tab第一个元素时,是U + 0009(’CHARACTER TABULATION’)。
但是,由于您的需要(检测选项卡),C
getchar()并不适合,因为它需要用户按Enter键。您需要的是@miku提到的ncurses的getch()/ readline /
jLine之类的东西。有了这些,您实际上可以等待一次击键。
因此,您有多种选择:
使用
ncurses
/readline
绑定,例如https://pre.google.com/p/goncurses/或类似的https://github.com/nsf/termbox自己滚动,请参阅http://play.golang.org/p/plwBIIYiqG作为起点
用于
os.Exec
运行stty或jLine。
参考:
https://groups.google.com/forum/?fromgroups=#!topic/golang-
nuts/zhBE5MH4n-Q
https://groups.google.com/forum/?fromgroups=#!topic/golang-
nuts/S9AO_kHktiY
https://groups.google.com/forum/?fromgroups=#!topic/golang-
nuts/icMfYF8wJCk



