Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b49ed16
Improve Colorize
Apr 18, 2019
2e6cdf4
Improve mode documentation
Apr 18, 2019
69d64e8
Make Colorize::Object#surround public again
Apr 18, 2019
702c6f2
Change Spec::COLORS to use the enum members
Apr 18, 2019
64cf180
Rename some variables and add documentation to surround
Apr 18, 2019
c22e57c
Fix specs
Apr 18, 2019
9432a4c
Fix specs
Apr 18, 2019
38ef634
Remove (*args)
Apr 18, 2019
f0cac30
Make RGB colorize's arguments more explicit
Apr 18, 2019
80180f0
Use color enum members in 2048.cr
Apr 18, 2019
e3b84b6
Add back Colorize::Object(T)#on and remove some documentation
Apr 18, 2019
ef19001
Remove unneeded parentheses and avoid capitalize in macro
Apr 18, 2019
743a6a9
Improve documentation
Apr 19, 2019
6425ad9
Fix Mode enum
Apr 19, 2019
c0f4405
Remove COLORS and MODES and use ColorANSI and Mode
Apr 24, 2019
8042ed4
More documentation
May 13, 2019
0f84ac8
Fix specs
May 13, 2019
ba56508
Remove the private attribute from two methods
May 13, 2019
d8ce0ce
Minor documentation improvements
May 13, 2019
d8d271b
Merge branch 'master' into patch-29
Sep 28, 2019
a9fda36
Add a missing comma
Sep 28, 2019
95569e2
Remove bright
Sep 28, 2019
c81322c
Don't generate all and none methods
Sep 28, 2019
94fc12e
Add bright back but deprecate it
Sep 28, 2019
fedd9d3
Commit Sija's suggestion
Sep 29, 2019
073e2d7
Remove useless `u8`s, fix the warning message and improve docs
Sep 29, 2019
830d994
Improve an example
Dec 22, 2019
0f2470b
Merge branch 'master' into patch-29
Dec 22, 2019
3c453bf
Remove on_tty_only!
Dec 22, 2019
16aa6fb
Merge branch 'master' into patch-29
Apr 22, 2021
9f19d98
Re-add on_tty_only!
Apr 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions samples/2048.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
require "colorize"

module Screen
alias Color = Colorize::ColorANSI

TILES = {
0 => {:white, nil},
2 => {:black, :white},
4 => {:blue, :white},
8 => {:black, :yellow},
16 => {:white, :red},
32 => {:black, :red},
64 => {:white, :magenta},
128 => {:red, :yellow},
256 => {:magenta, :yellow},
512 => {:white, :yellow},
1024 => {:white, :yellow},
2048 => {:white, :yellow},
4096 => {:white, :black},
8192 => {:white, :black},
16384 => {:white, :black},
32768 => {:white, :black},
65536 => {:white, :black},
0 => {Color::White, nil},
2 => {Color::Black, Color::White},
4 => {Color::Blue, Color::White},
8 => {Color::Black, Color::Yellow},
16 => {Color::White, Color::Red},
32 => {Color::Black, Color::Red},
64 => {Color::White, Color::Magenta},
128 => {Color::Red, Color::Yellow},
256 => {Color::Magenta, Color::Yellow},
512 => {Color::White, Color::Yellow},
1024 => {Color::White, Color::Yellow},
2048 => {Color::White, Color::Yellow},
4096 => {Color::White, Color::Black},
8192 => {Color::White, Color::Black},
16384 => {Color::White, Color::Black},
32768 => {Color::White, Color::Black},
65536 => {Color::White, Color::Black},
}

def self.colorize_for(tile)
Expand Down
35 changes: 8 additions & 27 deletions spec/std/colorize_spec.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "spec"
require "colorize"

private def colorize(obj, *args)
obj.colorize(*args).toggle(true)
private def colorize(obj)
obj.colorize.toggle(true)
end

private def with_color_wrap(*args)
Expand Down Expand Up @@ -42,11 +42,11 @@ describe "colorize" do
end

it "colorizes foreground with 8-bit color" do
colorize("hello").fore(Colorize::Color256.new(123u8)).to_s.should eq("\e[38;5;123mhello\e[0m")
colorize("hello").fore(Colorize::Color256.new(123)).to_s.should eq("\e[38;5;123mhello\e[0m")
end

it "colorizes foreground with true color" do
colorize("hello").fore(Colorize::ColorRGB.new(12u8, 34u8, 56u8)).to_s.should eq("\e[38;2;12;34;56mhello\e[0m")
colorize("hello").fore(Colorize::ColorRGB.new(12, 34, 56)).to_s.should eq("\e[38;2;12;34;56mhello\e[0m")
end

it "colorizes background" do
Expand All @@ -69,16 +69,15 @@ describe "colorize" do
end

it "colorizes background with 8-bit color" do
colorize("hello").back(Colorize::Color256.new(123u8)).to_s.should eq("\e[48;5;123mhello\e[0m")
colorize("hello").back(Colorize::Color256.new(123)).to_s.should eq("\e[48;5;123mhello\e[0m")
end

it "colorizes background with true color" do
colorize("hello").back(Colorize::ColorRGB.new(12u8, 34u8, 56u8)).to_s.should eq("\e[48;2;12;34;56mhello\e[0m")
colorize("hello").back(Colorize::ColorRGB.new(12, 34, 56)).to_s.should eq("\e[48;2;12;34;56mhello\e[0m")
end

it "colorizes mode" do
colorize("hello").bold.to_s.should eq("\e[1mhello\e[0m")
colorize("hello").bright.to_s.should eq("\e[1mhello\e[0m")
colorize("hello").dim.to_s.should eq("\e[2mhello\e[0m")
colorize("hello").underline.to_s.should eq("\e[4mhello\e[0m")
colorize("hello").blink.to_s.should eq("\e[5mhello\e[0m")
Expand All @@ -99,34 +98,16 @@ describe "colorize" do
end

it "colorizes foreground with symbol" do
colorize("hello", :red).to_s.should eq("\e[31mhello\e[0m")
colorize("hello").fore(:red).to_s.should eq("\e[31mhello\e[0m")
colorize("hello").fore(:red).to_s.should eq("\e[31mhello\e[0m")
end

it "colorizes mode with symbol" do
colorize("hello").mode(:bold).to_s.should eq("\e[1mhello\e[0m")
end

it "raises on unknown foreground color" do
expect_raises ArgumentError, "Unknown color: brown" do
colorize("hello", :brown)
end
end

it "raises on unknown background color" do
expect_raises ArgumentError, "Unknown color: brown" do
colorize("hello").back(:brown)
end
end

it "raises on unknown mode" do
expect_raises ArgumentError, "Unknown mode: bad" do
colorize("hello").mode(:bad)
end
end

it "inspects" do
colorize("hello", :red).inspect.should eq("\e[31m\"hello\"\e[0m")
colorize("hello").fore(:red).inspect.should eq("\"\\e[31mhello\\e[0m\"")
end

it "colorizes with surround" do
Expand Down
Loading