Skip to content

Commit

Permalink
fix for 1.0 (#23)
Browse files Browse the repository at this point in the history
* fix for 1.0

* fix AV
  • Loading branch information
KristofferC authored Aug 9, 2018
1 parent 507ef21 commit bef1ad1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 52 deletions.
10 changes: 8 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name = "Crayons"
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
version = "0.5.0"
version = "1.0.0"

[compat]
julia = "0.7"
julia = "0.7, 1.0"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ print(GREEN_FG(

## Misc

The Base function `print_with_color` is extended so that the first argument can also be a `Crayon`.

The function `inv` on a `Crayon` returns a `Crayon` that undos what the `Crayon` in the argument to `inv` does.
As an example, `inv(Crayon(bold = true))` returns a `Crayon` that disables bold.

Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.7-
julia 0.7 2.0
34 changes: 19 additions & 15 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1.0
- julia_version: latest

platform:
- x86 # 32-bit
- x64 # 64-bit

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - julia_version: latest

branches:
only:
- master
Expand All @@ -16,18 +26,12 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
- C:\projects\julia\bin\julia -e "
import InteractiveUtils; versioninfo();
import Pkg; Pkg.build()"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test()"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
22 changes: 4 additions & 18 deletions src/crayon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ struct Crayon
strikethrough::ANSIStyle
end

anyactive(x::Crayon) = ((x.reset.active && x.reset.on) || x.fg.active || x.bg.active || x.bold.active || x.faint.active ||
x.italics.active || x.underline.active || x.blink.active || x.negative.active || x.conceal.active || x.strikethrough.active)
anyactive(x::Crayon) = ((x.reset.active && x.reset.on) ||
x.fg.active || x.bg.active || x.bold.active ||
x.faint.active || x.italics.active || x.underline.active ||
x.blink.active || x.negative.active || x.conceal.active || x.strikethrough.active)

Base.inv(c::Crayon) = Crayon(inv(c.fg), inv(c.bg), ANSIStyle(), # no point taking inverse of reset,
inv(c.bold), inv(c.faint), inv(c.italics), inv(c.underline),
Expand Down Expand Up @@ -270,22 +272,6 @@ function Base.merge(toks::Crayon...)
return tok
end

function Base.with_output_color(f::Function, crayon::Crayon, io::IO, args...)
buf = IOBuffer()
print(buf, crayon)
try f(buf, args...)
finally
print(buf, inv(crayon))
print(io, String(take!(buf)))
end
end

Base.print_with_color(crayon::Crayon, io::IO, msg::AbstractString...) =
Base.with_output_color(print, crayon, io, msg...)
Base.print_with_color(crayon::Crayon, msg::AbstractString...) =
print_with_color(crayon, stdout, msg...)


# 24bit -> 256 colors
function _to256(crayon::Crayon)
fg = crayon.fg
Expand Down
2 changes: 1 addition & 1 deletion src/crayon_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end
function (c::Crayon)(args::Union{CrayonWrapper,AbstractString}...)
typefix(cw::CrayonWrapper) = cw
typefix(str) = String(str)

CrayonWrapper(c, typefix.(collect(args)))
end

Expand Down
2 changes: 1 addition & 1 deletion src/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ function _parse_color_string(token::AbstractString)
end

throw(ArgumentError("could not parse $token as a color"))
end
end
13 changes: 1 addition & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using Crayons
using Crayons.Box

if VERSION < v"0.7.0-DEV.2005"
using Base.Test
else
using Test
end
using Test

withenv("FORCE_COLOR" => true) do

Expand Down Expand Up @@ -73,7 +68,6 @@ withenv("FORCE_256_COLORS" => true) do
@test string(crayon"(0,0,255)") == string(Crayon(foreground = 21))
@test string(crayon"fg:(0,0,255) bg:(255,0,255)") == string(Crayon(foreground = 21, background = 201))
end


# CrayonStack
cs = CrayonStack()
Expand Down Expand Up @@ -126,11 +120,6 @@ pop!(cs) # State change: fg = default

string(BLACK_BG * WHITE_FG * BOLD) == string(Crayon(foreground = :white, background = :black, bold = true))

# print_with_color
io = IOBuffer()
print_with_color(Crayon(foreground = :red), io, "haho")
@test String(take!(io)) == string(Crayon(foreground = :red), "haho", inv(Crayon(foreground = :red)))

# Call overloading
@test string(Crayon()("hello")) == "hello"
@test string(Crayon()(split("hello world")[1])) == "hello" # test substrings
Expand Down

0 comments on commit bef1ad1

Please sign in to comment.