diff --git a/README.md b/README.md index b8ebf5f..236d7cd 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,7 @@ To configure `qrcp` you can create a configuration file inside `$XDG_CONFIG_HOME > Note: On Linux, the `$XDG_CONFIG_HOME` is `.config` under user home directory. > So, for example, on Linux the configuration file will be `$HOME/.config/qrcp/config.yml`. +> On MacOS, it defaults to `$HOME/Library/Application Support/qrcp/config.yml`` > Note: Starting from version 0.10.0, qrcp uses a YAML configuration file instead of the old JSON one. You can automatically migrate the legacy JSON format to the new YAML format by running `qrcp config migrate`. @@ -214,6 +215,7 @@ To configure `qrcp` you can create a configuration file inside `$XDG_CONFIG_HOME | `secure` | Bool | Controls whether `qrcp` should use HTTPS instead of HTTP. Defaults to `false` | | `tls-cert` | String | Path to the TLS certificate. It's only used when `secure: true`. | | `tls-key` | String | Path to the TLS key. It's only used when `secure: true`. | +| `reversed` | Bool | Reverse QR code (black text on white background)?" true`. | All the configuration parameters can be controlled via environment variables prefixed with `QRCP_`, for example: diff --git a/application/application.go b/application/application.go index 4a6b185..637d9cf 100644 --- a/application/application.go +++ b/application/application.go @@ -16,6 +16,7 @@ type Flags struct { TlsCert string TlsKey string Output string + Reversed bool } type App struct { diff --git a/cmd/qrcp.go b/cmd/qrcp.go index 4569a56..8eefc41 100644 --- a/cmd/qrcp.go +++ b/cmd/qrcp.go @@ -30,6 +30,7 @@ func init() { rootCmd.PersistentFlags().BoolVarP(&app.Flags.Secure, "secure", "s", false, "use https connection") rootCmd.PersistentFlags().StringVar(&app.Flags.TlsCert, "tls-cert", "", "path to TLS certificate to use with HTTPS") rootCmd.PersistentFlags().StringVar(&app.Flags.TlsKey, "tls-key", "", "path to TLS private key to use with HTTPS") + rootCmd.PersistentFlags().BoolVarP(&app.Flags.Reversed, "reversed", "r", false, "Reverse QR code (black text on white background)") // Receive command flags receiveCmd.PersistentFlags().StringVarP(&app.Flags.Output, "output", "o", "", "output directory for receiving files") } diff --git a/cmd/receive.go b/cmd/receive.go index 1dc1f20..4cc4aa8 100644 --- a/cmd/receive.go +++ b/cmd/receive.go @@ -28,7 +28,7 @@ func receiveCmdFunc(command *cobra.Command, args []string) error { log.Print(`Scan the following URL with a QR reader to start the file transfer, press CTRL+C or "q" to exit:`) log.Print(srv.ReceiveURL) // Renders the QR - qr.RenderString(srv.ReceiveURL) + qr.RenderString(srv.ReceiveURL, cfg.Reversed) if app.Flags.Browser { srv.DisplayQR(srv.ReceiveURL) } diff --git a/cmd/send.go b/cmd/send.go index a6ff716..9b6c2a0 100644 --- a/cmd/send.go +++ b/cmd/send.go @@ -31,7 +31,7 @@ func sendCmdFunc(command *cobra.Command, args []string) error { srv.Send(payload) log.Print(`Scan the following URL with a QR reader to start the file transfer, press CTRL+C or "q" to exit:`) log.Print(srv.SendURL) - qr.RenderString(srv.SendURL) + qr.RenderString(srv.SendURL, cfg.Reversed) if app.Flags.Browser { srv.DisplayQR(srv.SendURL) } diff --git a/config/config.go b/config/config.go index 9b644dc..3b1f93a 100644 --- a/config/config.go +++ b/config/config.go @@ -27,6 +27,7 @@ type Config struct { TlsCert string `yaml:",omitempty"` FQDN string `yaml:",omitempty"` Output string `yaml:",omitempty"` + Reversed bool `yaml:",omitempty"` } var interactive bool = false @@ -61,6 +62,7 @@ func New(app application.App) Config { cfg.TlsCert = v.GetString("tls-cert") cfg.FQDN = v.GetString("fqdn") cfg.Output = v.GetString("output") + cfg.Reversed = v.GetBool("reversed") // Override if app.Flags.Interface != "" { @@ -93,6 +95,9 @@ func New(app application.App) Config { if app.Flags.Output != "" { cfg.Output = app.Flags.Output } + if app.Flags.Reversed { + cfg.Reversed = true + } // Discover interface if it's not been set yet if !interactive { @@ -306,6 +311,16 @@ func Wizard(app application.App) error { v.Set("output", output) } } + promptReversed := promptui.Select{ + Items: []string{"No", "Yes"}, + Label: "Reverse QR code (black text on white background)?", + } + if _, promptReversedResultString, err := promptReversed.Run(); err == nil { + if promptReversedResultString == "Yes" { + v.Set("reversed", true) + } + cfg.Reversed = v.GetBool("reversed") + } return v.WriteConfig() } diff --git a/config/config_test.go b/config/config_test.go index 830ea4c..8f3eb84 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -96,6 +96,7 @@ func TestNew(t *testing.T) { TlsCert: "/path/to/cert", FQDN: "mylan.com", Output: "/path/to/default/output/dir", + Reversed: true, }, }, { @@ -118,6 +119,7 @@ func TestNew(t *testing.T) { TlsCert: "/path/to/cert", FQDN: "mylan.com", Output: "/path/to/default/output/dir", + Reversed: true, }, }, } diff --git a/config/testdata/full.yml b/config/testdata/full.yml index 820d917..6c97817 100644 --- a/config/testdata/full.yml +++ b/config/testdata/full.yml @@ -8,3 +8,4 @@ tls-key: /path/to/key tls-cert: /path/to/cert fqdn: mylan.com output: /path/to/default/output/dir +reversed: true diff --git a/docs/index.md b/docs/index.md index 7682823..64a3cc6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -259,6 +259,13 @@ qrcp --tls-cert /path/to/cert.pem --tls-key /path/to/cert.key MyDocument A `--secure` flag is available too, you can use it to override the default value. +### Color scheme + +By default, `qrcp`` is configured for terminals with light text on a dark background. Terminals with a light color scheme can invert this with the `--reversed` or `-r` flag. + +```sh +qrcp --reversed MyDocument.pdf +``` ### Open in browser diff --git a/qr/qr.go b/qr/qr.go index 8e03b2c..2b0e8d9 100644 --- a/qr/qr.go +++ b/qr/qr.go @@ -9,12 +9,12 @@ import ( ) // RenderString as a QR code -func RenderString(s string) { +func RenderString(s string, inverseColor bool) { q, err := qrcode.New(s, qrcode.Medium) if err != nil { log.Fatal(err) } - fmt.Println(q.ToSmallString(false)) + fmt.Println(q.ToSmallString(inverseColor)) } // RenderImage returns a QR code as an image.Image