Пример #1
0
// Gets password from input
func getPass() string {
	gc.Echo(false)
	stdscr := gc.StdScr()
	var returnString []byte

	x := 0
	var c gc.Char
	var rawInput gc.Key
	for {
		rawInput = stdscr.GetChar()
		c = gc.Char(rawInput)
		if rawInput == gc.KEY_BACKSPACE || c == gc.Char(127) {
			if x != 0 {
				returnString = returnString[0 : len(returnString)-1]
				x--
			} else {
				continue
			}
		} else if rawInput == gc.KEY_RETURN {
			if x != 0 {
				return string(returnString)
			}
		} else if c > 31 && c < 127 {
			returnString = append(returnString, byte(c))
			x++
		} else {
			continue
		}
	}
}
Пример #2
0
// Gets the passphrase to the chat database from the user
func passphraseUnlock() string {
	stdscr := gc.StdScr()
	y, x := stdscr.MaxYX()
	stdscr.Println()
	stdscr.MovePrintln((2*int(y/3))-2, int(x/2)-16, "Please enter your passphrase:")
	stdscr.Move((2*int(y/3))-1, int(x/2)-16)

	pass = getPass()
	return pass
}
Пример #3
0
// function to read the verification code stolen from janimo
func readLine(prompt string) string {
	stdscr := gc.StdScr()
	y, x := stdscr.MaxYX()
	stdscr.Println()
	stdscr.MovePrintln((2*int(y/3))-2, int(x/2)-16, "Please enter the verification code:")
	stdscr.Move((2*int(y/3))-1, int(x/2)-16)

	pass = getPass()
	return pass
}
Пример #4
0
func main() {
	var term1, term2 *gc.Screen
	var err error

	flag.Parse()

	if flag.NArg() != 1 {
		log.Fatal("Must supply path to a pseudo-terminal (ie. /dev/pts/0)")
	}

	// You can, for example, use the current psuedo-terminal to read/write to
	// You may need to change the  to one you have read/write access to
	var pts *os.File
	pts, err = os.OpenFile(flag.Arg(0), os.O_RDWR, os.FileMode(666))
	if err != nil {
		log.Fatal(err)
	}
	defer pts.Close()

	// Create a new terminal using the default $TERM type and the psuedo-terminal
	term1, err = gc.NewTerm("", pts, pts)
	if err != nil {
		log.Fatal("newterm:", err)
	}
	// Remember that defer is LIFO order and End must be called prior to Delete
	defer term1.Delete()
	defer term1.End()

	// Create a second terminal as if we had two to interact with
	term2, err = gc.NewTerm("", os.Stdout, os.Stdin)
	if err != nil {
		log.Fatal("newterm:", err)
	}
	// It is important that End is called on term2 prior to term1
	defer term2.Delete()
	defer term2.End() // comment out for an alternative to End
	//defer gc.End()    // uncomment for alternate way to end
	//defer term2.Set() // uncomment

	// Set the active terminal to term1
	term1.Set()

	// Get the Standard Screen Window and write to the active terminal
	mw := gc.StdScr()
	mw.MovePrint(0, 0, "Term 1 works! Press any key to exit...")
	mw.Refresh()
	mw.GetChar()

	// activate term2 and send data to it
	term2.Set()
	mw.MovePrint(0, 0, "Term 2 works! Press any key to exit...")
	mw.Refresh()
	mw.GetChar()
}