// Path: sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/autoconfiguration/SshSessionContext.java
// public enum SshSessionContext {
// 
//     ;
// 
//     private static final ThreadLocal<Supplier<File>> USER_DIR_CONTEXT = new ThreadLocal<Supplier<File>>();
//     private static final ThreadLocal<Map<String, Object>> THREAD_CONTEXT = new ThreadLocal<Map<String, Object>>() {
//         @Override
//         protected Map<String, Object> initialValue() {
//             return new HashMap<>();
//         }
//     };
// 
//     public static void put(String key, Object value) {
//         THREAD_CONTEXT.get().put(key, value);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <E> E get(String key) {
//         return (E) THREAD_CONTEXT.get().get(key);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <E> E remove(String key) {
//         return (E) THREAD_CONTEXT.get().remove(key);
//     }
// 
//     public static boolean containsKey(String key) {
//         return THREAD_CONTEXT.get().containsKey(key);
//     }
// 
//     public static boolean isEmpty() {
//         return THREAD_CONTEXT.get().isEmpty();
//     }
// 
//     public static void clear() {
//         THREAD_CONTEXT.remove();
//         USER_DIR_CONTEXT.remove();
//     }
// 
//     public static void setUserDir(Supplier<File> userDirSupplier) {
//         USER_DIR_CONTEXT.set(userDirSupplier);
//     }
// 
//     public static File getUserDir() {
//         return USER_DIR_CONTEXT.get().get();
//     }
// }
// 
// Path: sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/util/JsonUtils.java
// @lombok.extern.slf4j.Slf4j
// public enum JsonUtils {
//     ;
//     
//     private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().findAndRegisterModules();
//     private static final ObjectWriter WRITER = OBJECT_MAPPER.writer().withDefaultPrettyPrinter();
//     
//     public static String asJson(Object object) {
//         try {
//             return WRITER.writeValueAsString(object);
//         } catch (JsonProcessingException ex) {
//             log.error("Error processing json output", ex);
//             return "Error processing json output: " + ex.getMessage();
//         }
//     }
// 
//     public static <E> E stringToObject(String json, Class<E> clazz) throws IOException {
//         return OBJECT_MAPPER.readValue(json, clazz);
//     }
// }


import java.io.IOException;
import java.util.Objects;
import org.jline.reader.LineReader;
import org.jline.terminal.Terminal;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;
import sshd.shell.springboot.autoconfiguration.SshSessionContext;
import sshd.shell.springboot.util.JsonUtils;
     * @param output Text output
     */
    public static void writeOutput(String output) {
        writeOutput(output, null);
    }

    /**
     * Write highlighted output.
     *
     * @param output Text output
     * @param textToHighlight text to highlight
     */
    public static void writeOutput(String output, String textToHighlight) {
        Terminal terminal = SshSessionContext.<Terminal>get(TERMINAL);
        AttributedStringBuilder builder = new AttributedStringBuilder()
                .style(SshSessionContext.<AttributedStyle>get(TEXT_STYLE));
        if (Objects.isNull(textToHighlight)) {
            builder.append(output);
        } else {
            addHighlightedTextToBuilder(output, textToHighlight, builder);
        }
        terminal.writer().println(builder.style(AttributedStyle.DEFAULT).toAnsi(terminal));
        terminal.flush();
    }

    private static void addHighlightedTextToBuilder(String output, String textToHighlight,
            AttributedStringBuilder builder) {
        String[] split = output.split(textToHighlight);
        for (int i = 0; i < split.length - 1; i++) {
            builder.append(split[i])
// Path: sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/autoconfiguration/SshSessionContext.java
// public enum SshSessionContext {
// 
//     ;
// 
//     private static final ThreadLocal<Supplier<File>> USER_DIR_CONTEXT = new ThreadLocal<Supplier<File>>();
//     private static final ThreadLocal<Map<String, Object>> THREAD_CONTEXT = new ThreadLocal<Map<String, Object>>() {
//         @Override
//         protected Map<String, Object> initialValue() {
//             return new HashMap<>();
//         }
//     };
// 
//     public static void put(String key, Object value) {
//         THREAD_CONTEXT.get().put(key, value);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <E> E get(String key) {
//         return (E) THREAD_CONTEXT.get().get(key);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <E> E remove(String key) {
//         return (E) THREAD_CONTEXT.get().remove(key);
//     }
// 
//     public static boolean containsKey(String key) {
//         return THREAD_CONTEXT.get().containsKey(key);
//     }
// 
//     public static boolean isEmpty() {
//         return THREAD_CONTEXT.get().isEmpty();
//     }
// 
//     public static void clear() {
//         THREAD_CONTEXT.remove();
//         USER_DIR_CONTEXT.remove();
//     }
// 
//     public static void setUserDir(Supplier<File> userDirSupplier) {
//         USER_DIR_CONTEXT.set(userDirSupplier);
//     }
// 
//     public static File getUserDir() {
//         return USER_DIR_CONTEXT.get().get();
//     }
// }
// 
// Path: sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/util/JsonUtils.java
// @lombok.extern.slf4j.Slf4j
// public enum JsonUtils {
//     ;
//     
//     private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().findAndRegisterModules();
//     private static final ObjectWriter WRITER = OBJECT_MAPPER.writer().withDefaultPrettyPrinter();
//     
//     public static String asJson(Object object) {
//         try {
//             return WRITER.writeValueAsString(object);
//         } catch (JsonProcessingException ex) {
//             log.error("Error processing json output", ex);
//             return "Error processing json output: " + ex.getMessage();
//         }
//     }
// 
//     public static <E> E stringToObject(String json, Class<E> clazz) throws IOException {
//         return OBJECT_MAPPER.readValue(json, clazz);
//     }
// }


// Path: sshd-shell-spring-boot-starter/src/main/java/sshd/shell/springboot/console/ConsoleIO.java
import java.io.IOException;
import java.util.Objects;
import org.jline.reader.LineReader;
import org.jline.terminal.Terminal;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;
import sshd.shell.springboot.autoconfiguration.SshSessionContext;
import sshd.shell.springboot.util.JsonUtils;

     * @param output Text output
     */
    public static void writeOutput(String output) {
        writeOutput(output, null);
    }

    /**
     * Write highlighted output.
     *
     * @param output Text output
     * @param textToHighlight text to highlight
     */
    public static void writeOutput(String output, String textToHighlight) {
        Terminal terminal = SshSessionContext.<Terminal>get(TERMINAL);
        AttributedStringBuilder builder = new AttributedStringBuilder()
                .style(SshSessionContext.<AttributedStyle>get(TEXT_STYLE));
        if (Objects.isNull(textToHighlight)) {
            builder.append(output);
        } else {
            addHighlightedTextToBuilder(output, textToHighlight, builder);
        }
        terminal.writer().println(builder.style(AttributedStyle.DEFAULT).toAnsi(terminal));
        terminal.flush();
    }

    private static void addHighlightedTextToBuilder(String output, String textToHighlight,
            AttributedStringBuilder builder) {
        String[] split = output.split(textToHighlight);
        for (int i = 0; i < split.length - 1; i++) {
            builder.append(split[i])
                    .style(SshSessionContext.<AttributedStyle>get(HIGHLIGHT_COLOR))