func select_device() (*evdev.InputDevice, error) {
	devices, _ := evdev.ListInputDevices(device_glob)

	lines := make([]string, 0)
	max := 0
	if len(devices) > 0 {
		for i := range devices {
			dev := devices[i]
			str := fmt.Sprintf("%-3d %-20s %-35s %-35s %s", i, dev.Fn, dev.Name, dev.Phys, dev.Ident)
			if len(str) > max {
				max = len(str)
			}
			lines = append(lines, str)
		}
		fmt.Printf("%-3s %-20s %-35s %-35s %s\n", "ID", "Device", "Name", "Phys", "Ident")
		fmt.Printf(strings.Repeat("-", max) + "\n")
		fmt.Printf(strings.Join(lines, "\n") + "\n")

		var choice int
		choice_max := len(lines) - 1

	ReadChoice:
		fmt.Printf("Select device [0-%d]: ", choice_max)
		_, err := fmt.Scan(&choice)
		if err != nil || choice > choice_max || choice < 0 {
			goto ReadChoice
		}

		return devices[choice], nil
	}

	errmsg := fmt.Sprintf("no accessible input devices found by %s", device_glob)
	return nil, errors.New(errmsg)
}
// Select a device from a list of accessible input devices.
Select a device from a list of accessible input devices.
// Select a device from a list of accessible input devices .
func select_device() (*evdev.InputDevice, error) {
	devices, _ := evdev.ListInputDevices(device_glob)
	lines := make([]string, 0)
	max := 0
	if len(devices) > 0 {
		for i := range devices {
			dev := devices[i]
			str := fmt.Sprintf("%-3d %-20s %-35s %-35s %s", i, dev.Fn, dev.Name, dev.Phys, dev.Ident)
			if len(str) > max {
				max = len(str)
			}
			lines = append(lines, str)
		}
		fmt.Printf("%-3s %-20s %-35s %-35s %s\n", "ID", "Device", "Name", "Phys", "Ident")
		fmt.Printf(strings.Repeat("-", max) + "\n")
		fmt.Printf(strings.Join(lines, "\n") + "\n")
		var choice int
		choice_max := len(lines) - 1
	ReadChoice:
		fmt.Printf("Select device [0-%d]: ", choice_max)
		_, err := fmt.Scan(&choice)
		if err != nil || choice > choice_max || choice < 0 {
			goto ReadChoice
		}
		return devices[choice], nil
	}
	errmsg := fmt.Sprintf("no accessible input devices found by %s", device_glob)
	return nil, errors.New(errmsg)
}
func select_device ( ) ( * evdev . InputDevice , error ) { devices , _ := evdev . ListInputDevices ( device_glob ) lines := make ( [ ] string , 0 ) max := 0 if len ( devices ) > 0 { for i := range devices { dev := devices [ i ] str := fmt . Sprintf ( " " , i , dev . Fn , dev . Name , dev . Phys , dev . Ident ) if len ( str ) > max { max = len ( str ) } lines = append ( lines , str ) } fmt . Printf ( " \n " , " " , " " , " " , " " , " " ) fmt . Printf ( strings . Repeat ( " " , max ) + " \n " ) fmt . Printf ( strings . Join ( lines , " \n " ) + " \n " ) var choice int choice_max := len ( lines ) - 1 ReadChoice : fmt . Printf ( " " , choice_max ) _ , err := fmt . Scan ( & choice ) if err != nil || choice > choice_max || choice < 0 { goto ReadChoice } return devices [ choice ] , nil } errmsg := fmt . Sprintf ( " " , device_glob ) return nil , errors . New ( errmsg ) }
Select a device from a list of accessible input devices.
Select a device from a list of accessible input devices .