Skip to content

Commit a2216b8

Browse files
committed
Add an custom object to perform my problem
Update build.gradle to 1.1.0
1 parent 86eaa3f commit a2216b8

File tree

6 files changed

+86
-20
lines changed

6 files changed

+86
-20
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'de.mint.consoleline'
8-
version '1.0.9'
8+
version '1.1.0'
99

1010
java {
1111
toolchain {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package de.mint.consoleline.Format;
2+
3+
public class CustomColors {
4+
5+
public static final String RESET = "\u001B[0m";
6+
public static final String GRAY = "\u001B[90m";
7+
public static final String GREEN = "\u001B[92m";
8+
public static final String YELLOW = "\u001B[93m";
9+
public static final String RED = "\u001B[91m";
10+
public static final String CYAN = "\u001B[96m";
11+
12+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package de.mint.consoleline.Format;
2+
3+
import java.text.SimpleDateFormat;
4+
import java.util.Date;
5+
6+
public class CustomFormat {
7+
8+
private String stringFormat;
9+
10+
private CustomColors previewColor;
11+
12+
private SimpleDateFormat simpleDateFormat;
13+
14+
private String message;
15+
16+
public CustomFormat(
17+
String stringFormat,
18+
CustomColors previewColor,
19+
SimpleDateFormat simpleDateFormat,
20+
String message) {
21+
this.stringFormat = stringFormat;
22+
this.previewColor = previewColor;
23+
this.simpleDateFormat = simpleDateFormat;
24+
this.message = message;
25+
}
26+
27+
public String format() {
28+
this.simpleDateFormat = new SimpleDateFormat();
29+
final String time = simpleDateFormat.format(new Date());
30+
return String.format(
31+
this.stringFormat,
32+
this.previewColor,
33+
time,
34+
CustomColors.YELLOW,
35+
"WARN",
36+
message,
37+
CustomColors.RESET);
38+
}
39+
40+
public String getStringFormat() {
41+
return stringFormat;
42+
}
43+
44+
public CustomColors getPreviewColor() {
45+
return previewColor;
46+
}
47+
48+
public SimpleDateFormat getSimpleDateFormat() {
49+
return simpleDateFormat;
50+
}
51+
52+
public String getMessage() {
53+
return message;
54+
}
55+
}

src/main/java/de/mint/consoleline/event/input/InputRunnable.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.mint.consoleline.event.input;
22

3+
import de.mint.consoleline.Format.CustomFormat;
34
import de.mint.consoleline.command.CommandHandler;
45
import de.mint.consoleline.exception.ConsoleLineException;
56
import de.mint.consoleline.service.JlineUtils;
@@ -21,8 +22,8 @@ public record InputRunnable(
2122
String prompt,
2223
String commandNotAvailable,
2324
String commandArgumentNotAvailable,
24-
String[] commandNotAvailableFormat,
25-
String[] commandArgumentNotAvailableFormat)
25+
CustomFormat commandNotAvailableFormat,
26+
CustomFormat commandArgumentNotAvailableFormat)
2627
implements Runnable {
2728

2829
@Override
@@ -53,9 +54,7 @@ public void run() {
5354
} else {
5455

5556
if (this.commandArgumentNotAvailableFormat() != null) {
56-
final String[] formatData = this.commandArgumentNotAvailableFormat();
57-
final Object[] args = Arrays.copyOfRange(formatData, 1, formatData.length);
58-
System.out.printf((formatData[0]) + "%n", args);
57+
System.out.println(commandArgumentNotAvailableFormat.format());
5958
} else {
6059
if (this.commandArgumentNotAvailable() != null) {
6160
System.out.println(this.commandArgumentNotAvailable());
@@ -65,9 +64,7 @@ public void run() {
6564
} else {
6665

6766
if (this.commandNotAvailableFormat() != null) {
68-
final String[] formatData = this.commandNotAvailableFormat();
69-
final Object[] args = Arrays.copyOfRange(formatData, 1, formatData.length);
70-
System.out.printf((formatData[0]) + "%n", args);
67+
System.out.println(commandNotAvailableFormat.format());
7168
} else {
7269
if (this.commandNotAvailable() != null) {
7370
System.out.println(this.commandNotAvailable());

src/main/java/de/mint/consoleline/service/JlineBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.mint.consoleline.service;
22

3+
import de.mint.consoleline.Format.CustomFormat;
34
import org.jetbrains.annotations.NotNull;
45
import org.jline.reader.Completer;
56
import org.jline.reader.Highlighter;
@@ -113,12 +114,12 @@ public JlineBuilder setScheduleExecutorService(final ScheduledExecutorService sc
113114
}
114115

115116

116-
public JlineBuilder setCommandArgumentNotAvailableFormat(String[] commandArgumentNotAvailableFormat) {
117+
public JlineBuilder setCommandArgumentNotAvailableFormat(CustomFormat commandArgumentNotAvailableFormat) {
117118
this.jlineConfiguration.setCommandArgumentNotAvailableFormat(commandArgumentNotAvailableFormat);
118119
return this;
119120
}
120121

121-
public JlineBuilder setCommandNotAvailableFormat(String[] commandNotAvailableFormat) {
122+
public JlineBuilder setCommandNotAvailableFormat(CustomFormat commandNotAvailableFormat) {
122123
this.jlineConfiguration.setCommandNotAvailableFormat(commandNotAvailableFormat);
123124
return this;
124125
}

src/main/java/de/mint/consoleline/service/JlineExecutor.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.mint.consoleline.service;
22

3+
import de.mint.consoleline.Format.CustomFormat;
34
import de.mint.consoleline.command.CommandArguments;
45
import de.mint.consoleline.command.CommandHandler;
56
import de.mint.consoleline.event.error.ErrorPrintStream;
@@ -49,8 +50,8 @@ public class JlineExecutor {
4950

5051
private String prompt;
5152

52-
private String[] commandArgumentNotAvailableFormat;
53-
private String[] commandNotAvailableFormat;
53+
private CustomFormat commandArgumentNotAvailableFormat;
54+
private CustomFormat commandNotAvailableFormat;
5455

5556
private String prefix = null;
5657

@@ -189,19 +190,19 @@ public boolean isJna() {
189190
return this.jna;
190191
}
191192

192-
public String[] getCommandArgumentNotAvailableFormat() {
193-
return this.commandArgumentNotAvailableFormat;
193+
public CustomFormat getCommandArgumentNotAvailableFormat() {
194+
return commandArgumentNotAvailableFormat;
194195
}
195196

196-
void setCommandArgumentNotAvailableFormat(String[] commandArgumentNotAvailableFormat) {
197-
this.commandArgumentNotAvailableFormat = commandArgumentNotAvailableFormat;
197+
public CustomFormat getCommandNotAvailableFormat() {
198+
return commandNotAvailableFormat;
198199
}
199200

200-
public String[] getCommandNotAvailableFormat() {
201-
return commandNotAvailableFormat;
201+
void setCommandArgumentNotAvailableFormat(CustomFormat commandArgumentNotAvailableFormat) {
202+
this.commandArgumentNotAvailableFormat = commandArgumentNotAvailableFormat;
202203
}
203204

204-
public void setCommandNotAvailableFormat(String[] commandNotAvailableFormat) {
205+
void setCommandNotAvailableFormat(CustomFormat commandNotAvailableFormat) {
205206
this.commandNotAvailableFormat = commandNotAvailableFormat;
206207
}
207208

0 commit comments

Comments
 (0)