All Projects → reconquest → Loreley

reconquest / Loreley

Licence: mit
Simple and extensible colorizer for programs' output

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Loreley

Zoya
Truly highly composable logging utility
Stars: ✭ 116 (+213.51%)
Mutual labels:  logs, colors
Testlogcollectors
A framework for capturing log statements during tests. Compatible with most popular logging frameworks. Works with JUnit and TestNG
Stars: ✭ 31 (-16.22%)
Mutual labels:  logs
Ekanite
The Syslog server with built-in search
Stars: ✭ 729 (+1870.27%)
Mutual labels:  logs
Git Praise
A nicer git blame.
Stars: ✭ 24 (-35.14%)
Mutual labels:  colors
Loghouse
Ready to use log management solution for Kubernetes storing data in ClickHouse and providing web UI.
Stars: ✭ 805 (+2075.68%)
Mutual labels:  logs
Vector
A reliable, high-performance tool for building observability data pipelines.
Stars: ✭ 8,736 (+23510.81%)
Mutual labels:  logs
Colored
(Rust) Coloring terminal so simple you already know how to do it !
Stars: ✭ 715 (+1832.43%)
Mutual labels:  colors
Brim
Desktop application to efficiently search large packet captures and Zeek logs.
Stars: ✭ 976 (+2537.84%)
Mutual labels:  logs
Cl Ansi Text
Enables ANSI colors for printing.
Stars: ✭ 30 (-18.92%)
Mutual labels:  colors
Logmonitor
Monitoring log files on windows systems.
Stars: ✭ 23 (-37.84%)
Mutual labels:  logs
Graylog Cp Watchguard
Graylog Content Pack for Watchguard Fireware Logging
Stars: ✭ 23 (-37.84%)
Mutual labels:  logs
Styled System
⬢ Style props for rapid UI development
Stars: ✭ 7,126 (+19159.46%)
Mutual labels:  colors
Gollum
An n:m message multiplexer written in Go
Stars: ✭ 883 (+2286.49%)
Mutual labels:  logs
Opstrace
Secure observability, deployed in your own network. An open source alternative to SaaS solutions like Datadog, SignalFx, ...
Stars: ✭ 743 (+1908.11%)
Mutual labels:  logs
Hsluv
Human-friendly HSL, reference implementation
Stars: ✭ 959 (+2491.89%)
Mutual labels:  colors
Django Admin Interface
django's default admin interface made customizable. popup windows replaced by modals. :mage: ⚡️
Stars: ✭ 717 (+1837.84%)
Mutual labels:  colors
Pm2 Logrotate
Automatically rotate all applications logs managed by PM2
Stars: ✭ 905 (+2345.95%)
Mutual labels:  logs
Irc Colors.js
Color and formatting for irc bots made easy. Inspired by colors.js and cli-color.
Stars: ✭ 26 (-29.73%)
Mutual labels:  colors
Vue Beautiful Chat
A simple and beautiful Vue chat component backend agnostic, fully customisable and extendable.
Stars: ✭ 979 (+2545.95%)
Mutual labels:  colors
Leonardo
Generate colors based on a desired contrast ratio
Stars: ✭ 973 (+2529.73%)
Mutual labels:  colors

loreley

Easy and extensible colorizer for the programs' output.

Basically, loreley turns this:

{bold}{fg 15}{bg 27} hello {from "" 29} there {to 16 ""},

Into this:

2016-06-27-13t53t45

Usage

package main

import "fmt"
import "github.com/reconquest/loreley"

func main() {
	text, err := loreley.CompileAndExecuteToString(
		`{bold}{fg 15}{bg 27} hello {from "" 29} {.where} {to 16 ""}{reset}`,
		nil,
		map[string]interface{}{"where": "there"},
	)
	if err != nil {
		fmt.Errorf(`can't compile loreley template: %s`, err)
	}

	fmt.Println(text)
}

Colors in text/tabwriter

Unfortunately, stdlib tabwriter does not implement proper column width calculation if you use escape sequences in your data to highlight some output.

So, probably, You will see something like this trying tabwriter:

tabwriter-before

Using loreley you can achieve exactly what you're expecting to see:

tabwriter-after

package main

import (
	"bytes"
	"fmt"
	"strings"
	"text/tabwriter"

	"github.com/reconquest/loreley"
)

const ()

func main() {
	buffer := &bytes.Buffer{}

	writer := tabwriter.NewWriter(buffer, 2, 4, 2, ' ', tabwriter.FilterHTML)

	writer.Write([]byte(strings.Join(
		[]string{
			"<underline>CORES<reset>",
			"<underline>DESCRIPTION<reset>\n",
		}, "\t",
	)))

	writer.Write([]byte(strings.Join(
		[]string{
			"<fg 15><bg 1><bold> 1 <reset> <fg 15><bg 243><bold> 3 <reset>",
			"test\n",
		}, "\t",
	)))

	writer.Flush()

	loreley.DelimLeft = "<"
	loreley.DelimRight = ">"

	result, err := loreley.CompileAndExecuteToString(
		buffer.String(),
		nil,
		nil,
	)
	if err != nil {
		panic(err)
	}

	fmt.Print(result)
}

Reference

loreley extends Go-lang template system. So, fully syntax is supported with exception, that { and } will be used as delimiters.

All <color>, accepted by loreley, should be the 256-color code.

Available template functions:

  • {bg <color>} sets background color for the next text;
  • {fg <color>} sets foreground color for the next text;
  • {nobg} resets background color to the default;
  • {nofg} resets foreground color to the default;
  • {bold} set bold mode on for the next text;
  • {nobold} set bold mode to off;
  • {reverse} set reverse mode on for the next text;
  • {noreverse} set reverse mode off;
  • {underline} set underline mode on for the next text;
  • {nounderline} set underline mode off;
  • {reset} resets all styles to default;
  • {from <text> <bg>} reuse current fg as specified <text>'s bg color, specified <bg> will be used as fg color and as bg color for the following text;
  • {to <bg> <text>} reuse current bg as specified <text>'s bg color, specified <bg> will be used as fg color for the following text;

License

This project is licensed under the terms of the MIT 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].