Last active
May 28, 2021 02:57
-
-
Save davecheney/64f46f2b969c238132cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// junkterm is a quick and dirty serial terminal. | |
package main | |
import ( | |
"io" | |
"log" | |
"os" | |
"github.com/pkg/term" | |
"github.com/spf13/cobra" | |
) | |
func main() { | |
var baud int | |
var dev string | |
cmd := &cobra.Command{ | |
Use: "junkterm", | |
Short: "junkterm is a quick and dirty serial terminal.", | |
Run: func(cmd *cobra.Command, args []string) { | |
term, err := term.Open(dev, term.Speed(baud), term.RawMode) | |
if err != nil { | |
log.Fatal(err) | |
} | |
go io.Copy(os.Stdout, term) | |
io.Copy(term, os.Stdin) | |
}, | |
} | |
cmd.Flags().IntVarP(&baud, "baud", "b", 115200, "baud rate") | |
cmd.Flags().StringVarP(&dev, "dev", "d", "/dev/USB0", "device") | |
cmd.Execute() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment