// Interactive sets this gosh's mode to interactive.
// User input is read from the underlying terminal
// and commands are executed in the current namespace.
// A suitable exit code and any error is returned in the end.
Interactive sets this gosh's mode to interactive.
User input is read from the underlying terminal
and commands are executed in the current namespace.
A suitable exit code and any error is returned in the end.
// Interactive sets this gosh ' s mode to interactive . // User input is read from the underlying terminal // and commands are executed in the current namespace . // A suitable exit code and any error is returned in the end .
func (g *Gosh) Interactive() (int, error) {
	var err error
	if !g.ready {
		err = g.Init()
		if err != nil {
			os.Stdout.WriteString("Error occurred during intialization:")
			os.Stdout.WriteString(err.Error())
			os.Stdout.WriteString("\n")
			return 1, err
		}
		defer g.Close()
	}
	var in []termios.Key
	var k termios.Key
	g.DebugMessage(shared.ModMain, "Going interactive")
	g.term.Write([]byte(fmt.Sprintf("This is %s %s. Press C-d to exit.\r\n", shared.GoshName, shared.GoshVersion)))
	g.prompt.redraw()
	for {
		g.term.SetRaw(true)
		in, err = g.term.Read()
		g.term.SetRaw(false)
		if err != nil {
			os.Stdout.WriteString("Error reading input:\n")
			os.Stdout.WriteString(err.Error() + "\n")
		} else {
			for _, k = range in {
				if k.Equal(&keyCd) { 
					return 0, nil
				}
				if !g.handler.PreSendKey(g, &k) {
					g.DebugMessage(shared.ModMain, "Skipping this key because a plugin skipped it")
					continue
				}
				g.prompt.OnKey(k)
				if !g.ready {
					return 0, nil
				}
			}
		}
	}
}
func ( g * Gosh ) Interactive ( ) ( int , error ) { var err error if ! g . ready { err = g . Init ( ) if err != nil { os . Stdout . WriteString ( " " ) os . Stdout . WriteString ( err . Error ( ) ) os . Stdout . WriteString ( " \n " ) return 1 , err } defer g . Close ( ) } var in [ ] termios . Key var k termios . Key g . DebugMessage ( shared . ModMain , " " ) g . term . Write ( [ ] byte ( fmt . Sprintf ( " \r \n " , shared . GoshName , shared . GoshVersion ) ) ) g . prompt . redraw ( ) for { g . term . SetRaw ( true ) in , err = g . term . Read ( ) g . term . SetRaw ( false ) if err != nil { os . Stdout . WriteString ( " \n " ) os . Stdout . WriteString ( err . Error ( ) + " \n " ) } else { for _ , k = range in { if k . Equal ( & keyCd ) { return 0 , nil } if ! g . handler . PreSendKey ( g , & k ) { g . DebugMessage ( shared . ModMain , " " ) continue } g . prompt . OnKey ( k ) if ! g . ready { return 0 , nil } } } } }
Interactive sets this gosh's mode to interactive.
Interactive sets this gosh ' s mode to interactive .
// Consider g.term broken: // C-d to quit // If the terminal has been closed because of that key, // return: