-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
term: add writeln_color() #24463
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
term: add writeln_color() #24463
Conversation
Connected to Huly®: V_0.6-22833 |
But why? We already have |
I agree with @Delta456 - this should be in import term
...
term.writeln(mut sb, 'hello', styles :[.bold, .italic, .underline], fg: .red, bg : .cyan) |
If so, there is a little confuse jump from a.v module main
import term
import strings
fn main() {
mut sb := strings.new_builder(100)
term.write_color(mut sb, '[Warning]', fg : .red)
sb.write_string('Please make sure ')
term.write_color(mut sb, 'value > 0', fg: .cyan)
sb.write_string(' and ')
term.write_color(mut sb, 'format is string', fg : .cyan)
sb.writeln('')
output := sb.str()
println(output)
} And I prefer build the string in string builder, not just output it directly. |
It makes no logical sense for a specific formatting function (using ANSI escape codes) to be part of the string builder. |
I agree - that is why the first argument is a mutable string builder. That: term.writeln(mut sb, 'hello', styles :[.bold, .italic, .underline], fg: .red, bg : .cyan) is a direct equivalent to your: sb.writeln_color('hello', styles :[.bold, .italic, .underline], fg: .red, bg : .cyan) It will not print anything on its own to stdout, it will just append to the string builder like yours does. |
@medvednikov what do you think? |
I agree with spy here |
The PR add
write_color()
andwriteln_color()
toterm
module, enable output ANSI colorful string.example:
will get output:
