@@ -1935,3 +1935,247 @@ impl Modifiers {
19351935 * self == ( * current_mods & Self :: SHORTCUTLR )
19361936 }
19371937}
1938+
1939+ const SYM_CONTROL : & str = "⌃" ; //⎈
1940+ const SYM_SHIFT : & str = "⇧" ;
1941+ #[ cfg( target_os = "windows" ) ]
1942+ const SYM_ALT : & str = "⎇" ;
1943+ #[ cfg( target_vendor = "apple" ) ]
1944+ const SYM_ALT : & str = "⌥" ;
1945+ #[ cfg( all( not( target_os = "windows" ) , not( target_vendor = "apple" ) ) ) ]
1946+ const SYM_ALT : & str = "⎇" ;
1947+ #[ cfg( target_os = "windows" ) ]
1948+ const SYM_META : & str = "❖" ;
1949+ #[ cfg( target_vendor = "apple" ) ]
1950+ const SYM_META : & str = "⌘" ;
1951+ #[ cfg( all( not( target_os = "windows" ) , not( target_vendor = "apple" ) ) ) ]
1952+ const SYM_META : & str = "◆" ;
1953+
1954+ use std:: fmt:: { self , Display , Formatter } ;
1955+ impl Display for Modifiers {
1956+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
1957+ if f. alternate ( ) {
1958+ // {:#} "Fixed position" string output so that, e.g.,
1959+ // ⇧ is always the 2nd symbol as " ⇧" or "‹⇧"
1960+ if self . lshift_state ( ) {
1961+ write ! ( f, "‹{SYM_SHIFT}" ) ?;
1962+ if self . rshift_state ( ) {
1963+ write ! ( f, "›" ) ?;
1964+ } else {
1965+ write ! ( f, " " ) ?;
1966+ } ;
1967+ } else if self . rshift_state ( ) {
1968+ write ! ( f, " {SYM_SHIFT}›" ) ?;
1969+ } else if self . shift_state ( ) {
1970+ write ! ( f, " {SYM_SHIFT} " ) ?;
1971+ } else {
1972+ write ! ( f, " " ) ?;
1973+ }
1974+ if self . lcontrol_state ( ) {
1975+ write ! ( f, "‹{SYM_CONTROL}" ) ?;
1976+ if self . rcontrol_state ( ) {
1977+ write ! ( f, "›" ) ?;
1978+ } else {
1979+ write ! ( f, " " ) ?;
1980+ } ;
1981+ } else if self . rcontrol_state ( ) {
1982+ write ! ( f, " {SYM_CONTROL}›" ) ?;
1983+ } else if self . control_state ( ) {
1984+ write ! ( f, " {SYM_CONTROL} " ) ?;
1985+ } else {
1986+ write ! ( f, " " ) ?;
1987+ }
1988+ if self . lmeta_state ( ) {
1989+ write ! ( f, "‹{SYM_META}" ) ?;
1990+ if self . rmeta_state ( ) {
1991+ write ! ( f, "›" ) ?;
1992+ } else {
1993+ write ! ( f, " " ) ?;
1994+ } ;
1995+ } else if self . rmeta_state ( ) {
1996+ write ! ( f, " {SYM_META}›" ) ?;
1997+ } else if self . meta_state ( ) {
1998+ write ! ( f, " {SYM_META} " ) ?;
1999+ } else {
2000+ write ! ( f, " " ) ?;
2001+ }
2002+ if self . lalt_state ( ) {
2003+ write ! ( f, "‹{SYM_ALT}" ) ?;
2004+ if self . ralt_state ( ) {
2005+ write ! ( f, "›" ) ?;
2006+ } else {
2007+ write ! ( f, " " ) ?;
2008+ } ;
2009+ } else if self . ralt_state ( ) {
2010+ write ! ( f, " {SYM_ALT}›" ) ?;
2011+ } else if self . alt_state ( ) {
2012+ write ! ( f, " {SYM_ALT} " ) ?;
2013+ } else {
2014+ write ! ( f, " " ) ?;
2015+ }
2016+ if self . lalt_graph_state ( ) {
2017+ write ! ( f, "‹{SYM_ALT}Gr" ) ?;
2018+ if self . ralt_graph_state ( ) {
2019+ write ! ( f, "›" ) ?;
2020+ } else {
2021+ write ! ( f, " " ) ?;
2022+ } ;
2023+ } else if self . ralt_graph_state ( ) {
2024+ write ! ( f, " {SYM_ALT}Gr›" ) ?;
2025+ } else if self . alt_graph_state ( ) {
2026+ write ! ( f, " {SYM_ALT}Gr " ) ?;
2027+ } else {
2028+ write ! ( f, " " ) ?;
2029+ }
2030+
2031+ if self . caps_lock_state ( ) {
2032+ write ! ( f, "⇪" ) ?;
2033+ } else {
2034+ write ! ( f, " " ) ?;
2035+ }
2036+ if self . num_lock_state ( ) {
2037+ write ! ( f, "⇭" ) ?;
2038+ } else {
2039+ write ! ( f, " " ) ?;
2040+ }
2041+ if self . scroll_lock_state ( ) {
2042+ write ! ( f, "⇳🔒" ) ?;
2043+ } else {
2044+ write ! ( f, " " ) ?;
2045+ }
2046+
2047+ if self . fn_state ( ) {
2048+ write ! ( f, "ƒ" ) ?;
2049+ } else {
2050+ write ! ( f, " " ) ?;
2051+ }
2052+ if self . fn_lock_state ( ) {
2053+ write ! ( f, "ƒ🔒" ) ?;
2054+ } else {
2055+ write ! ( f, " " ) ?;
2056+ }
2057+ if self . kana_lock_state ( ) {
2058+ write ! ( f, "カナ🔒" ) ?;
2059+ } else {
2060+ write ! ( f, " " ) ?;
2061+ }
2062+
2063+ if self . loya_state ( ) {
2064+ write ! ( f, "‹👍" ) ?;
2065+ if self . roya_state ( ) {
2066+ write ! ( f, "›" ) ?;
2067+ } else {
2068+ write ! ( f, " " ) ?;
2069+ } ;
2070+ } else if self . roya_state ( ) {
2071+ write ! ( f, " 👍›" ) ?;
2072+ } else if self . oya_state ( ) {
2073+ write ! ( f, " 👍 " ) ?;
2074+ } else {
2075+ write ! ( f, " " ) ?;
2076+ }
2077+
2078+ if self . symbol_state ( ) {
2079+ write ! ( f, "🔣" ) ?;
2080+ } else {
2081+ write ! ( f, " " ) ?;
2082+ }
2083+ if self . symbol_lock_state ( ) {
2084+ write ! ( f, "🔣🔒" ) ?;
2085+ } else {
2086+ write ! ( f, " " ) ?;
2087+ }
2088+ } else {
2089+ // {} "Flexible position" string output, no extra space separators
2090+ if self . lshift_state ( ) {
2091+ write ! ( f, "‹{SYM_SHIFT}" ) ?;
2092+ if self . rshift_state ( ) {
2093+ write ! ( f, "›" ) ?;
2094+ } ;
2095+ } else if self . rshift_state ( ) {
2096+ write ! ( f, "{SYM_SHIFT}›" ) ?;
2097+ } else if self . shift_state ( ) {
2098+ write ! ( f, "{SYM_SHIFT}" ) ?;
2099+ }
2100+ if self . lcontrol_state ( ) {
2101+ write ! ( f, "‹{SYM_CONTROL}" ) ?;
2102+ if self . rcontrol_state ( ) {
2103+ write ! ( f, "›" ) ?;
2104+ } ;
2105+ } else if self . rcontrol_state ( ) {
2106+ write ! ( f, "{SYM_CONTROL}›" ) ?;
2107+ } else if self . control_state ( ) {
2108+ write ! ( f, "{SYM_CONTROL}" ) ?;
2109+ }
2110+ if self . lmeta_state ( ) {
2111+ write ! ( f, "‹{SYM_META}" ) ?;
2112+ if self . rmeta_state ( ) {
2113+ write ! ( f, "›" ) ?;
2114+ } ;
2115+ } else if self . rmeta_state ( ) {
2116+ write ! ( f, "{SYM_META}›" ) ?;
2117+ } else if self . meta_state ( ) {
2118+ write ! ( f, "{SYM_META}" ) ?;
2119+ }
2120+ if self . lalt_state ( ) {
2121+ write ! ( f, "‹{SYM_ALT}" ) ?;
2122+ if self . ralt_state ( ) {
2123+ write ! ( f, "›" ) ?;
2124+ } ;
2125+ } else if self . ralt_state ( ) {
2126+ write ! ( f, "{SYM_ALT}›" ) ?;
2127+ } else if self . alt_state ( ) {
2128+ write ! ( f, "{SYM_ALT}" ) ?;
2129+ }
2130+ if self . lalt_graph_state ( ) {
2131+ write ! ( f, "‹{SYM_ALT}Gr" ) ?;
2132+ if self . ralt_graph_state ( ) {
2133+ write ! ( f, "›" ) ?;
2134+ } ;
2135+ } else if self . ralt_graph_state ( ) {
2136+ write ! ( f, "{SYM_ALT}Gr›" ) ?;
2137+ } else if self . alt_graph_state ( ) {
2138+ write ! ( f, "{SYM_ALT}Gr" ) ?;
2139+ }
2140+
2141+ if self . caps_lock_state ( ) {
2142+ write ! ( f, "⇪" ) ?;
2143+ }
2144+ if self . num_lock_state ( ) {
2145+ write ! ( f, "⇭" ) ?;
2146+ }
2147+ if self . scroll_lock_state ( ) {
2148+ write ! ( f, "⇳🔒" ) ?;
2149+ }
2150+
2151+ if self . fn_state ( ) {
2152+ write ! ( f, "ƒ" ) ?;
2153+ }
2154+ if self . fn_lock_state ( ) {
2155+ write ! ( f, "ƒ🔒" ) ?;
2156+ }
2157+ if self . kana_lock_state ( ) {
2158+ write ! ( f, "カナ🔒" ) ?;
2159+ }
2160+
2161+ if self . loya_state ( ) {
2162+ write ! ( f, "‹👍" ) ?;
2163+ if self . roya_state ( ) {
2164+ write ! ( f, "›" ) ?;
2165+ } ;
2166+ } else if self . roya_state ( ) {
2167+ write ! ( f, "👍›" ) ?;
2168+ } else if self . oya_state ( ) {
2169+ write ! ( f, "👍" ) ?;
2170+ }
2171+
2172+ if self . symbol_state ( ) {
2173+ write ! ( f, "🔣" ) ?;
2174+ }
2175+ if self . symbol_lock_state ( ) {
2176+ write ! ( f, "🔣🔒" ) ?;
2177+ }
2178+ }
2179+ Ok ( ( ) )
2180+ }
2181+ }
0 commit comments