Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-7995] Switch to JLine to provide line editing #1279

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apache-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ under the License.
<artifactId>maven-slf4j-provider</artifactId>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
</dependency>

<!-- DI Runtime -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Copyright (c) 2002-2023, the original author or authors.
All rights reserved.

https://opensource.org/licenses/BSD-3-Clause

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:

Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with
the distribution.

Neither the name of JLine nor the names of its contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @since 4.0.0
* @see MessageBuilderFactory
*/
public interface MessageBuilder {
public interface MessageBuilder extends Appendable {

/**
* Append message content in trace style.
Expand All @@ -36,7 +36,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder trace(Object message);
default MessageBuilder trace(Object message) {
return style(".trace:-bold,f:magenta", message);
}

/**
* Append message content in debug style.
Expand All @@ -46,7 +48,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder debug(Object message);
default MessageBuilder debug(Object message) {
return style(".debug:-bold,f:cyan", message);
}

/**
* Append message content in info style.
Expand All @@ -56,7 +60,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder info(Object message);
default MessageBuilder info(Object message) {
return style(".info:-bold,f:blue", message);
}

/**
* Append message content in warning style.
Expand All @@ -66,7 +72,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder warning(Object message);
default MessageBuilder warning(Object message) {
return style(".warning:-bold,f:yellow", message);
}

/**
* Append message content in error style.
Expand All @@ -76,7 +84,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder error(Object message);
default MessageBuilder error(Object message) {
return style(".error:-bold,f:red", message);
}

/**
* Append message content in success style.
Expand All @@ -86,7 +96,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder success(Object message);
default MessageBuilder success(Object message) {
return style(".success:-bold,f:green", message);
}

/**
* Append message content in failure style.
Expand All @@ -96,7 +108,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder failure(Object message);
default MessageBuilder failure(Object message) {
return style(".failure:-bold,f:red", message);
}

/**
* Append message content in strong style.
Expand All @@ -106,7 +120,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder strong(Object message);
default MessageBuilder strong(Object message) {
return style(".strong:-bold", message);
}

/**
* Append message content in mojo style.
Expand All @@ -116,7 +132,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder mojo(Object message);
default MessageBuilder mojo(Object message) {
return style(".mojo:-f:green", message);
}

/**
* Append message content in project style.
Expand All @@ -126,11 +144,35 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder project(Object message);
default MessageBuilder project(Object message) {
return style(".project:-f:cyan", message);
}

@Nonnull
default MessageBuilder style(String style, Object message) {
return style(style).a(message).resetStyle();
}

MessageBuilder style(String style);

MessageBuilder resetStyle();

//
// message building methods modelled after Ansi methods
//

@Nonnull
@Override
MessageBuilder append(CharSequence cs);

@Nonnull
@Override
MessageBuilder append(CharSequence cs, int start, int end);

@Nonnull
@Override
MessageBuilder append(char c);

/**
* Append content to the message buffer.
*
Expand All @@ -140,7 +182,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder a(char[] value, int offset, int len);
default MessageBuilder a(char[] value, int offset, int len) {
return append(String.valueOf(value, offset, len));
}

/**
* Append content to the message buffer.
Expand All @@ -149,7 +193,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder a(char[] value);
default MessageBuilder a(char[] value) {
return append(String.valueOf(value));
}

/**
* Append content to the message buffer.
Expand All @@ -160,7 +206,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder a(CharSequence value, int start, int end);
default MessageBuilder a(CharSequence value, int start, int end) {
return append(value, start, end);
}

/**
* Append content to the message buffer.
Expand All @@ -169,7 +217,9 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder a(CharSequence value);
default MessageBuilder a(CharSequence value) {
return append(value);
}

/**
* Append content to the message buffer.
Expand All @@ -178,15 +228,19 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder a(Object value);
default MessageBuilder a(Object value) {
return append(String.valueOf(value));
}

/**
* Append newline to the message buffer.
*
* @return the current builder
*/
@Nonnull
MessageBuilder newline();
default MessageBuilder newline() {
return append(System.lineSeparator());
}

/**
* Append formatted content to the buffer.
Expand All @@ -197,20 +251,23 @@ public interface MessageBuilder {
* @return the current builder
*/
@Nonnull
MessageBuilder format(String pattern, Object... args);
default MessageBuilder format(String pattern, Object... args) {
return append(String.format(pattern, args));
}

/**
* Return the built message.
* Set the buffer length.
*
* @return the message
* @param length the new length
* @return the current builder
*/
@Nonnull
String build();
MessageBuilder setLength(int length);

/**
* Set the buffer length.
* Return the built message.
*
* @param length the new length
* @return the message
*/
void setLength(int length);
@Nonnull
String build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,11 @@ public interface MessageBuilderFactory extends Service {
@Nonnull
MessageBuilder builder();

/**
* Creates a new message builder backed by the given string builder.
* @param stringBuilder a string builder
* @return a new message builder
*/
@Nonnull
MessageBuilder builder(@Nonnull StringBuilder stringBuilder);

/**
* Creates a new message builder of the specified size.
* @param size the initial size of the message builder buffer
* @return a new message builder
*/
@Nonnull
default MessageBuilder builder(int size) {
return builder(new StringBuilder(size));
}
MessageBuilder builder(int size);
}
Loading