trufflehog/pkg/tui/common/utils.go
Hon Kwok 4598244167
Use placeholder as default if field left empty and is required (#1642)
* Use placeholder as default if field left empty and is required

Co-authored-by: mcastorina <m.castorina93@gmail.com>

* Drop unused func

* uncomment azure source

* update wording

---------

Co-authored-by: mcastorina <m.castorina93@gmail.com>
2023-10-02 17:21:40 -07:00

28 lines
691 B
Go

package common
import (
"strings"
"github.com/muesli/reflow/truncate"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/components/textinputs"
)
// TruncateString is a convenient wrapper around truncate.TruncateString.
func TruncateString(s string, max int) string {
if max < 0 {
max = 0
}
return truncate.StringWithTail(s, uint(max), "…")
}
func SummarizeSource(keys []string, inputs map[string]textinputs.Input, labels map[string]string) string {
summary := strings.Builder{}
for _, key := range keys {
if inputs[key].Value != "" {
summary.WriteString("\t" + labels[key] + ": " + inputs[key].Value + "\n")
}
}
summary.WriteString("\n")
return summary.String()
}