예제 #1
0
파일: ui.go 프로젝트: shaunstanislaus/oh
func New(args []string) *cli {
	if len(args) > 1 {
		return nil
	}

	// We assume the terminal starts in cooked mode.
	cooked, _ = liner.TerminalMode()
	if cooked == nil {
		return nil
	}

	i := &cli{liner.NewLiner()}

	if history_path, err := task.GetHistoryFilePath(); err == nil {
		if f, err := os.Open(history_path); err == nil {
			i.ReadHistory(f)
			f.Close()
		}
	}

	uncooked, _ = liner.TerminalMode()

	i.SetCtrlCAborts(true)
	i.SetTabCompletionStyle(liner.TabPrints)
	i.SetWordCompleter(complete)

	return i
}
예제 #2
0
파일: task.go 프로젝트: jmptrader/oh
func LaunchForegroundTask() {
	if task0 != nil {
		mode, _ := liner.TerminalMode()
		task0.Job.mode = mode
	}
	task0 = NewTask(Cons(nil, Null), nil, nil, nil)
	go task0.Listen()
}
예제 #3
0
func newUserInputReader() *userInputReader {
	r := new(userInputReader)
	// Get the original mode before calling NewLiner.
	// This is usually regular "cooked" mode where characters echo.
	normalMode, _ := liner.TerminalMode()
	// Turn on liner. It switches to raw mode.
	r.State = liner.NewLiner()
	rawMode, err := liner.TerminalMode()
	if err != nil || !liner.TerminalSupported() {
		r.supported = false
	} else {
		r.supported = true
		r.normalMode = normalMode
		r.rawMode = rawMode
		// Switch back to normal mode while we're not prompting.
		normalMode.ApplyMode()
	}
	return r
}
예제 #4
0
파일: ui.go 프로젝트: jmptrader/oh
func New(args []string) *cli {
	if len(args) > 1 {
		return nil
	}

	// We assume the terminal starts in cooked mode.
	cooked, _ = liner.TerminalMode()
	if cooked == nil {
		return nil
	}

	i := &cli{liner.NewLiner()}

	uncooked, _ = liner.TerminalMode()

	i.SetCtrlCAborts(true)
	i.SetTabCompletionStyle(liner.TabPrints)
	i.SetWordCompleter(complete)

	return i
}
예제 #5
0
// newTerminalPrompter creates a liner based user input prompter working off the
// standard input and output streams.
func newTerminalPrompter() *terminalPrompter {
	p := new(terminalPrompter)
	// Get the original mode before calling NewLiner.
	// This is usually regular "cooked" mode where characters echo.
	normalMode, _ := liner.TerminalMode()
	// Turn on liner. It switches to raw mode.
	p.State = liner.NewLiner()
	rawMode, err := liner.TerminalMode()
	if err != nil || !liner.TerminalSupported() {
		p.supported = false
	} else {
		p.supported = true
		p.normalMode = normalMode
		p.rawMode = rawMode
		// Switch back to normal mode while we're not prompting.
		normalMode.ApplyMode()
	}
	p.SetCtrlCAborts(true)
	p.SetTabCompletionStyle(liner.TabPrints)

	return p
}
예제 #6
0
func NewPrompter() *Prompter {
	origMode, err := liner.TerminalMode()
	if err != nil {
		panic(err)
	}

	p := &Prompter{
		prompt:   "zygo> ",
		prompter: liner.NewLiner(),
		origMode: origMode,
	}

	rawMode, err := liner.TerminalMode()
	if err != nil {
		panic(err)
	}
	p.rawMode = rawMode

	p.prompter.SetCtrlCAborts(false)
	//p.prompter.SetTabCompletionStyle(liner.TabPrints)

	p.prompter.SetCompleter(func(line string) (c []string) {
		for _, n := range completion_keywords {
			if strings.HasPrefix(n, strings.ToLower(line)) {
				c = append(c, n)
			}
		}
		return
	})

	if f, err := os.Open(history_fn); err == nil {
		p.prompter.ReadHistory(f)
		f.Close()
	}

	return p
}
예제 #7
0
파일: types.go 프로젝트: dsubhajit/oh
func NewJob() *Job {
	mode, _ := liner.TerminalMode()
	return &Job{&sync.Mutex{}, "", 0, mode}
}
예제 #8
0
파일: ui.go 프로젝트: michaelmacinnis/oh
func (i *cli) TerminalMode() (task.ApplyModer, error) {
	return liner.TerminalMode()
}