Mordant 为Kotlin命令行应用程序提供简单的文本样式化

网友投稿 589 2022-10-29

Mordant 为Kotlin命令行应用程序提供简单的文本样式化

Mordant 为Kotlin命令行应用程序提供简单的文本样式化

Mordant

Dead simple text styling for command-line applications

/mɔː(ɹ)dənt/ A substance used to set (i.e. bind) colored dyes on fabrics 1

Mordant has:

An easy, configuration-free, APISupport for nesting styles and colorsAutomatic detection of terminal color supportSupport for 256 and 24-bit colors, with automatic downsamplingSupport for specifying colors in every color space supported by colormath

Usage

val t = TermColors()println(t.red("This text will be red on terminals that support color"))

Multiple styles

with(TermColors()) { println("${red("red")} ${white("white")} and ${blue("blue")}")}

Foreground and background colors

with(TermColors()) { println((yellow on brightGreen)("this is easy to read, right?"))}

Background color alone

with(TermColors()) { println("The foreground ${brightBlue.bg("color will stay the")} same")}

Combine styles and colors

with(TermColors()) { val style = (bold + white + underline) println(style("You can save styles")) println(style("to reuse"))}

Nest styles and colors

with(TermColors()) { println(white("You ${(blue on yellow)("can ${(black + strikethrough)("nest")} styles")} arbitrarily"))}

True color and other color spaces

with(TermColors()) { println(rgb("#b4eeb4")("This will get downsampled on terminals that don't support truecolor"))}

with(TermColors()) { for (v in 0..100 step 4) { for (h in 0..360 step 4) { print(hsv(h, 100, 100 - v).bg(" ")) } println() }}

API Documentation

API docs are hosted on JitPack.

Installation

Mordant is distributed through Maven Central, Jcenter and Jitpack.

dependencies { implementation 'com.github.ajalt:mordant:1.2.0'}

License

Copyright 2018 AJ AltLicensed 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://apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:教你如何定位不合理的SQL?并优化之
下一篇:从头开始学Shell------查看文件、数组、别名
相关文章

 发表评论

暂时没有评论,来抢沙发吧~