Skip to content

Commit

Permalink
clg: nicer layout by integrating progress bar into "box" output
Browse files Browse the repository at this point in the history
  • Loading branch information
Claude Gex committed Mar 21, 2018
1 parent e6fced9 commit f85ac72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
21 changes: 15 additions & 6 deletions AareGuru.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
"os"
"sync"
"strconv"
)

const progressBarCount = 100
Expand All @@ -28,6 +29,7 @@ func main() {

InitConsole(!*colorless)
ClearConsole()
fmt.Println()

aareGuruResponseChannel := make(chan api.AareGuruResponse)
errChannel := make(chan string)
Expand Down Expand Up @@ -55,8 +57,8 @@ func main() {
}()

aareGuruResponse := readData(aareGuruResponseChannel, errChannel, bar, &wg)

fmt.Println()
fmt.Println(output_simple.Box_horizontal_line())
output_simple.PrintBanner()
output_simple.PrintOutput(*aareGuruResponse)
}
Expand Down Expand Up @@ -88,9 +90,6 @@ func readData(aareGuruResponseChannel chan api.AareGuruResponse, errChannel chan
wg.Wait()
stopBar()

fmt.Println(CGreen(texts.Success_msg))
fmt.Println()

return aareGuruResponse
}

Expand All @@ -107,10 +106,20 @@ func createBar() *uiprogress.Bar {
return nil;
}

fmt.Println(output_simple.Box_horizontal_line())
bar := uiprogress.AddBar(progressBarCount).AppendCompleted().PrependElapsed()
bar.Width = 45
bar.PrependFunc(func(b *uiprogress.Bar) string {
return fmt.Sprintf("%s (%d/%d)", texts.Loading_msg, b.Current(), progressBarCount)
msg := texts.Loading_msg
len := 9
if b.Current() == progressBarCount {
msg = CGreen(texts.Success_msg)
len += output_simple.ColorCharsLength(CGreen(""))
}
return fmt.Sprintf("| %-" + strconv.Itoa(len) + "s %3d", msg, b.Current())
})
bar.AppendFunc(func(b *uiprogress.Bar) string {
return fmt.Sprintf("|")
})
uiprogress.Start()
return bar
Expand Down
14 changes: 7 additions & 7 deletions output/output_simple/SimpleOutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func PrintOutput(aareGuruResponse api.AareGuruResponse) {

func printLastUpdateInformation(t time.Time, weather api.Weather) {
fmt.Println(box(fmt.Sprintf("%-13s | %02d:%02d - %02d.%02d.%04d (%s)", texts.Current_title, t.Hour(), t.Minute(), t.Day(), t.Month(), t.Year(), weather.Location)))
fmt.Println(box_horizontal_line())
fmt.Println(Box_horizontal_line())
}

func printAareTemperatureAndFlow(aare api.Aare) {
Expand Down Expand Up @@ -61,13 +61,13 @@ func printAareTemperatureAndFlow(aare api.Aare) {
}

func printNVA(weatherToday api.WeatherToday) {
fmt.Println(box_horizontal_line())
fmt.Println(Box_horizontal_line())
fmt.Println(nva_row(texts.Nva_title_1st_row, texts.Nva_morning, weatherToday.V))
fmt.Println(nva_row(texts.Nva_title_2nd_row, texts.Nva_afternoon, weatherToday.N))
fmt.Println(nva_row("", texts.Nva_evening, weatherToday.A))
fmt.Println(box_horizontal_line())
fmt.Println(Box_horizontal_line())
fmt.Println(box(fmt.Sprintf(texts.Nva_caption)))
fmt.Println(box_horizontal_line())
fmt.Println(Box_horizontal_line())
}

func nva_row(col1_text string, col2_text string, info api.WeatherInfos) string {
Expand All @@ -78,15 +78,15 @@ func nva_row(col1_text string, col2_text string, info api.WeatherInfos) string {
return box(fmt.Sprintf("%-13s | %s | %s", col1, col2, col3), CRed(""), CGreen(""), CBrown(""))
}

func box_horizontal_line() string {
func Box_horizontal_line() string {
return "+------------------------------------------------------------------------+"
}

func box(str string, colorChars ...string) string {
return fmt.Sprintf("| %-"+strconv.Itoa(70+colorCharsLength(colorChars...))+"s |", str)
return fmt.Sprintf("| %-"+strconv.Itoa(70+ColorCharsLength(colorChars...))+"s |", str)
}

func colorCharsLength(colorChars ...string) int {
func ColorCharsLength(colorChars ...string) int {
var colorCharsLen = 0
for _, element := range colorChars {
colorCharsLen += len(element)
Expand Down

0 comments on commit f85ac72

Please sign in to comment.