From adef0057a939ab9b71907d378c9af5fc97edad36 Mon Sep 17 00:00:00 2001 From: Roi Martin Date: Sun, 13 Nov 2016 20:46:02 +0100 Subject: [PATCH] Add more tests to _examples/colors256.go --- _examples/colors256.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/_examples/colors256.go b/_examples/colors256.go index cf12888..3abd423 100644 --- a/_examples/colors256.go +++ b/_examples/colors256.go @@ -37,20 +37,33 @@ func layout(g *gocui.Gui) error { return err } - var count int - for i := 1; i <= 255; i++ { - count++ + // 256-colors escape codes + for i := 0; i < 256; i++ { + str := fmt.Sprintf("\x1b[48;5;%dm\x1b[30m%3d\x1b[0m ", i, i) + str += fmt.Sprintf("\x1b[38;5;%dm%3d\x1b[0m ", i, i) - block := fmt.Sprintf("\x1b[48;5;%dm%3s\x1b[0m", i, " ") - str := fmt.Sprintf("\x1b[38;5;%dm%3d %s\x1b[0m\t", i, i, block) - - if count == 10 { - str += "\n\n" - count = 0 + if (i+1)%10 == 0 { + str += "\n" } fmt.Fprint(v, str) + } + fmt.Fprint(v, "\n\n") + + // 8-colors escape codes + ctr := 0 + for i := 0; i <= 7; i++ { + for _, j := range []int{1, 4, 7} { + str := fmt.Sprintf("\x1b[3%d;%dm%d:%d\x1b[0m ", i, j, i, j) + if (ctr+1)%20 == 0 { + str += "\n" + } + + fmt.Fprint(v, str) + + ctr++ + } } } return nil