Skip to content

Instantly share code, notes, and snippets.

@davecheney
Last active May 28, 2021 02:57
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davecheney/64f46f2b969c238132cb to your computer and use it in GitHub Desktop.
Save davecheney/64f46f2b969c238132cb to your computer and use it in GitHub Desktop.
// 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