64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package widgets
|
|
|
|
import (
|
|
"ArinDash/config"
|
|
"ArinDash/util"
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/mum4k/termdash/terminal/terminalapi"
|
|
"github.com/mum4k/termdash/widgetapi"
|
|
"github.com/mum4k/termdash/widgets/text"
|
|
)
|
|
|
|
type configFile struct {
|
|
Wifi wifiConfig
|
|
}
|
|
|
|
type wifiConfig struct {
|
|
Auth string
|
|
SSID string
|
|
Password string
|
|
}
|
|
|
|
const template = "WIFI:T:%s;S:%s;P:%s;;"
|
|
|
|
type WifiQRCodeOptions struct {
|
|
}
|
|
|
|
func WifiQRCode() WifiQRCodeOptions {
|
|
widgetOptions["WifiQRCodeOptions"] = createWifiQRCode
|
|
return WifiQRCodeOptions{}
|
|
}
|
|
|
|
func createWifiQRCode(_ context.Context, _ terminalapi.Terminal, _ interface{}) widgetapi.Widget {
|
|
cfg := &configFile{}
|
|
config.LoadConfig(cfg)
|
|
|
|
widget := util.PanicOnErrorWithResult(text.New())
|
|
|
|
util.PanicOnError(widget.Write(QrCodeASCII(fmt.Sprintf(template, cfg.Wifi.Auth, escapeSpecialChars(cfg.Wifi.SSID), escapeSpecialChars(cfg.Wifi.Password)))))
|
|
|
|
return widget
|
|
}
|
|
|
|
func escapeSpecialChars(s string) string {
|
|
return strings.ReplaceAll(
|
|
strings.ReplaceAll(
|
|
strings.ReplaceAll(
|
|
strings.ReplaceAll(
|
|
strings.ReplaceAll(
|
|
s,
|
|
"\\", "\\\\",
|
|
),
|
|
"\"", "\\\"",
|
|
),
|
|
",", "\\,",
|
|
),
|
|
";", "\\;",
|
|
),
|
|
":", "\\:",
|
|
)
|
|
}
|