-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add --color={always,never,auto} flag
#58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| --- create_logger: function( | ||
| --- stream: FILE, | ||
| --- verbosity_threshold: Verbosity, | ||
| --- color_mode: ColorMode, | ||
| --- prefix: string | decoration.Decorated, | ||
| --- cont: string | decoration.Decorated, | ||
| --- inspector: function(any): string | ||
|
|
@@ -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 | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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 | ||
|
|
@@ -348,6 +374,7 @@ local log <const> = { | |
| create_logger = create_logger, | ||
| verbosities = verbosities, | ||
| Verbosity = Verbosity, | ||
| ColorMode = ColorMode, | ||
| Logger = Logger, | ||
| } | ||
|
|
||
|
|
@@ -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) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
color_modeisn't a parameter tocreate_logger, is it meant to be?