scoop:scoop.window:0.1.0
platform/apple/shortcut_labels.scoop
Selected production source · platform/apple/shortcut_labels.scoop
1
package scoop.window3
internal fun platformShortcutLabel(chord: ShortcutChord): ShortcutLabel {4
val modifiers = resolvedModifiers(chord.modifiers, platformPrimaryModifier())5
val parts = ArrayList<String>()6
if (modifiers.control) parts.add("⌃")7
if (modifiers.alt) parts.add("⌥")8
if (modifiers.shift) parts.add("⇧")9
if (modifiers.superKey) parts.add("⌘")10
if (modifiers.function) parts.add("fn")11
parts.add(darwinShortcutLabel(chord.key))12
return ShortcutLabel(parts.toArray(), "")13
}15
private fun darwinShortcutLabel(key: ShortcutKey): String {16
return when (key) {17
case Logical(LogicalKey.Character(val text)) -> text18
case Logical(LogicalKey.Named(val key)) -> appleNamedLabel(key)19
case Logical(LogicalKey.Dead(_)) ->20
throw IllegalArgumentException(21
Some("dead shortcut key")22
)23
case Logical(LogicalKey.Unidentified(_)) -> "Unknown"24
case Physical(PhysicalKey.Unidentified(_)) -> "Unknown"25
case Physical(PhysicalKey.Code(val key)) -> applePhysicalLabel(key)26
}27
}29
internal fun appleNamedLabel(key: NamedKey): String = when (key) {30
case Enter -> "↩"31
case Tab -> "⇥"32
case Space -> "␣"33
case Backspace -> "⌫"34
case Escape -> "⎋"35
case Shift -> "⇧"36
case Control -> "⌃"37
case Alt -> "⌥"38
case Super -> "⌘"39
case CapsLock -> "⇪"40
case NumLock -> "Num Lock"41
case ScrollLock -> "Scroll Lock"42
case Insert -> "Insert"43
case PrintScreen -> "Print Screen"44
case Pause -> "Pause"45
case Fn -> "fn"46
case ArrowLeft -> "←"47
case ArrowRight -> "→"48
case ArrowUp -> "↑"49
case ArrowDown -> "↓"50
case Delete -> "⌦"51
case Home -> "↖"52
case End -> "↘"53
case PageUp -> "⇞"54
case PageDown -> "⇟"55
case Help -> "Help"56
case ContextMenu -> "Context Menu"57
case F1 -> "F1"58
case F2 -> "F2"59
case F3 -> "F3"60
case F4 -> "F4"61
case F5 -> "F5"62
case F6 -> "F6"63
case F7 -> "F7"64
case F8 -> "F8"65
case F9 -> "F9"66
case F10 -> "F10"67
case F11 -> "F11"68
case F12 -> "F12"69
case F13 -> "F13"70
case F14 -> "F14"71
case F15 -> "F15"72
case F16 -> "F16"73
case F17 -> "F17"74
case F18 -> "F18"75
case F19 -> "F19"76
case F20 -> "F20"77
case Clear -> "⌧"78
case AudioVolumeUp -> "Audio Volume Up"79
case AudioVolumeDown -> "Audio Volume Down"80
case AudioVolumeMute -> "Audio Volume Mute"81
case Eisu -> "Eisu"82
case Kana -> "Kana"83
}85
internal fun platformPrimaryModifier(): PrimaryModifier = PrimaryModifier.Super