ls: less verbose formatting

master
Sina Siadat 9 years ago
parent bbc91f317c
commit d24721db6b

@ -230,9 +230,14 @@ func (attr attrStruct) print(w *tabwriter.Writer, verbose bool, indent int, high
//fmt.Printf(strings.Repeat(" ", indent)) //fmt.Printf(strings.Repeat(" ", indent))
if attr.getMark() == 0 { if attr.getMark() == 0 {
fmt.Fprintf(out, "[%s] %s\n", color(attr.getIdentifier(), "yellow+b"), attr.title()) fmt.Fprintf(out, "%s: %s\n", color(attr.getIdentifier(), "yellow+b"), attr.title())
} else { } else {
fmt.Fprintf(out, "%s %s\n", color("("+attr.getIdentifier()+")", "black+b:white"), color(attr.title(), "default")) if isOutputColored() {
fmt.Fprintf(out, "%s: %s\n", color(attr.getIdentifier(), "green"), color(attr.title(), "default"))
} else {
fmt.Fprintf(out, "[%s]: %s\n", attr.getIdentifier(), attr.title())
}
} }
if len(highlighteds) > 0 { if len(highlighteds) > 0 {
fmt.Fprintln(out, attr.prettyMatches(highlighteds, after)) fmt.Fprintln(out, attr.prettyMatches(highlighteds, after))
@ -516,14 +521,14 @@ func prettyAttr(name, value string) string {
if len(name) > 0 { if len(name) > 0 {
name = name + ":" name = name + ":"
} }
if termutil.Isatty(os.Stdout.Fd()) { if isOutputColored() {
return ansi.Color(name, "black") + ansi.Color(value, "default") return ansi.Color(name, "black") + ansi.Color(value, "default")
} }
return name + value return name + value
} }
func prettyAttr2(name, value string) string { func prettyAttr2(name, value string) string {
if termutil.Isatty(os.Stdout.Fd()) { if isOutputColored() {
return ansi.Color(name+":", "black") + ansi.Color(value, "blue") return ansi.Color(name+":", "black") + ansi.Color(value, "blue")
} }
return name + ":" + value return name + ":" + value
@ -531,12 +536,16 @@ func prettyAttr2(name, value string) string {
// color is the same as ansi.Color but only if STDOUT is a TTY // color is the same as ansi.Color but only if STDOUT is a TTY
func color(str, color string) string { func color(str, color string) string {
if termutil.Isatty(os.Stdout.Fd()) { if isOutputColored() {
return ansi.Color(str, color) return ansi.Color(str, color)
} }
return str return str
} }
func isOutputColored() bool {
return termutil.Isatty(os.Stdout.Fd())
}
func findAttributeByID(db *sql.DB, ID int64) (attr attrStruct) { func findAttributeByID(db *sql.DB, ID int64) (attr attrStruct) {
var err error var err error
var stmt *sql.Stmt var stmt *sql.Stmt

Loading…
Cancel
Save