FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Strongbox/StrongBox/ColoredStringHelper.m at master · MacPass/Strongbox · GitHub
MacPass
/
Strongbox
Public
forked from
strongbox-password-safe/Strongbox
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Strongbox
/
StrongBox
/
ColoredStringHelper.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
194 lines (152 loc) · 6.31 KB
Breadcrumbs
Strongbox
/
StrongBox
/
ColoredStringHelper.m
Copy path
File metadata and controls
194 lines (152 loc) · 6.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
//
ColoredStringHelper.m
//
Strongbox
//
//
Created by Mark on 02/03/2020.
//
Copyright © 2014-2021 Mark McGuill. All rights reserved.
//
#
import
"
ColoredStringHelper.h
"
#
import
"
Utils.h
"
typedef
NS_ENUM
(
unsigned
int
, CharacterType) {
kUnknown
,
kCharacterTypeNumber
,
kCharacterTypeUpperLetter
,
kCharacterTypeLowerLetter
,
kCharacterTypeSymbol
,
};
typedef
struct
_Palette {
COLOR_PTR
numberColor;
COLOR_PTR
symbolColor;
COLOR_PTR
upperLetterColor;
COLOR_PTR
lowerLetterColor;
} Palette;
static
Palette light;
static
Palette dark;
static
Palette lightColorBlind;
static
Palette darkColorBlind;
static
COLOR_PTR
defaultNonColorizedColor;
@implementation
ColoredStringHelper
+ (
void
)
initialize
{
if
(self == [ColoredStringHelper
class
]) {
lightColorBlind.
numberColor
=
ColorFromRGB
(
0xCC79A7
);
lightColorBlind.
symbolColor
=
ColorFromRGB
(
0x0072B2
);
lightColorBlind.
upperLetterColor
=
ColorFromRGB
(
0x009E63
);
lightColorBlind.
lowerLetterColor
=
ColorFromRGB
(
0x000000
);
darkColorBlind.
numberColor
=
ColorFromRGB
(
0xD55E00
);
darkColorBlind.
symbolColor
=
ColorFromRGB
(
0x56B4E9
);
darkColorBlind.
upperLetterColor
=
ColorFromRGB
(
0xF0E442
);
darkColorBlind.
lowerLetterColor
=
ColorFromRGB
(
0x009E63
);
#
if
TARGET_OS_IPHONE
light.
numberColor
= UIColor.
systemBlueColor
;
light.
symbolColor
= UIColor.
systemPinkColor
;
light.
upperLetterColor
= UIColor.
systemGreenColor
;
dark.
numberColor
= UIColor.
systemBlueColor
;
dark.
symbolColor
= UIColor.
systemYellowColor
;
dark.
upperLetterColor
= UIColor.
systemGreenColor
;
if
(@
available
(iOS
13.0
, *)) {
dark.
lowerLetterColor
= UIColor.
labelColor
;
light.
lowerLetterColor
= UIColor.
labelColor
;
}
else
{
dark.
lowerLetterColor
= UIColor.
darkTextColor
;
light.
lowerLetterColor
= UIColor.
darkTextColor
;
}
#
else
dark.
numberColor
=
NSColor
.
systemBlueColor
;
dark.
symbolColor
=
NSColor
.
systemYellowColor
;
dark.
upperLetterColor
=
NSColor
.
systemGreenColor
;
dark.
lowerLetterColor
=
NSColor
.
labelColor
;
light.
numberColor
=
NSColor
.
systemBlueColor
;
light.
symbolColor
=
NSColor
.
systemPinkColor
;
light.
upperLetterColor
=
NSColor
.
systemGreenColor
;
light.
lowerLetterColor
=
NSColor
.
labelColor
;
#
endif
#
if
TARGET_OS_IPHONE
if
(@
available
(iOS
13.0
, *)) {
defaultNonColorizedColor = UIColor.
labelColor
;
}
else
{
defaultNonColorizedColor = UIColor.
darkTextColor
;
}
#
else
defaultNonColorizedColor =
NSColor
.
labelColor
;
#
endif
}
}
+ (
NSAttributedString
*)
getColorizedAttributedString
:
(
NSString
*)
password
colorize
:
(
BOOL
)
colorize
darkMode
:
(
BOOL
)
darkMode
colorBlind
:
(
BOOL
)
colorBlind
font
:
(
FONT_PTR
)
font
{
NSMutableAttributedString
* ret = [[
NSMutableAttributedString
alloc
]
initWithString:
@"
"
];
Palette *palette = darkMode ? (colorBlind ? &darkColorBlind : &dark ) : (colorBlind ? &lightColorBlind : &light);
[ret
beginEditing
];
NSArray
<
NSString
*>* characters = [ColoredStringHelper
getStringCharacters:
password];
for
(
NSString
* character in characters) {
CharacterType type = [ColoredStringHelper
getCharacterType:
character];
NSDictionary
*attrs = [ColoredStringHelper
getAttributesForCharacterType:
type
colorize:
colorize
palette:
palette
font:
font];
NSAttributedString
*attr = [[
NSAttributedString
alloc
]
initWithString:
character
attributes:
attrs];
[ret
appendAttributedString:
attr];
}
[ret
endEditing
];
return
ret.
copy
;
}
+ (
NSDictionary
*)
getAttributesForCharacterType
:
(CharacterType)
type
colorize
:
(
BOOL
)
colorize
palette
:
(Palette*)
palette
font
:
(
FONT_PTR
)
font
{
NSMutableDictionary
* ret = [
NSMutableDictionary
dictionaryWithDictionary:
@{
NSForegroundColorAttributeName
: colorize ? [ColoredStringHelper
getColorForCharacterType:
type
palette:
palette] : defaultNonColorizedColor,
NSKernAttributeName
: @(
1.4
)
}];
if
( font ) {
ret[
NSFontAttributeName
] = font;
}
return
ret;
}
+ (
COLOR_PTR
)
getColorForCharacterType
:
(CharacterType)
type
palette
:
(Palette*)
palette
{
if
(type ==
kCharacterTypeNumber
) {
return
palette->
numberColor
;
}
else
if
(type ==
kCharacterTypeSymbol
) {
return
palette->
symbolColor
;
}
else
if
(type ==
kCharacterTypeUpperLetter
) {
return
palette->
upperLetterColor
;
}
else
{
return
palette->
lowerLetterColor
;
}
}
+ (CharacterType)
getCharacterType
:
(
NSString
*)
character
{
NSCharacterSet
*inStringSet = [
NSCharacterSet
characterSetWithCharactersInString:
character];
if
([
NSCharacterSet
.decimalDigitCharacterSet
isSupersetOfSet:
inStringSet]) {
return
kCharacterTypeNumber
;
}
else
if
([
NSCharacterSet
.lowercaseLetterCharacterSet
isSupersetOfSet:
inStringSet]) {
return
kCharacterTypeLowerLetter
;
}
else
if
([
NSCharacterSet
.uppercaseLetterCharacterSet
isSupersetOfSet:
inStringSet]) {
return
kCharacterTypeUpperLetter
;
}
else
{
return
kCharacterTypeSymbol
;
}
}
+ (
NSArray
<NSString*>*)
getStringCharacters
:
(
NSString
*)
composite
{
if
(!composite.
length
) {
return
@[];
}
NSMutableArray
*chars = [
NSMutableArray
array
];
[composite
enumerateSubstringsInRange:
NSMakeRange
(
0
, composite.length)
options:
NSStringEnumerationByComposedCharacterSequences
usingBlock:
^(
NSString
*inSubstring,
NSRange
inSubstringRange,
NSRange
inEnclosingRange,
BOOL
*outStop) {
[chars
addObject:
inSubstring];
}];
return
chars.
copy
;
}
@end
Back
|
FazBrowse Home
|
New Git URL