Пример #1
0
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 hpath, err := system.GetHistoryFilePath(); err == nil {
		if f, err := os.Open(hpath); err == nil {
			i.ReadHistory(f)
			f.Close()
		}
	}

	uncooked, _ = liner.TerminalMode()

	i.SetCtrlCAborts(true)
	i.SetTabCompletionStyle(liner.TabPrints)
	i.SetShouldRestart(system.ResetForegroundGroup)
	i.SetWordCompleter(complete)

	return i
}
Пример #2
0
func (i *cli) Close() error {
	if i.Exists() {
		if hpath, err := system.GetHistoryFilePath(); err == nil {
			if f, err := os.Create(hpath); err == nil {
				i.WriteHistory(f)
				f.Close()
			} else {
				println("Error writing history: " + err.Error())
			}
		}
	}
	return i.State.Close()
}