From 1889a4623b8146b34631bfc701f3d57fac1687e5 Mon Sep 17 00:00:00 2001 From: Daniel Byron Date: Mon, 22 Aug 2016 09:28:14 +1000 Subject: Removed abort on less than 16 colors generated Now when the number of colors generated is less than 16, the sequence of generated colors will be repeated to fill 16 colors. --- main.go | 15 ++++++++++----- tests/Terminals/xterm/test-10colors | 11 +++++++++++ tests/Terminals/xterm/test-4colors | 5 +++++ tests/Terminals/xterm/test-8colors | 9 +++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/Terminals/xterm/test-10colors create mode 100644 tests/Terminals/xterm/test-4colors create mode 100644 tests/Terminals/xterm/test-8colors diff --git a/main.go b/main.go index 8ae1e34..afdbfdf 100644 --- a/main.go +++ b/main.go @@ -204,12 +204,17 @@ func main() { return } - // Ensure there are 16 colors - if len(colors) > 16 { + // Keep track of the original number of colors + // In case we need to add more to meet 16 + num_colors := len(colors) + if num_colors > 16 { + // Truncate the list down to 16 colors = colors[:16] - } else if len(colors) < 16 { - // TODO: Should this just be a warning (for cases where only 8 colors are defined?) - log.Fatal("Less than 16 colors. Aborting.") + } else if num_colors < 16 { + // In the case that less than 16 colors are generated, repeat the sequence. + for i := 0; i < 16-num_colors; i++ { + colors = append(colors, colors[i%num_colors]) + } } // Output the configuration for terminal, or image diff --git a/tests/Terminals/xterm/test-10colors b/tests/Terminals/xterm/test-10colors new file mode 100644 index 0000000..b88eb8b --- /dev/null +++ b/tests/Terminals/xterm/test-10colors @@ -0,0 +1,11 @@ +! Terminal colors +*color0: #000211 +*color1: #bb0454 +*color2: #32b792 +*color3: #db9b64 +*color4: #15547b +*color5: #910957 +*color6: #81148e +*color7: #cacaca +*color8: #282a3b +*color9: #cd236d diff --git a/tests/Terminals/xterm/test-4colors b/tests/Terminals/xterm/test-4colors new file mode 100644 index 0000000..b737af9 --- /dev/null +++ b/tests/Terminals/xterm/test-4colors @@ -0,0 +1,5 @@ +! Terminal colors +*color0: #000211 +*color1: #bb0454 +*color2: #32b792 +*color3: #db9b64 diff --git a/tests/Terminals/xterm/test-8colors b/tests/Terminals/xterm/test-8colors new file mode 100644 index 0000000..6764357 --- /dev/null +++ b/tests/Terminals/xterm/test-8colors @@ -0,0 +1,9 @@ +! Terminal colors +*color0: #000211 +*color1: #bb0454 +*color2: #32b792 +*color3: #db9b64 +*color4: #15547b +*color5: #910957 +*color6: #81148e +*color7: #cacaca -- cgit v1.2.3