aboutsummaryrefslogtreecommitdiff
path: root/internal/prompt/misc.go
blob: 382c6cd5ccb06a8e33db9579c7af785781c88dcf (plain)
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
// SPDX-FileCopyrightText: 2017 Stefan Majewsky <majewsky@gmx.net>
// SPDX-License-Identifier: GPL-3.0-only

package prompt

import (
	"os"
	"strconv"
)

func getTerminalField() string {
	termName := os.Getenv("TERM")
	if termName == "xterm-256color" {
		return ""
	}
	if termName == "" {
		termName = withColor("1;41", "not set")
	}
	return withType("term", termName)
}

func getExitCodeField(arg string) string {
	exitCode, err := strconv.Atoi(arg)
	if err == nil && exitCode > 0 {
		return withColor("1;31", "exit:"+arg)
	}
	return ""
}