-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add color echo functions to stdlib #308
Conversation
We were discussing this morning about this proposal #306 |
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.
Some small changes
that would have to be in its own file tho, since #291 was merged |
c8a6f2e
to
ea2526f
Compare
Just before approve this PR, we have #306 that is proposing a new syntax that will be used for stuff like this PR. We want to have those methods until that syntax get supported? |
I think is not a good idea to use
this means that the user must understand this mechanism to use the echo command this means that user inputs would have to be escaped i think is more easy if |
|
|
I'm still thinking if what I proposed first (to add Example: Sorry for that back and fourth. |
Since
We need to remember to add the newline character in the end though. What do you think? |
this :
fail :
and this :
return this :
i think echo is better than printf |
👍 |
I agree with @CymDeveloppement. I just checked that The solution would be to use text="This is %T a test"
printf "${text//%/%%}\n"
# This is %T a test |
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.
I think that is perfect for now as we are in alpha, in the future a way to change the colors will be needed for the various functions.
now all function use printf, i have also integrate new necessary function. |
printf function can close #271 |
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.
Small changes
src/std/env.ab
Outdated
pub fun text_bold(message: Text): Text { | ||
return "\e[1m{printf_escape(message)}\e[0m" | ||
} | ||
|
||
pub fun text_italic(message: Text): Text { | ||
return "\e[3m{printf_escape(message)}\e[0m" | ||
} | ||
|
||
pub fun text_underlined(message: Text): Text { | ||
return "\e[4m{printf_escape(message)}\e[0m" | ||
} | ||
|
||
pub fun color_echo(message: Text, color: Num): Null { | ||
printf("\e[{color as Text}m%s\e[0m\n", [message]) | ||
} | ||
|
||
pub fun echo_info(message: Text): Null { | ||
printf("\e[1;3;97;44m %s \e[0m\n", [message]) | ||
} | ||
|
||
pub fun echo_success(message: Text): Null { | ||
printf("\e[1;3;97;42m %s \e[0m\n", [message]) | ||
} | ||
|
||
pub fun echo_warning(message: Text): Null { | ||
printf("\e[1;3;97;43m %s \e[0m\n", [message]) | ||
} | ||
|
||
pub fun error(message: Text, exit_code: Num = 1): Null { | ||
printf("\e[1;3;97;41m %s \e[0m\n", [message]) | ||
if exit_code > 0 : exit(exit_code) | ||
} |
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.
Could you change the \e
to \033
? Just so that everything is uniform
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.
\033
not work, i think is a rust problem.
Error: Error { kind: InvalidInput, message: "nul byte found in provided data" }
I used the hexadecimal notation instead
Co-authored-by: Phoenix Himself <[email protected]>
Co-authored-by: Phoenix Himself <[email protected]>
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.
Looks great. Good job
here are some new functions for color echo.
echo functions:
echo_esc
anecho -e
wrapperby default echo do not interpret escaped sequence, and is a good choice.
I think Amber should have the same logic, no escaped sequence by default.
color_echo
print a message with a style codeinfo
display a blue background textsuccess
display a green background textwarning
display a yellow background texterror
display a red background text and exit if exit_code is greater than 0format text functions:
shell_text
return a text sequence with foreground, background and stylebold_text
return a bold text sequenceitalic_text
return a italic text sequenceunderlined_text
return a underlined text sequenceI need your opinion, maybe this is too many function
related to #306 and #290