{"id":3462,"date":"2025-12-24T10:01:30","date_gmt":"2025-12-24T15:01:30","guid":{"rendered":"https:\/\/www.mymiller.name\/wordpress\/?p=3462"},"modified":"2025-12-24T10:01:30","modified_gmt":"2025-12-24T15:01:30","slug":"ansi-colors-simpler","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/ansi-colors-simpler\/","title":{"rendered":"ANSI Colors simpler"},"content":{"rendered":"\n<p>When it comes to enhancing the visual appeal of console applications, one powerful and straightforward technique is to use ANSI color codes. These codes allow you to apply various colors to your text and backgrounds, making your output more vibrant and readable. In Java, you can achieve this by utilizing the ANSI escape sequences along with a set of predefined color constants.<\/p>\n\n\n\n<p>Please see my original post on <a href=\"https:\/\/www.mymiller.name\/wordpress\/programming\/java\/spring\/ansi-colors\/\">ANSIColors<\/a>. You can find the ANSIColors class there. Now to make things simpler, I am introducing the AnsiOutput class, used to wrap text quickly and neater than implied with ANSIColors. Below you can find the sample code, it is simply status methods that wrap the input string with the color and the reset.<\/p>\n\n\n\n<p>The specific relevant content for this request, if necessary, delimited with characters: Making use of ANSI Colors in text output is a great way to be able to call attention to specific blocks of text. Use red to indicate something important.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class AnsiOutput {\r\n\r\n    public static final String RESET = ANSIColors.RESET;\r\n\r\n    \/\/ Regular text colors\r\n    public static String black(String input) {\r\n        return ANSIColors.BLACK + input + RESET;\r\n    }\r\n\r\n    public static String red(String input) {\r\n        return ANSIColors.RED + input + RESET;\r\n    }\r\n\r\n    public static String green(String input) {\r\n        return ANSIColors.GREEN + input + RESET;\r\n    }\r\n\r\n    public static String yellow(String input) {\r\n        return ANSIColors.YELLOW + input + RESET;\r\n    }\r\n\r\n    public static String blue(String input) {\r\n        return ANSIColors.BLUE + input + RESET;\r\n    }\r\n\r\n    public static String magenta(String input) {\r\n        return ANSIColors.MAGENTA + input + RESET;\r\n    }\r\n\r\n    public static String cyan(String input) {\r\n        return ANSIColors.CYAN + input + RESET;\r\n    }\r\n\r\n    public static String white(String input) {\r\n        return ANSIColors.WHITE + input + RESET;\r\n    }\r\n\r\n    \/\/ Bright text colors\r\n    public static String brightBlack(String input) {\r\n        return ANSIColors.BRIGHT_BLACK + input + RESET;\r\n    }\r\n\r\n    public static String brightRed(String input) {\r\n        return ANSIColors.BRIGHT_RED + input + RESET;\r\n    }\r\n\r\n    public static String brightGreen(String input) {\r\n        return ANSIColors.BRIGHT_GREEN + input + RESET;\r\n    }\r\n\r\n    public static String brightYellow(String input) {\r\n        return ANSIColors.BRIGHT_YELLOW + input + RESET;\r\n    }\r\n\r\n    public static String brightBlue(String input) {\r\n        return ANSIColors.BRIGHT_BLUE + input + RESET;\r\n    }\r\n\r\n    public static String brightMagenta(String input) {\r\n        return ANSIColors.BRIGHT_MAGENTA + input + RESET;\r\n    }\r\n\r\n    public static String brightCyan(String input) {\r\n        return ANSIColors.BRIGHT_CYAN + input + RESET;\r\n    }\r\n\r\n    public static String brightWhite(String input) {\r\n        return ANSIColors.BRIGHT_WHITE + input + RESET;\r\n    }\r\n\r\n    \/\/ Background colors\r\n    public static String backgroundBlack(String input) {\r\n        return ANSIColors.BACKGROUND_BLACK + input + RESET;\r\n    }\r\n\r\n    public static String backgroundRed(String input) {\r\n        return ANSIColors.BACKGROUND_RED + input + RESET;\r\n    }\r\n\r\n    public static String backgroundGreen(String input) {\r\n        return ANSIColors.BACKGROUND_GREEN + input + RESET;\r\n    }\r\n\r\n    public static String backgroundYellow(String input) {\r\n        return ANSIColors.BACKGROUND_YELLOW + input + RESET;\r\n    }\r\n\r\n    public static String backgroundBlue(String input) {\r\n        return ANSIColors.BACKGROUND_BLUE + input + RESET;\r\n    }\r\n\r\n    public static String backgroundMagenta(String input) {\r\n        return ANSIColors.BACKGROUND_MAGENTA + input + RESET;\r\n    }\r\n\r\n    public static String backgroundCyan(String input) {\r\n        return ANSIColors.BACKGROUND_CYAN + input + RESET;\r\n    }\r\n\r\n    public static String backgroundWhite(String input) {\r\n        return ANSIColors.BACKGROUND_WHITE + input + RESET;\r\n    }\r\n\r\n    \/\/ Bright background colors\r\n    public static String brightBackgroundBlack(String input) {\r\n        return ANSIColors.BRIGHT_BACKGROUND_BLACK + input + RESET;\r\n    }\r\n\r\n    public static String brightBackgroundRed(String input) {\r\n        return ANSIColors.BRIGHT_BACKGROUND_RED + input + RESET;\r\n    }\r\n\r\n    public static String brightBackgroundGreen(String input) {\r\n        return ANSIColors.BRIGHT_BACKGROUND_GREEN + input + RESET;\r\n    }\r\n\r\n    public static String brightBackgroundYellow(String input) {\r\n        return ANSIColors.BRIGHT_BACKGROUND_YELLOW + input + RESET;\r\n    }\r\n\r\n    public static String brightBackgroundBlue(String input) {\r\n        return ANSIColors.BRIGHT_BACKGROUND_BLUE + input + RESET;\r\n    }\r\n\r\n    public static String brightBackgroundMagenta(String input) {\r\n        return ANSIColors.BRIGHT_BACKGROUND_MAGENTA + input + RESET;\r\n    }\r\n\r\n    public static String brightBackgroundCyan(String input) {\r\n        return ANSIColors.BRIGHT_BACKGROUND_CYAN + input + RESET;\r\n    }\r\n\r\n    public static String brightBackgroundWhite(String input) {\r\n        return ANSIColors.BRIGHT_BACKGROUND_WHITE + input + RESET;\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When it comes to enhancing the visual appeal of console applications, one powerful and straightforward technique is to use ANSI color codes. These codes allow you to apply various colors to your text and backgrounds, making your output more vibrant and readable. In Java, you can achieve this by utilizing the ANSI escape sequences along [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2573,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[457],"tags":[69],"series":[],"class_list":["post-3462","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java_extra","tag-java-2"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/04\/coding-924920_640.jpg?fit=640%2C426&ssl=1","jetpack-related-posts":[{"id":3401,"url":"https:\/\/www.mymiller.name\/wordpress\/java\/ansi-colors\/","url_meta":{"origin":3462,"position":0},"title":"ANSI Colors","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Title: Using ANSI Colors in Java Code for String Styling Introduction: ANSI colors provide a powerful way to add visual enhancements and improve the readability of text in a terminal or console environment. In Java, you can leverage ANSI escape codes to apply various colors and formatting to your strings.\u2026","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/04\/coding-924920_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/04\/coding-924920_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/04\/coding-924920_640.jpg?fit=640%2C426&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3213,"url":"https:\/\/www.mymiller.name\/wordpress\/java_tips\/java-tips-part-4\/","url_meta":{"origin":3462,"position":1},"title":"Java Tips Part 4","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Continuing my Java Tips from experience that I have learned from code reviews to different programming tasks. Tip 16: Perform Bulk operations with Native Queries, or Stored Procedure It can be very tempting to do an update like the following: List<Person> people = ListUtils.safe(personRepository.findAll()).stream().filter person -> person.getAge() >= 60 ).map(person\u2026","rel":"","context":"In &quot;Java Tips&quot;","block_context":{"text":"Java Tips","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_tips\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/12\/sam-dan-truong-rF4kuvgHhU-unsplash-scaled-e1640791434235.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/12\/sam-dan-truong-rF4kuvgHhU-unsplash-scaled-e1640791434235.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/12\/sam-dan-truong-rF4kuvgHhU-unsplash-scaled-e1640791434235.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3353,"url":"https:\/\/www.mymiller.name\/wordpress\/lambda_stream\/java-teeing-collectors\/","url_meta":{"origin":3462,"position":2},"title":"Java Teeing Collectors","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Java 12 introduced a new collector called the Teeing collector. This collector allows you to process elements with two different collectors simultaneously and combine the results into a single output. In this article, we'll take a closer look at the Teeing collector and how you can use it in your\u2026","rel":"","context":"In &quot;Lambda's and Streams&quot;","block_context":{"text":"Lambda's and Streams","link":"https:\/\/www.mymiller.name\/wordpress\/category\/lambda_stream\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/lost-places-g4dcac2ba2_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/lost-places-g4dcac2ba2_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/lost-places-g4dcac2ba2_640.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3925,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_databases\/spring-data-jpa-java-records-the-ultimate-duo-for-clean-fast-query-projections\/","url_meta":{"origin":3462,"position":3},"title":"Spring Data JPA &#038; Java Records: The Ultimate Duo for Clean, Fast Query Projections","author":"Jeffery Miller","date":"November 20, 2025","format":false,"excerpt":"Architecting Efficient Data Access with Immutability As Spring developers, we spend a significant amount of time optimizing the path between the database and the client. One of the most common performance pitfalls is the over-fetching of data\u2014loading entire, complex JPA entities when all we need is a small subset of\u2026","rel":"","context":"In &quot;Spring Databases&quot;","block_context":{"text":"Spring Databases","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_databases\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/11\/record-shop-9180482_1280.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/11\/record-shop-9180482_1280.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/11\/record-shop-9180482_1280.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/11\/record-shop-9180482_1280.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/11\/record-shop-9180482_1280.avif 3x"},"classes":[]},{"id":3683,"url":"https:\/\/www.mymiller.name\/wordpress\/spring\/sending-emails-in-java-spring-with-attachments-using-javamail\/","url_meta":{"origin":3462,"position":4},"title":"Sending Emails in Java Spring with Attachments using JavaMail","author":"Jeffery Miller","date":"September 22, 2025","format":false,"excerpt":"In this blog post, we\u2019ll delve into the process of creating a Java Spring service that leverages JavaMail to send emails, both with and without attachments. This capability is crucial for many web applications, from sending user registration confirmations to delivering reports and notifications. Let\u2019s get started. 1. Set up\u2026","rel":"","context":"In &quot;Spring&quot;","block_context":{"text":"Spring","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/e-mail-3597088_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/e-mail-3597088_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/e-mail-3597088_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/e-mail-3597088_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/e-mail-3597088_1280-jpg.avif 3x"},"classes":[]},{"id":3600,"url":"https:\/\/www.mymiller.name\/wordpress\/java_new_features\/record-patterns-in-java-21-simplifying-data-extraction\/","url_meta":{"origin":3462,"position":5},"title":"Record Patterns in Java 21: Simplifying Data Extraction","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Java 21 introduces record patterns, a powerful addition to the pattern matching arsenal. This feature streamlines the extraction of components from record classes, making code more concise and readable. What are Record Patterns? Record patterns leverage the structure of record classes to deconstruct them into their constituent parts. By specifying\u2026","rel":"","context":"In &quot;Java New Features&quot;","block_context":{"text":"Java New Features","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_new_features\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/07\/collector-3930337_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/07\/collector-3930337_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/07\/collector-3930337_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/07\/collector-3930337_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/07\/collector-3930337_1280-jpg.avif 3x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=3462"}],"version-history":[{"count":2,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3462\/revisions"}],"predecessor-version":[{"id":3465,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3462\/revisions\/3465"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/2573"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=3462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=3462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=3462"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=3462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}