Merge pull request #526 from harshavardhana/pr_out_print_ls_with_special_color_for_directories

This commit is contained in:
Harshavardhana
2015-04-23 21:37:25 -07:00
3 changed files with 19 additions and 14 deletions
+12 -4
View File
@@ -18,6 +18,7 @@ package main
import (
"fmt"
"os"
"time"
"github.com/dustin/go-humanize"
@@ -33,10 +34,16 @@ const (
)
// printItem prints item meta-data
func printItem(date time.Time, v int64, name string) {
func printItem(date time.Time, v int64, name string, fileType os.FileMode) {
fmt.Printf(console.Time("[%s] ", date.Local().Format(printDate)))
fmt.Printf(console.Size("%6s ", humanize.IBytes(uint64(v))))
fmt.Println(console.File("%s", name))
// just making it explicit
if fileType.IsDir() {
fmt.Println(console.Dir("%s/", name))
}
if fileType.IsRegular() {
fmt.Println(console.File("%s", name))
}
}
func doList(clnt client.Client, targetURL string) error {
@@ -46,7 +53,7 @@ func doList(clnt client.Client, targetURL string) error {
err = itemCh.Err
break
}
printItem(itemCh.Item.Time, itemCh.Item.Size, itemCh.Item.Name)
printItem(itemCh.Item.Time, itemCh.Item.Size, itemCh.Item.Name, itemCh.Item.FileType)
}
if err != nil {
@@ -81,7 +88,8 @@ func runListCmd(ctx *cli.Context) {
targetConfig, err := getHostConfig(targetURL)
if err != nil {
log.Debug.Println(iodine.New(err, nil))
console.Fatalf("Unable to read host configuration for [%s] from config file [%s]. Reason: [%s].\n", targetURL, mustGetMcConfigPath(), iodine.ToError(err))
console.Fatalf("Unable to read host configuration for [%s] from config file [%s]. Reason: [%s].\n",
targetURL, mustGetMcConfigPath(), iodine.ToError(err))
}
targetURLConfigMap[targetURL] = targetConfig
}
+4
View File
@@ -70,6 +70,8 @@ var (
// File - File("foo.txt")
File = themesDB[currThemeName].File.SprintfFunc()
// Dir - Dir("dir/")
Dir = themesDB[currThemeName].Dir.SprintfFunc()
// Size - Size("12GB")
Size = themesDB[currThemeName].Size.SprintfFunc()
//Time - Time("12 Hours")
@@ -85,6 +87,7 @@ type Theme struct {
Size *color.Color
Time *color.Color
File *color.Color
Dir *color.Color
// Reason *color.Color
}
@@ -155,6 +158,7 @@ func SetTheme(themeName string) error {
// Debugf prints a debug message with formatting
Debugf = func(f string, a ...interface{}) { printf(theme.Debug, "<DEBUG>", f, a...) }
Dir = theme.Dir.SprintfFunc()
File = theme.File.SprintfFunc()
Size = theme.Size.SprintfFunc()
Time = theme.Time.SprintfFunc()
+3 -10
View File
@@ -19,22 +19,13 @@ package console
import "github.com/fatih/color"
// MiniTheme - Minio's default color theme
/*
var MiniTheme = Theme{
Debug: (color.New(color.FgWhite, color.Faint, color.Italic)),
Fatal: (color.New(color.FgRed, color.Bold, color.Italic)),
Error: (color.New(color.FgYellow, color.Bold, color.Italic)),
Info: (color.New(color.FgGreen, color.Bold)),
File: (color.New(color.FgCyan, color.Bold)),
Size: (color.New(color.FgYellow, color.Bold)),
Time: (color.New(color.FgGreen, color.Bold)),
}*/
var MiniTheme = Theme{
Debug: (color.New(color.FgWhite, color.Faint, color.Italic)),
Fatal: (color.New(color.FgRed, color.Italic, color.Bold)),
Error: (color.New(color.FgYellow, color.Italic)),
Info: (color.New(color.FgGreen, color.Bold)),
File: (color.New(color.FgWhite)),
Dir: (color.New(color.FgCyan, color.Bold)),
Size: (color.New(color.FgYellow)),
Time: (color.New(color.FgGreen)),
}
@@ -46,6 +37,7 @@ var WhiteTheme = Theme{
Error: (color.New(color.FgWhite, color.Bold, color.Italic)),
Info: (color.New(color.FgWhite, color.Bold)),
File: (color.New(color.FgWhite, color.Bold)),
Dir: (color.New(color.FgWhite, color.Bold)),
Size: (color.New(color.FgWhite, color.Bold)),
Time: (color.New(color.FgWhite, color.Bold)),
}
@@ -57,6 +49,7 @@ var NoColorTheme = Theme{
Error: (color.New()),
Info: (color.New()),
File: (color.New()),
Dir: (color.New()),
Size: (color.New()),
Time: (color.New()),
}