Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion build/cyan/cli.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/cyan/command.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/cyan/config.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build/cyan/decoration.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/cyan/fs/path.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/cyan/graph.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 35 additions & 2 deletions build/cyan/log.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/cyan/script.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/cyan/tlcommon.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build/testing/temporary-files.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/cyan/cli.tl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ parser:option("--gen-target", "Minimum targeted Lua version for generated code."
parser:flag("--no-script", "Do not run any scripts.")
:action(script.disable)

parser:option("--color", "Colorize the output.", nil, nil, nil, nil)
:choices({ "never", "always", "auto" })
:default("auto")
:action(function(_: argparse.Args, __: string, val: string|boolean|{string})
log.set_color_mode(val as log.ColorMode)
end)

parser:mutex(
parser:flag("-q --quiet", "Do not print information messages to stdout. Errors may still be printed to stderr. (Same as --verbosity quiet).")
:action(function()
Expand Down
33 changes: 33 additions & 0 deletions src/cyan/log.tl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
--- create_logger: function(
--- stream: FILE,
--- verbosity_threshold: Verbosity,
--- color_mode: ColorMode,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

color_mode isn't a parameter to create_logger, is it meant to be?

--- prefix: string | decoration.Decorated,
--- cont: string | decoration.Decorated,
--- inspector: function(any): string
Expand Down Expand Up @@ -65,7 +66,16 @@ local verbosity_to_int <total>: {Verbosity:integer} = {
debug = 3,
}

---@desc
--- Whether to apply color to the output
local enum ColorMode
"always"
"never"
"auto"
end

local verbosity: Verbosity = "normal"
local color_mode: ColorMode = "auto"
local prefix_padding: integer = 10

local inspect: function(any): string
Expand Down Expand Up @@ -101,6 +111,22 @@ local function is_a_tty(file: FILE): boolean
end

local function renderer(stream: FILE): decoration.Renderer
if color_mode == "always" then
if not is_a_tty(stream) then
return function(buf: {string}, content: string, decor: decoration.Decoration)
if decor then
decor.linked_uri = nil
end
Comment on lines +117 to +119
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably fine in practice, but I'm not a huge fan of modifying arguments like this. Not saying that this is a blocker, but maybe render_ansi could take another parameter like dont_render_uris: boolean or something.

decoration.render_ansi(buf, content, decor)
end
end

return decoration.render_ansi
end
if color_mode == "never" then
return decoration.render_plain
end

if no_color_env or not is_a_tty(stream) then
return decoration.render_plain
end
Expand Down Expand Up @@ -348,6 +374,7 @@ local log <const> = {
create_logger = create_logger,
verbosities = verbosities,
Verbosity = Verbosity,
ColorMode = ColorMode,
Logger = Logger,
}

Expand All @@ -357,6 +384,12 @@ function log.set_verbosity(level: Verbosity)
verbosity = level
end

---@desc
--- Globally set the color behavior of the logging module.
function log.set_color_mode(mode: ColorMode)
color_mode = mode
end

---@desc
--- Globally set the padding of the prefixes of loggers.
function log.set_prefix_padding(padding: integer)
Expand Down
Loading