Skip to content

Commit a547166

Browse files
authored
Merge pull request #36 from JuliaLang/cjf/printstyled_update
Some minor cleanups
2 parents 320b036 + 57637f2 commit a547166

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

src/diagnostics.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function show_diagnostic(io::IO, diagnostic::Diagnostic, source::SourceFile)
8989
# a...............
9090
# .....p...q......
9191
# ...............b
92-
_printstyled(io, source[p:q]; color=hicol)
92+
_printstyled(io, source[p:q]; bgcolor=hicol)
9393
else
9494
# Or large and we trucate the code to show only the region around the
9595
# start and end of the error.
@@ -100,9 +100,9 @@ function show_diagnostic(io::IO, diagnostic::Diagnostic, source::SourceFile)
100100
# c...............
101101
# .....q..........
102102
# ...............d
103-
_printstyled(io, source[p:b]; color=hicol)
103+
_printstyled(io, source[p:b]; bgcolor=hicol)
104104
println(io, "")
105-
_printstyled(io, source[c:q]; color=hicol)
105+
_printstyled(io, source[c:q]; bgcolor=hicol)
106106
end
107107
print(io, source[nextind(text,q):d])
108108
println(io)

src/parse_stream.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,15 @@ end
557557
bump(stream [, flags=EMPTY_FLAGS];
558558
skip_newlines=false, error, remap_kind)
559559
560-
Shift the current token from the input to the output, adding the given flags.
560+
Copy the current token from the input stream to the output. Adds the given
561+
flags to the output token (normally this would be the default `EMPTY_FLAGS` or
562+
`TRIVIA_FLAG`).
563+
564+
Keyword arguments:
565+
* `skip_newlines` - if `true`, newlines are treated as whitespace.
566+
* `error` - if set, emit an error for this token
567+
* `remap_kind` - the kind of the token in the output token stream if it needs
568+
to be modified.
561569
"""
562570
function bump(stream::ParseStream, flags=EMPTY_FLAGS; skip_newlines=false,
563571
error=nothing, remap_kind::Kind=K"None")

src/syntax_tree.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ function highlight(code::String, node, path::Int...; color=(40,40,70))
253253
node, p, span = child_position_span(node, path...)
254254
q = p + span
255255
print(stdout, code[1:p-1])
256-
_printstyled(stdout, code[p:q-1]; color=color)
256+
_printstyled(stdout, code[p:q-1]; bgcolor=color)
257257
print(stdout, code[q:end])
258258
end
259259

src/utils.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
"""
33
Like printstyled, but allows providing RGB colors for true color terminals
44
"""
5-
function _printstyled(io::IO, text; color)
6-
if length(color) != 3 || !all(0 .<= color .< 256)
7-
error("Invalid ansi color $color")
5+
function _printstyled(io::IO, text; fgcolor=nothing, bgcolor=nothing)
6+
colcode = ""
7+
if !isnothing(fgcolor)
8+
if length(fgcolor) != 3 || !all(0 .<= fgcolor .< 256)
9+
error("Invalid ansi color $fgcolor")
10+
end
11+
colcode *= "\e[38;2;$(fgcolor[1]);$(fgcolor[2]);$(fgcolor[3])m"
12+
end
13+
if !isnothing(bgcolor)
14+
if length(bgcolor) != 3 || !all(0 .<= bgcolor .< 256)
15+
error("Invalid ansi color $bgcolor")
16+
end
17+
colcode *= "\e[48;2;$(bgcolor[1]);$(bgcolor[2]);$(bgcolor[3])m"
818
end
9-
colcode = "\e[48;2;$(color[1]);$(color[2]);$(color[3])m"
1019
colreset = "\e[0;0m"
1120
first = true
1221
for linepart in split(text, '\n')

0 commit comments

Comments
 (0)