diff options
author | H.J <thechairman@thechairman.info> | 2024-10-09 11:35:09 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-10-09 11:35:09 -0400 |
commit | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (patch) | |
tree | 5d990ded3baba51ca3934b51994285f7d5915c34 /aoc2023/build/packages/gleam_community_ansi | |
parent | ef2ad0ee020b6754c230ae08f5979948b8db1350 (diff) | |
download | gleam_aoc-6156a9ef7be4012063a042aafb4e9b0d7eadde8e.tar.gz gleam_aoc-6156a9ef7be4012063a042aafb4e9b0d7eadde8e.zip |
cleanup
Diffstat (limited to 'aoc2023/build/packages/gleam_community_ansi')
6 files changed, 0 insertions, 2864 deletions
diff --git a/aoc2023/build/packages/gleam_community_ansi/LICENCE b/aoc2023/build/packages/gleam_community_ansi/LICENCE deleted file mode 100644 index a84f0ec..0000000 --- a/aoc2023/build/packages/gleam_community_ansi/LICENCE +++ /dev/null @@ -1,190 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - Copyright 2023 Gleam Community Contributors - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License.
\ No newline at end of file diff --git a/aoc2023/build/packages/gleam_community_ansi/README.md b/aoc2023/build/packages/gleam_community_ansi/README.md deleted file mode 100644 index 90ab0d5..0000000 --- a/aoc2023/build/packages/gleam_community_ansi/README.md +++ /dev/null @@ -1,72 +0,0 @@ -# gleam-community/ansi - -Format text with ANSI escape sequences. - -[](https://hex.pm/packages/gleam_community_ansi) -[](https://hexdocs.pm/gleam_community_ansi/) - -✨ This project is written in _pure Gleam_ so you can use it anywhere Gleam runs: -Erlang, Elixir, Node, Deno, even [some browsers](https://bit.ly/devtools-console-ansi-support)! - ---- - -## Quickstart - -```gleam -import gleam/io -import gleam_community/ansi - -pub fn main() { - let greeting = "Hello, " <> ansi.pink("world") <> "!" - - greeting - |> ansi.bg_white - |> io.println -} - -``` - -## Installation - -`gleam_community` packages are published to [hex.pm](https://hex.pm/packages/gleam_community_ansi) -with the prefix `gleam_community_`. You can add them to your Gleam projects directly: - -```sh -gleam add gleam_community_ansi -``` - -The docs can be found over at [hexdocs.pm](https://hexdocs.pm/gleam_community_ansi). - -## ANSI-what? - -ANSI escape sequences date back to the 70s as a standard way to format text on -various video text terminals. Since then they have been adopted by many software -terminal emulators and platforms, including some Web browsers, and are a simple -way to format text without platform-specific APIs. - -The point of this package is to abstract the specific codes away and give you an -easy-to-understand API for formatting and colouring terminal text. Still, here is -a quick couple of examples of what's happening under the hood. - -You can copy these examples straight into your terminal to see them in action! - -- Colour text yellow: - - ```shell - $ echo "\e[33mhello" - ``` - -- Colour the background pink: - - ```shell - $ echo "\e[45mhello" - ``` - -- Render text italic: - - ```shell - $ echo "\e[3mhello\e[23m" - ``` - -As you can see, the escape sequences are a bit obscure. Sure, you could hard code -them, or you could use this package! diff --git a/aoc2023/build/packages/gleam_community_ansi/gleam.toml b/aoc2023/build/packages/gleam_community_ansi/gleam.toml deleted file mode 100644 index 5da1f7e..0000000 --- a/aoc2023/build/packages/gleam_community_ansi/gleam.toml +++ /dev/null @@ -1,13 +0,0 @@ -name = "gleam_community_ansi" -version = "1.2.0" -licences = ["Apache-2.0"] -description = "ANSI colours, formatting, and control codes" -repository = { type = "github", user = "gleam-community", repo = "ansi" } -gleam = ">= 0.32.0" - -[dependencies] -gleam_stdlib = "~> 0.32" -gleam_community_colour = "~> 1.2" - -[dev-dependencies] -gleeunit = "~> 0.11" diff --git a/aoc2023/build/packages/gleam_community_ansi/src/gleam_community/ansi.gleam b/aoc2023/build/packages/gleam_community_ansi/src/gleam_community/ansi.gleam deleted file mode 100644 index a542dda..0000000 --- a/aoc2023/build/packages/gleam_community_ansi/src/gleam_community/ansi.gleam +++ /dev/null @@ -1,2317 +0,0 @@ -//// -//// - **Text style** -//// - [`bold`](#bold) -//// - [`italic`](#italic) -//// - [`underline`](#underline) -//// - [`strikethrough`](#strikethrough) -//// - [`inverse`](#inverse) -//// - [`dim`](#dim) -//// - [`hidden`](#hidden) -//// - [`reset`](#reset) -//// - **Text colour** -//// - [`black`](#black) -//// - [`red`](#red) -//// - [`green`](#green) -//// - [`yellow`](#yellow) -//// - [`blue`](#blue) -//// - [`magenta`](#magenta) -//// - [`cyan`](#cyan) -//// - [`white`](#white) -//// - [`pink`](#pink) -//// - [`grey`](#grey) -//// - [`gray`](#gray) -//// - [`bright_black`](#bright_black) -//// - [`bright_red`](#bright_red) -//// - [`bright_green`](#bright_green) -//// - [`bright_yellow`](#bright_yellow) -//// - [`bright_blue`](#bright_blue) -//// - [`bright_magenta`](#bright_magenta) -//// - [`bright_cyan`](#bright_cyan) -//// - [`bright_white`](#bright_white) -//// - [`hex`](#hex) -//// - [`colour`](#colour) -//// - [`color`](#color) -//// - **Background colour** -//// - [`bg_black`](#bg_black) -//// - [`bg_red`](#bg_red) -//// - [`bg_green`](#bg_green) -//// - [`bg_yellow`](#bg_yellow) -//// - [`bg_blue`](#bg_blue) -//// - [`bg_magenta`](#bg_magenta) -//// - [`bg_cyan`](#bg_cyan) -//// - [`bg_white`](#bg_white) -//// - [`bg_pink`](#bg_pink) -//// - [`bg_bright_black`](#bg_bright_black) -//// - [`bg_bright_red`](#bg_bright_red) -//// - [`bg_bright_green`](#bg_bright_green) -//// - [`bg_bright_yellow`](#bg_bright_yellow) -//// - [`bg_bright_blue`](#bg_bright_blue) -//// - [`bg_bright_magenta`](#bg_bright_magenta) -//// - [`bg_bright_cyan`](#bg_bright_cyan) -//// - [`bg_bright_white`](#bg_bright_white) -//// - [`bg_hex`](#bg_hex) -//// - [`bg_colour`](#bg_colour) -//// - [`bg_color`](#bg_color) -//// -//// --- -//// -//// This package was heavily inspired by the `colours` module in the Deno standard -//// library. The original source code can be found -//// <a href="https://deno.land/std@0.167.0/fmt/colours.ts">here</a>. -//// -//// <details> -//// <summary>The license of that package is produced below:</summary> -//// -//// -//// > MIT License -//// -//// > Copyright 2018-2022 the Deno authors. -//// -//// > 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. -//// </details> -//// - -// Just in case we decide in the future to no longer include the above reference -// and license, this package was initially a port of the Deno `colours` module: -// -// https://deno.land/std@0.167.0/fmt/colours.ts -// - -// This seems like a really handy reference if/when we want to expand this beyond -// formatting escape sequences: -// -// https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 -// - -// IMPORTS -------------------------------------------------------------------- - -import gleam/int -import gleam/list -import gleam/string -import gleam_community/colour.{type Colour} as gc_colour - -// CONSTS --------------------------------------------------------------------- - -const asci_escape_character = "" - -// TYPES ---------------------------------------------------------------------- - -type Code { - Code(open: String, close: String, regexp: String) -} - -// UTILITY -------------------------------------------------------------------- - -/// Builds colour code -fn code(open: List(Int), close: Int) -> Code { - let close_str = int.to_string(close) - let open_strs = list.map(open, int.to_string) - - Code( - open: asci_escape_character <> "[" <> string.join(open_strs, ";") <> "m", - close: asci_escape_character <> "[" <> close_str <> "m", - regexp: asci_escape_character <> "[" <> close_str <> "m", - ) -} - -/// Applies colour and background based on colour code and its associated text -fn run(text: String, code: Code) -> String { - code.open <> string.replace(text, code.regexp, code.open) <> code.close -} - -// STYLES --------------------------------------------------------------------- - -/// Reset the text modified -pub fn reset(text: String) -> String { - run(text, code([0], 0)) -} - -/// Style the given text bold. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bold("lucy") -/// // => "\x1B[1mlucy\x1B[22m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[22m"` added to the string. This is the escape code -/// for the "default" bold/dim style of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// style, it will use both the outter style and the inner style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be dim but the text "fun?" will be -/// both underlined, *and* bold! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bold(text: String) -> String { - run(text, code([1], 22)) -} - -/// Style the given text's colour to be dimmer. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.dim("lucy") -/// // => "\x1B[2mlucy\x1B[22m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[22m"` added to the string. This is the escape code -/// for the "default" bold/dim style of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// style, it will use both the outter style and the inner style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be dim but the text "fun?" will be -/// both underlined, *and* bold! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn dim(text: String) -> String { - run(text, code([2], 22)) -} - -/// Style the given text italic. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.italic("lucy") -/// // => "\x1B[3mlucy\x1B[23m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[23m"` added to the string. This is the escape code -/// for the "default" italic style of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// style, it will use both the outter style and the inner style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.underline("Isn't " <> ansi.bold("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be underlined but the text "fun?" will be -/// both underlined, *and* bold! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn italic(text: String) -> String { - run(text, code([3], 23)) -} - -/// Style the given text's colour to be dimmer. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.underline("lucy") -/// // => "\x1B[4mlucy\x1B[24m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[24m"` added to the string. This is the escape code -/// for the "default" underline style of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// style, it will use both the outter style and the inner style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be dim but the text "fun?" will be -/// both underlined, *and* bold! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn underline(text: String) -> String { - run(text, code([4], 24)) -} - -/// Inverse the given text's colour, and background colour. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.inverse("lucy") -/// // => "\x1B[7mlucy\x1B[27m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[27m"` added to the string. This is the escape code -/// for the "default" inverse style of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// style, it will use both the outter style and the inner style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be dim but the text "fun?" will be -/// both underlined, *and* bold! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn inverse(text: String) -> String { - run(text, code([7], 27)) -} - -/// Style the given text to be hidden. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.hidden("lucy") -/// // => "\x1B[8mlucy\x1B[28m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[28m"` added to the string. This is the escape code -/// for the "default" hidden style of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// style, it will use both the outter style and the inner style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be dim but the text "fun?" will be -/// both underlined, *and* bold! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn hidden(text: String) -> String { - run(text, code([8], 28)) -} - -/// Style the given text to be striked through. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.strikethrough("lucy") -/// // => "\x1B[9mlucy\x1B[29m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[29m"` added to the string. This is the escape code -/// for the "default" strikethrough style of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// style, it will use both the outter style and the inner style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.dim("Isn't " <> ansi.bold("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be dim but the text "fun?" will be -/// both underlined, *and* bold! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn strikethrough(text: String) -> String { - run(text, code([9], 29)) -} - -// FOREGROUND ----------------------------------------------------------------- - -/// Colour the given text black. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.black("lucy") -/// // => "\x1B[30mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn black(text: String) -> String { - run(text, code([30], 39)) -} - -/// Colour the given text red. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.red("lucy") -/// // => "\x1B[31mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn red(text: String) -> String { - run(text, code([31], 39)) -} - -/// Colour the given text green. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.green("lucy") -/// // => "\x1B[32mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn green(text: String) -> String { - run(text, code([32], 39)) -} - -/// Colour the given text yellow. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("lucy") -/// // => "\x1B[33mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn yellow(text: String) -> String { - run(text, code([33], 39)) -} - -/// Colour the given text blue. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.blue("lucy") -/// // => "\x1B[34mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn blue(text: String) -> String { - run(text, code([34], 39)) -} - -/// Colour the given text magenta. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.magenta("lucy") -/// // => "\x1B[35mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn magenta(text: String) -> String { - run(text, code([35], 39)) -} - -/// Colour the given text cyan. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.cyan("lucy") -/// // => "\x1B[36mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn cyan(text: String) -> String { - run(text, code([36], 39)) -} - -/// Colour the given text white. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.white("lucy") -/// // => "\x1B[37mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn white(text: String) -> String { - run(text, code([37], 39)) -} - -/// Colour the given text gray. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.gray("lucy") -/// // => "\x1B[90mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn grey(text: String) -> String { - bright_black(text) -} - -/// This is an alias for [`grey`](#grey) for those who prefer the American English -/// spelling. -/// -pub fn gray(text: String) -> String { - bright_black(text) -} - -/// Colour the given text bright black. This should increase the luminosity of -/// the base colour, but some terminals will interpret this as bold instead. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bright_black("lucy") -/// // => "\x1B[90mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bright_black(text: String) -> String { - run(text, code([90], 39)) -} - -/// Colour the given text bright red. This should increase the luminosity of -/// the base colour, but some terminals will interpret this as bold instead. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bright_red("lucy") -/// // => "\x1B[91mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bright_red(text: String) -> String { - run(text, code([91], 39)) -} - -/// Colour the given text bright green. This should increase the luminosity of -/// the base colour, but some terminals will interpret this as bold instead. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// fn example() { -/// ansi.bright_green("lucy") -/// // => "\x1B[92mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href=""> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bright_green(text: String) -> String { - run(text, code([92], 39)) -} - -/// Colour the given text bright yellow. This should increase the luminosity of -/// the base colour, but some terminals will interpret this as bold instead. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// fn example() { -/// ansi.bright_yellow("lucy") -/// // => "\x1B[93mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href=""> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bright_yellow(text: String) -> String { - run(text, code([93], 39)) -} - -/// Colour the given text bright blue. This should increase the luminosity of -/// the base colour, but some terminals will interpret this as bold instead. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// fn example() { -/// ansi.bright_blue("lucy") -/// // => "\x1B[94mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href=""> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bright_blue(text: String) -> String { - run(text, code([94], 39)) -} - -/// Colour the given text bright gremagentaen. This should increase the luminosity -/// of the base colour, but some terminals will interpret this as bold instead. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// fn example() { -/// ansi.bright_magenta("lucy") -/// // => "\x1B[95mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href=""> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bright_magenta(text: String) -> String { - run(text, code([95], 39)) -} - -/// Colour the given text bright cyan. This should increase the luminosity of -/// the base colour, but some terminals will interpret this as bold instead. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// fn example() { -/// ansi.bright_cyan("lucy") -/// // => "\x1B[96mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href=""> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bright_cyan(text: String) -> String { - run(text, code([96], 39)) -} - -/// Colour the given text bright white. This should increase the luminosity of -/// the base colour, but some terminals will interpret this as bold instead. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// fn example() { -/// ansi.bright_white("lucy") -/// // => "\x1B[97mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href=""> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bright_white(text: String) -> String { - run(text, code([97], 39)) -} - -/// Colour the given text pink. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.pink("lucy") -/// // => "\x1B[38;2;255;175;243mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[39m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn pink(text: String) -> String { - hex(text, 0xffaff3) -} - -/// Colour the given text the given colour represented by a hex `Int`. -/// -/// The given hex Int can be any valid [shorthand hexadecimal form](https://en.wikipedia.org/wiki/Web_colors#Shorthand_hexadecimal_form). -/// -/// ❗️ Note that if supplied hex Int is less than 0 or larger than 0xfffff the -/// colour will be set to black and white respectively. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.hex("lucy", 0xffaff3) -/// // => "\x1B[38;2;255;175;243mlucy\x1B[39m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn hex(text: String, colour: Int) -> String { - let colour = int.clamp(colour, max: 0xffffff, min: 0x0) - run( - text, - code( - [ - 38, - 2, - int.bitwise_shift_right(colour, 16) - |> int.bitwise_and(0xff), - int.bitwise_shift_right(colour, 8) - |> int.bitwise_and(0xff), - int.bitwise_and(colour, 0xff), - ], - 39, - ), - ) -} - -/// Colour the given text the given colour represented by a `Colour`. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// import gleam_community/colour.{Colour} -/// -/// fn example() { -/// let pink = colour.from_hsl(0.8583, 1.0, 0,84) -/// ansi.colour("lucy", pink) -/// // => "\x1B[48;2;255;175;243mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn colour(text: String, colour: Colour) -> String { - let hex_colour = gc_colour.to_rgb_hex(colour) - hex(text, hex_colour) -} - -/// This is an alias for [`colour`](#colour) for those who prefer the American English -/// spelling. -/// -pub fn color(text: String, color: Colour) -> String { - colour(text, color) -} - -// BACKGROUND ----------------------------------------------------------------- - -/// Colour the given text's background black. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_black("lucy") -/// // => "\x1B[40mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_black(text: String) -> String { - run(text, code([40], 49)) -} - -/// Colour the given text's background red. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_red("lucy") -/// // => "\x1B[41mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_red(text: String) -> String { - run(text, code([41], 49)) -} - -/// Colour the given text's background green. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_green("lucy") -/// // => "\x1B[42mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_green(text: String) -> String { - run(text, code([42], 49)) -} - -/// Colour the given text's background yellow. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_yellow("lucy") -/// // => "\x1B[43mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_yellow(text: String) -> String { - run(text, code([43], 49)) -} - -/// Colour the given text's background blue. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_blue("lucy") -/// // => "\x1B[44mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_blue(text: String) -> String { - run(text, code([44], 49)) -} - -/// Colour the given text's background magenta. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_magenta("lucy") -/// // => "\x1B[45mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_magenta(text: String) -> String { - run(text, code([45], 49)) -} - -/// Colour the given text's background cyan. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_cyan("lucy") -/// // => "\x1B[46mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_cyan(text: String) -> String { - run(text, code([46], 49)) -} - -/// Colour the given text's background white. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_white("lucy") -/// // => "\x1B[47mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_white(text: String) -> String { - run(text, code([47], 49)) -} - -/// Colour the given text's background bright black. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_bright_black("lucy") -/// // => "\x1B[100mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_bright_black(text: String) -> String { - run(text, code([100], 49)) -} - -/// Colour the given text's background bright red. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_bright_red("lucy") -/// // => "\x1B[101mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_bright_red(text: String) -> String { - run(text, code([101], 49)) -} - -/// Colour the given text's background bright green. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_bright_green("lucy") -/// // => "\x1B[102mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_bright_green(text: String) -> String { - run(text, code([102], 49)) -} - -/// Colour the given text's background bright yellow. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_bright_yellow("lucy") -/// // => "\x1B[103mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_bright_yellow(text: String) -> String { - run(text, code([103], 49)) -} - -/// Colour the given text's background bright blue. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_bright_blue("lucy") -/// // => "\x1B[104mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_bright_blue(text: String) -> String { - run(text, code([104], 49)) -} - -/// Colour the given text's background bright magenta. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_bright_magenta("lucy") -/// // => "\x1B[105mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_bright_magenta(text: String) -> String { - run(text, code([105], 49)) -} - -/// Colour the given text's background bright cyan. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_bright_cyan("lucy") -/// // => "\x1B[106mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_bright_cyan(text: String) -> String { - run(text, code([106], 49)) -} - -/// Colour the given text's background bright white. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_bright_white("lucy") -/// // => "\x1B[107mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_bright_white(text: String) -> String { - run(text, code([107], 49)) -} - -/// Colour the given text's background pink. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.bg_pink("lucy") -/// // => "\x1B[48;2;255;175;243mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_pink(text: String) -> String { - bg_hex(text, 0xffaff3) -} - -/// Colour the given text's background the given colour represented by a hex `Int`. -/// -/// The given hex Int can be any valid [shorthand hexadecimal form](https://en.wikipedia.org/wiki/Web_colors#Shorthand_hexadecimal_form). -/// -/// ❗️ Note that if supplied hex Int is less than 0 or larger than 0xfffff the -/// colour will be set to black and white respectively. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.hex("lucy", 0xffaff3) -/// // => "\x1B[48;2;255;175;243mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_hex(text: String, colour: Int) -> String { - run( - text, - code( - [ - 48, - 2, - int.bitwise_shift_right(colour, 16) - |> int.bitwise_and(0xff), - int.bitwise_shift_right(colour, 8) - |> int.bitwise_and(0xff), - int.bitwise_and(colour, 0xff), - ], - 49, - ), - ) -} - -/// Colour the given text's background with the given colour represented by a `Colour`. -/// -/// <details> -/// <summary>Example:</summary> -/// -/// ```gleam -/// import gleam_community/ansi -/// import gleam_community/colour.{Colour} -/// -/// fn example() { -/// let pink = colour.from_hsl(0.8583, 1.0, 0,84) -/// ansi.bg_colour("lucy", pink) -/// // => "\x1B[48;2;255;175;243mlucy\x1B[49m" -/// } -/// ``` -/// -/// ❗️ Note the trailing `"\x1B[49m"` added to the string. This is the escape code -/// for the "default" colour of the terminal. This means text you write after -/// this will revert back to default. -/// -/// ✨ `gleam_community/ansi` is smart about nested styles; instead of using the default -/// colour, it will use the colour of the outter style. -/// -/// ```gleam -/// import gleam_community/ansi -/// -/// fn example() { -/// ansi.yellow("Isn't " <> ansi.pink("Gleam") <> " fun?") -/// } -/// ``` -/// -/// In this example, the text "Gleam" will be pink but the text "fun?" will be -/// yellow, *not* the default colour! -/// </details> -/// -/// <div style="position: relative;"> -/// <a style="position: absolute; left: 0;" href="https://github.com/gleam-community/ansi/issues"> -/// <small>Spot a typo? Open an issue!</small> -/// </a> -/// <a style="position: absolute; right: 0;" href="#"> -/// <small>Back to top ↑</small> -/// </a> -/// </div> -/// -pub fn bg_colour(text: String, colour: Colour) -> String { - let hex_colour = gc_colour.to_rgb_hex(colour) - bg_hex(text, hex_colour) -} - -/// This is an alias for [`bg_colour`](#bg_colour) for those who prefer the American English -/// spelling. -/// -pub fn bg_color(text: String, colour: Colour) -> String { - bg_colour(text, colour) -} diff --git a/aoc2023/build/packages/gleam_community_ansi/src/gleam_community@ansi.erl b/aoc2023/build/packages/gleam_community_ansi/src/gleam_community@ansi.erl deleted file mode 100644 index 8b7a4c9..0000000 --- a/aoc2023/build/packages/gleam_community_ansi/src/gleam_community@ansi.erl +++ /dev/null @@ -1,263 +0,0 @@ --module(gleam_community@ansi). --compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]). - --export([reset/1, bold/1, dim/1, italic/1, underline/1, inverse/1, hidden/1, strikethrough/1, black/1, red/1, green/1, yellow/1, blue/1, magenta/1, cyan/1, white/1, bright_black/1, grey/1, gray/1, bright_red/1, bright_green/1, bright_yellow/1, bright_blue/1, bright_magenta/1, bright_cyan/1, bright_white/1, hex/2, pink/1, colour/2, color/2, bg_black/1, bg_red/1, bg_green/1, bg_yellow/1, bg_blue/1, bg_magenta/1, bg_cyan/1, bg_white/1, bg_bright_black/1, bg_bright_red/1, bg_bright_green/1, bg_bright_yellow/1, bg_bright_blue/1, bg_bright_magenta/1, bg_bright_cyan/1, bg_bright_white/1, bg_hex/2, bg_pink/1, bg_colour/2, bg_color/2]). --export_type([code/0]). - --type code() :: {code, binary(), binary(), binary()}. - --spec code(list(integer()), integer()) -> code(). -code(Open, Close) -> - Close_str = gleam@int:to_string(Close), - Open_strs = gleam@list:map(Open, fun gleam@int:to_string/1), - {code, - <<<<<<""/utf8, "["/utf8>>/binary, - (gleam@string:join(Open_strs, <<";"/utf8>>))/binary>>/binary, - "m"/utf8>>, - <<<<<<""/utf8, "["/utf8>>/binary, Close_str/binary>>/binary, "m"/utf8>>, - <<<<<<""/utf8, "["/utf8>>/binary, Close_str/binary>>/binary, "m"/utf8>>}. - --spec run(binary(), code()) -> binary(). -run(Text, Code) -> - <<<<(erlang:element(2, Code))/binary, - (gleam@string:replace( - Text, - erlang:element(4, Code), - erlang:element(2, Code) - ))/binary>>/binary, - (erlang:element(3, Code))/binary>>. - --spec reset(binary()) -> binary(). -reset(Text) -> - run(Text, code([0], 0)). - --spec bold(binary()) -> binary(). -bold(Text) -> - run(Text, code([1], 22)). - --spec dim(binary()) -> binary(). -dim(Text) -> - run(Text, code([2], 22)). - --spec italic(binary()) -> binary(). -italic(Text) -> - run(Text, code([3], 23)). - --spec underline(binary()) -> binary(). -underline(Text) -> - run(Text, code([4], 24)). - --spec inverse(binary()) -> binary(). -inverse(Text) -> - run(Text, code([7], 27)). - --spec hidden(binary()) -> binary(). -hidden(Text) -> - run(Text, code([8], 28)). - --spec strikethrough(binary()) -> binary(). -strikethrough(Text) -> - run(Text, code([9], 29)). - --spec black(binary()) -> binary(). -black(Text) -> - run(Text, code([30], 39)). - --spec red(binary()) -> binary(). -red(Text) -> - run(Text, code([31], 39)). - --spec green(binary()) -> binary(). -green(Text) -> - run(Text, code([32], 39)). - --spec yellow(binary()) -> binary(). -yellow(Text) -> - run(Text, code([33], 39)). - --spec blue(binary()) -> binary(). -blue(Text) -> - run(Text, code([34], 39)). - --spec magenta(binary()) -> binary(). -magenta(Text) -> - run(Text, code([35], 39)). - --spec cyan(binary()) -> binary(). -cyan(Text) -> - run(Text, code([36], 39)). - --spec white(binary()) -> binary(). -white(Text) -> - run(Text, code([37], 39)). - --spec bright_black(binary()) -> binary(). -bright_black(Text) -> - run(Text, code([90], 39)). - --spec grey(binary()) -> binary(). -grey(Text) -> - bright_black(Text). - --spec gray(binary()) -> binary(). -gray(Text) -> - bright_black(Text). - --spec bright_red(binary()) -> binary(). -bright_red(Text) -> - run(Text, code([91], 39)). - --spec bright_green(binary()) -> binary(). -bright_green(Text) -> - run(Text, code([92], 39)). - --spec bright_yellow(binary()) -> binary(). -bright_yellow(Text) -> - run(Text, code([93], 39)). - --spec bright_blue(binary()) -> binary(). -bright_blue(Text) -> - run(Text, code([94], 39)). - --spec bright_magenta(binary()) -> binary(). -bright_magenta(Text) -> - run(Text, code([95], 39)). - --spec bright_cyan(binary()) -> binary(). -bright_cyan(Text) -> - run(Text, code([96], 39)). - --spec bright_white(binary()) -> binary(). -bright_white(Text) -> - run(Text, code([97], 39)). - --spec hex(binary(), integer()) -> binary(). -hex(Text, Colour) -> - Colour@1 = gleam@int:clamp(Colour, 16#0, 16#ffffff), - run( - Text, - code( - [38, - 2, - begin - _pipe = erlang:'bsr'(Colour@1, 16), - erlang:'band'(_pipe, 16#ff) - end, - begin - _pipe@1 = erlang:'bsr'(Colour@1, 8), - erlang:'band'(_pipe@1, 16#ff) - end, - erlang:'band'(Colour@1, 16#ff)], - 39 - ) - ). - --spec pink(binary()) -> binary(). -pink(Text) -> - hex(Text, 16#ffaff3). - --spec colour(binary(), gleam_community@colour:colour()) -> binary(). -colour(Text, Colour) -> - Hex_colour = gleam_community@colour:to_rgb_hex(Colour), - hex(Text, Hex_colour). - --spec color(binary(), gleam_community@colour:colour()) -> binary(). -color(Text, Color) -> - colour(Text, Color). - --spec bg_black(binary()) -> binary(). -bg_black(Text) -> - run(Text, code([40], 49)). - --spec bg_red(binary()) -> binary(). -bg_red(Text) -> - run(Text, code([41], 49)). - --spec bg_green(binary()) -> binary(). -bg_green(Text) -> - run(Text, code([42], 49)). - --spec bg_yellow(binary()) -> binary(). -bg_yellow(Text) -> - run(Text, code([43], 49)). - --spec bg_blue(binary()) -> binary(). -bg_blue(Text) -> - run(Text, code([44], 49)). - --spec bg_magenta(binary()) -> binary(). -bg_magenta(Text) -> - run(Text, code([45], 49)). - --spec bg_cyan(binary()) -> binary(). -bg_cyan(Text) -> - run(Text, code([46], 49)). - --spec bg_white(binary()) -> binary(). -bg_white(Text) -> - run(Text, code([47], 49)). - --spec bg_bright_black(binary()) -> binary(). -bg_bright_black(Text) -> - run(Text, code([100], 49)). - --spec bg_bright_red(binary()) -> binary(). -bg_bright_red(Text) -> - run(Text, code([101], 49)). - --spec bg_bright_green(binary()) -> binary(). -bg_bright_green(Text) -> - run(Text, code([102], 49)). - --spec bg_bright_yellow(binary()) -> binary(). -bg_bright_yellow(Text) -> - run(Text, code([103], 49)). - --spec bg_bright_blue(binary()) -> binary(). -bg_bright_blue(Text) -> - run(Text, code([104], 49)). - --spec bg_bright_magenta(binary()) -> binary(). -bg_bright_magenta(Text) -> - run(Text, code([105], 49)). - --spec bg_bright_cyan(binary()) -> binary(). -bg_bright_cyan(Text) -> - run(Text, code([106], 49)). - --spec bg_bright_white(binary()) -> binary(). -bg_bright_white(Text) -> - run(Text, code([107], 49)). - --spec bg_hex(binary(), integer()) -> binary(). -bg_hex(Text, Colour) -> - run( - Text, - code( - [48, - 2, - begin - _pipe = erlang:'bsr'(Colour, 16), - erlang:'band'(_pipe, 16#ff) - end, - begin - _pipe@1 = erlang:'bsr'(Colour, 8), - erlang:'band'(_pipe@1, 16#ff) - end, - erlang:'band'(Colour, 16#ff)], - 49 - ) - ). - --spec bg_pink(binary()) -> binary(). -bg_pink(Text) -> - bg_hex(Text, 16#ffaff3). - --spec bg_colour(binary(), gleam_community@colour:colour()) -> binary(). -bg_colour(Text, Colour) -> - Hex_colour = gleam_community@colour:to_rgb_hex(Colour), - bg_hex(Text, Hex_colour). - --spec bg_color(binary(), gleam_community@colour:colour()) -> binary(). -bg_color(Text, Colour) -> - bg_colour(Text, Colour). diff --git a/aoc2023/build/packages/gleam_community_ansi/src/gleam_community_ansi.app.src b/aoc2023/build/packages/gleam_community_ansi/src/gleam_community_ansi.app.src deleted file mode 100644 index dfcfdc3..0000000 --- a/aoc2023/build/packages/gleam_community_ansi/src/gleam_community_ansi.app.src +++ /dev/null @@ -1,9 +0,0 @@ -{application, gleam_community_ansi, [ - {vsn, "1.2.0"}, - {applications, [gleam_community_colour, - gleam_stdlib, - gleeunit]}, - {description, "ANSI colours, formatting, and control codes"}, - {modules, [gleam_community@ansi]}, - {registered, []} -]}. |