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

Feature - AnsiComponentSerializer #140

Closed
wants to merge 15 commits into from
Closed
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
3 changes: 2 additions & 1 deletion bom/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ dependencies {
"serializer-configurate4",
"text-serializer-gson",
"text-serializer-legacy",
"text-serializer-plain"
"text-serializer-plain",
"text-serializer-ansi"
].each {
api(project(":adventure-$it"))
}
Expand Down
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include "text-serializer-gson"
include "text-serializer-gson-legacy-impl"
include "text-serializer-legacy"
include "text-serializer-plain"
include "text-serializer-ansi"

[
"api",
Expand All @@ -25,7 +26,8 @@ include "text-serializer-plain"
"text-serializer-gson",
"text-serializer-gson-legacy-impl",
"text-serializer-legacy",
"text-serializer-plain"
"text-serializer-plain",
"text-serializer-ansi"
].each {
findProject(":$it")?.name = "adventure-$it"
}
11 changes: 11 additions & 0 deletions text-serializer-ansi/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dependencies {
api(project(":adventure-api"))
implementation('org.fusesource.jansi:jansi:1.18')

}

jar {
manifest.attributes(
'Automatic-Module-Name': 'net.kyori.adventure.text.serializer.ansi'
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* This file is part of adventure, licensed under the MIT License.
*
* Copyright (c) 2017-2021 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.text.serializer.ansi;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.ComponentSerializer;
import net.kyori.adventure.util.Buildable;
import org.checkerframework.checker.nullness.qual.NonNull;

/**
* An Ansi component serializer.
*
* <p>Use {@link Builder#downsampleColors(boolean)} to support consoles that cannot render
* 256 colors.</p>
*
* @since 4.0.0
*/
public interface ANSIComponentSerializer extends ComponentSerializer<Component, Component, String>, Buildable<ANSIComponentSerializer, ANSIComponentSerializer.Builder> {
Narimm marked this conversation as resolved.
Show resolved Hide resolved
char ESCAPE_CHAR = '\u001B';

/**
* This AnsiComponentSerializer produces full colour RGB codes and supports True colour terminals. Otherwise colours are down sampled to the nearest Named Colour.
*
* @return {@link ANSIComponentSerializer}
* @since 4.0.0
*/
static @NonNull ANSIComponentSerializer fullColour() {
return ANSIComponentSerializerImpl.TRUE_COLOR;
}

/**
* Creates a new {@link ANSIComponentSerializer.Builder}.
*
* @return a builder
* @since 4.0.0
*/
static @NonNull Builder builder() {
return new ANSIComponentSerializerImpl.BuilderImpl();
}

/**
* A builder for {@link ANSIComponentSerializer}.
*
* @since 4.0.0
*/
interface Builder extends Buildable.Builder<ANSIComponentSerializer> {

/**
* Sets that the serializer should down sample hex colors to named colors.
*
* @param downSample if true down sample the colour.
* @return this builder
*/
@NonNull Builder downsampleColors(final boolean downSample);

/**
* Creates a new {@link ANSIComponentSerializer.Builder}.
*
* @return a builder
*/
@Override
@NonNull ANSIComponentSerializer build();
}
}
Loading