52938
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2017, the original author or authors.
|
|
3 |
*
|
|
4 |
* This software is distributable under the BSD license. See the terms of the
|
|
5 |
* BSD license in the documentation provided with this software.
|
|
6 |
*
|
58903
|
7 |
* https://opensource.org/licenses/BSD-3-Clause
|
52938
|
8 |
*/
|
|
9 |
package jdk.internal.org.jline.reader.impl;
|
|
10 |
|
|
11 |
import jdk.internal.org.jline.reader.MaskingCallback;
|
|
12 |
|
|
13 |
import java.util.Objects;
|
|
14 |
|
|
15 |
/**
|
|
16 |
* Simple {@link MaskingCallback} that will replace all the characters in the line with the given mask.
|
|
17 |
* If the given mask is equal to {@link LineReaderImpl#NULL_MASK} then the line will be replaced with an empty String.
|
|
18 |
*/
|
|
19 |
public final class SimpleMaskingCallback implements MaskingCallback {
|
|
20 |
private final Character mask;
|
|
21 |
|
|
22 |
public SimpleMaskingCallback(Character mask) {
|
|
23 |
this.mask = Objects.requireNonNull(mask, "mask must be a non null character");
|
|
24 |
}
|
|
25 |
|
|
26 |
@Override
|
|
27 |
public String display(String line) {
|
|
28 |
if (mask.equals(LineReaderImpl.NULL_MASK)) {
|
|
29 |
return "";
|
|
30 |
} else {
|
|
31 |
StringBuilder sb = new StringBuilder(line.length());
|
|
32 |
for (int i = line.length(); i-- > 0;) {
|
|
33 |
sb.append((char) mask);
|
|
34 |
}
|
|
35 |
return sb.toString();
|
|
36 |
}
|
|
37 |
}
|
|
38 |
|
|
39 |
@Override
|
|
40 |
public String history(String line) {
|
|
41 |
return null;
|
|
42 |
}
|
|
43 |
|
|
44 |
}
|