• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ajalt/mordant: Multiplatform text styling for Kotlin command-line applications

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

ajalt/mordant

开源软件地址(OpenSource Url):

https://github.com/ajalt/mordant

开源编程语言(OpenSource Language):

Kotlin 98.6%

开源软件介绍(OpenSource Introduction):

Mordant

Colorful styling for command-line applications

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

Mordant has:

  • Easy colorful ANSI output with automatic detection of terminal capabilities
  • Markdown rendering directly to the terminal
  • Widgets for laying out terminal output, including lists, tables, panels, and more
  • Support for animating any widget, like progress bars and dashboards
This README documents Mordant 2.0, which is in beta. You can read the docs for Mordant 1.0 here.

Usage

Create a Terminal instance, and import any enum entries you want from TextColors and TextStyles. The println function on your Terminal will detect your current terminal capabilities and automatically downsample ANSI codes if necessary.

import com.github.ajalt.mordant.rendering.TextColors.*
import com.github.ajalt.mordant.rendering.TextStyles.*

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

Multiple styles

import com.github.ajalt.mordant.rendering.TextColors.*
val t = Terminal()
t.println("${red("red")} ${white("white")} and ${blue("blue")}")

Foreground and background colors

t.println((yellow on brightGreen)("this is easy to read, right?"))

Background color alone

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

Combine styles and colors

val style = (bold + white + underline)
t.println(style("You can save styles"))
t.println(style("to reuse"))

Nest styles and colors

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

True color and other color spaces

import com.github.ajalt.mordant.rendering.TextColors.Companion.rgb

t.println(rgb("#b4eeb4")("This will get downsampled on terminals that don't support truecolor"))

Terminal color support detection

By default, Terminal() will try to detect ANSI support in the current stdout stream. If you'd like to override the detection, you can pass a specific value to the Terminal constructor.

For example, to always output ANSI RGB color codes, even if stdout is currently directed to a file, you can do this:

Terminal(AnsiLevel.TRUECOLOR)

Tables

Use the table DSL to quickly create tables. Mordant handles ANSI styles and wide characters like CJK and emoji.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap