All Projects β†’ ajalt β†’ Mordant

ajalt / Mordant

Licence: apache-2.0
Full-featured text styling for Kotlin command-line applications

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Mordant

Rang
A Minimal, Header only Modern c++ library for terminal goodies πŸ’„βœ¨
Stars: ✭ 1,080 (+182.72%)
Mutual labels:  terminal, console, ansi, color
Chalk
πŸ– Terminal string styling done right
Stars: ✭ 17,566 (+4498.43%)
Mutual labels:  terminal, console, ansi, color
log-utils
Basic logging utils: colors, symbols and timestamp.
Stars: ✭ 24 (-93.72%)
Mutual labels:  console, color, ansi, ansi-colors
Paint
Ruby gem for ANSI terminal colors 🎨︎ VERY FAST
Stars: ✭ 317 (-17.02%)
Mutual labels:  terminal, ansi, ansi-colors
Box Cli Maker
Make Highly Customized Boxes for your CLI
Stars: ✭ 115 (-69.9%)
Mutual labels:  terminal, console, color
Php Console Spinner
Colorful highly configurable spinner for php cli applications (suitable for async apps)
Stars: ✭ 225 (-41.1%)
Mutual labels:  terminal, console, color
Crossline
A small, self-contained, zero-config, MIT licensed, cross-platform, readline and libedit replacement.
Stars: ✭ 53 (-86.13%)
Mutual labels:  terminal, console, color
leeks.js
Simple ANSI styling for your terminal
Stars: ✭ 12 (-96.86%)
Mutual labels:  console, color, ansi
strip-ansi-stream
Strip ANSI escape codes
Stars: ✭ 32 (-91.62%)
Mutual labels:  console, color, ansi
yachalk
πŸ–οΈ Terminal string styling done right
Stars: ✭ 131 (-65.71%)
Mutual labels:  console, color, ansi
paper-terminal
Print Markdown to a paper in your terminal
Stars: ✭ 33 (-91.36%)
Mutual labels:  console, color, ansi
Chalk Animation
🎬 Colorful animations in terminal output
Stars: ✭ 1,489 (+289.79%)
Mutual labels:  terminal, console, color
Asciichart
Nice-looking lightweight console ASCII line charts β•­β”ˆβ•― for NodeJS, browsers and terminal, no dependencies
Stars: ✭ 1,107 (+189.79%)
Mutual labels:  terminal, console, ansi
Colorizeswift
Terminal string styling for Swift.
Stars: ✭ 253 (-33.77%)
Mutual labels:  terminal, ansi, color
ansicolor
A JavaScript ANSI color/style management. ANSI parsing. ANSI to CSS. Small, clean, no dependencies.
Stars: ✭ 91 (-76.18%)
Mutual labels:  console, ansi, ansi-colors
concolor
Colouring template strings using tags with annotations 🎨
Stars: ✭ 35 (-90.84%)
Mutual labels:  console, color, ansi
go-color
A lightweight, simple and cross-platform package to colorize text in terminals
Stars: ✭ 65 (-82.98%)
Mutual labels:  console, color, ansi
Crossterm
Cross platform terminal library rust
Stars: ✭ 1,023 (+167.8%)
Mutual labels:  terminal, console, color
Colorette
Easily set the color and style of text in the terminal.
Stars: ✭ 1,047 (+174.08%)
Mutual labels:  terminal, console, ansi
ansiart2utf8
Processes legacy BBS-style ANSI art (ACiDDraw, PabloDraw, etc.) to UTF-8. Escape codes and line endings are processed for terminal friendliness.
Stars: ✭ 32 (-91.62%)
Mutual labels:  console, ansi, ansi-colors

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
  • Components for laying out our 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 alpha. 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 emojii.

val t = Terminal()
t.println(table {
    header { row("CJK", "Emojis") }
    body { row("λͺ¨γ„Ήλ‹¨γ…Œ", "πŸ™ŠπŸ™‰πŸ™ˆ") }
})

Mordant gives you lots of customization for your tables, including striped row styles, row and column spans, and different border styles.

table {
    borderStyle = SQUARE_DOUBLE_SECTION_SEPARATOR
    align = RIGHT
    outerBorder = false
    column(0) {
        align = LEFT
        borders = ALL
        style = magenta
    }
    column(3) {
        borders = ALL
        style = magenta
    }
    header {
        style(magenta, bold = true)
        row("", "Projected Cost", "Actual Cost", "Difference")
    }
    body {
        rowStyles(blue, brightBlue)
        borders = TOM_BOTTOM
        row("Food", "$400", "$200", "$200")
        row("Data", "$100", "$150", "-$50")
        row("Rent", "$800", "$800", "$0")
        row("Candles", "$0", "$3,600", "-$3,600")
        row("Utility", "$145", "$150", "-$5")
    }
    footer {
        style(bold = true)
        row {
            cell("Subtotal")
            cell("$-3,455") { columnSpan = 3 }
        }
    }
    captionBottom("Budget courtesy @dril", TextStyle(dim = true))
}

Markdown

Mordant can render GitHub Flavored Markdown. Hyperlinks will even be clickable if you're on a terminal that supports it, like recent versions of iTerm or Windows Terminal.

val t = Terminal()
t.printMarkdown(File("README.md").readText())

Controlling the cursor

You can show and hide the cursor, move it around, and clear parts of the screen with the cursor property on Terminal. If your terminal doesn't support cursor movements (like when output is redirected to a file) these commands are no-ops.

val t = Terminal()
t.cursor.up(3)
t.cursor.startOfLine()
t.cursor.clearScreenAfterCursor()
t.cursor.hide(showOnExit = true)

Animations

You can animate any widget like a table with Terminal.animation, or any regular string with Terminal.textAnimation.

val t = Terminal()
val a = t.textAnimation<Int> { frame ->
    (1..50).joinToString("") {
        val hue = (frame + it) * 3 % 360
        t.colors.hsv(hue, 100, 100)("━")
    }
}

t.cursor.hide(showOnExit = true)
repeat(120) {
    a.update(it)
    Thread.sleep(25)
}

Progress bars

You can create customizable progress bars that automatically compute speed and time remaining.

val t = Terminal()
val progress = t.progressAnimation {
    text("my-file.iso")
    percentage()
    progressBar()
    completed()
    speed("B/s")
    timeRemaining()
}

Call progress.start to animate the progress, and progress.update or progress.advance as your task completes.

Installation

Mordant is distributed through Maven Central.

dependencies {
   implementation("com.github.ajalt.mordant:mordant:2.0.0-alpha2")
}
In version 2.0, the maven coordinates changed. Make sure you're using the new coordinates if you're updating from an older version.

License

Copyright 2018-2020 AJ Alt

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].