File: main.go

package info (click to toggle)
golang-github-charmbracelet-x 0.0~git20240809.9ab0ca0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,004 kB
  • sloc: sh: 55; makefile: 5
file content (32 lines) | stat: -rw-r--r-- 590 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

import (
	"flag"
	"fmt"
	"log"
	"strconv"
	"strings"

	"github.com/charmbracelet/x/exp/term/ansi"
)

var (
	length = flag.Int("l", 80, "length of the output")
	tail   = flag.String("tail", "", "tail of the output")
)

func main() {
	flag.Parse()

	var err error
	input := strings.Join(flag.Args(), " ")
	input, err = strconv.Unquote(`"` + input + `"`)
	if err != nil {
		log.Fatalf("could not unquote input: %v", err)
	}

	output := ansi.Truncate(input, *length, *tail)
	output = strconv.Quote(output)
	output = output[1 : len(output)-1] // remove quotes
	fmt.Print(output)
}