github.com/secoba/wails/v2@v2.6.4/pkg/menu/keys/stringify.go (about)

     1  package keys
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/leaanthony/slicer"
     7  )
     8  
     9  var modifierStringMap = map[string]map[Modifier]string{
    10  	"windows": {
    11  		CmdOrCtrlKey:   "Ctrl",
    12  		ControlKey:     "Ctrl",
    13  		OptionOrAltKey: "Alt",
    14  		ShiftKey:       "Shift",
    15  		// SuperKey:       "Win",
    16  	},
    17  	"darwin": {
    18  		CmdOrCtrlKey:   "Cmd",
    19  		ControlKey:     "Ctrl",
    20  		OptionOrAltKey: "Option",
    21  		ShiftKey:       "Shift",
    22  		// SuperKey:       "Cmd",
    23  	},
    24  	"linux": {
    25  		CmdOrCtrlKey:   "Ctrl",
    26  		ControlKey:     "Ctrl",
    27  		OptionOrAltKey: "Alt",
    28  		ShiftKey:       "Shift",
    29  		// SuperKey:       "Super",
    30  	},
    31  }
    32  
    33  func Stringify(accelerator *Accelerator, platform string) string {
    34  	result := slicer.String()
    35  	for _, modifier := range accelerator.Modifiers {
    36  		result.Add(modifierStringMap[platform][modifier])
    37  	}
    38  	result.Deduplicate()
    39  	result.Add(strings.ToUpper(accelerator.Key))
    40  	return result.Join("+")
    41  }