Skip to content
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

feat:Make use of coloured output #197

Closed
wants to merge 4 commits into from

Conversation

Pavankumar07s
Copy link

Task 1 completed:Create a first PR that introduce the <unistd.h> approach on a helper in utils.h/utils.cc and maybe just uses it to color code "JSON Schema CLI vX.Y.Z" on the help page. Something super simple and without letting users control it yet.
Screenshot from 2024-11-08 21-36-05

src/messages.h Outdated
@@ -0,0 +1,14 @@
#ifndef MESSAGES_H
Copy link
Member

Choose a reason for hiding this comment

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

Please do if guards in a consistent manner, like the other headers. For example, SOURCEMETA_JSONSCHEMA_CLI_MESSAGES_H_

#ifdef _WIN32
#include <io.h>
#define isatty _isatty
#else
Copy link
Member

Choose a reason for hiding this comment

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

Where are we actually checking for TTY in the code?

Copy link
Author

Choose a reason for hiding this comment

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

Yes

Copy link
Author

@Pavankumar07s Pavankumar07s Nov 9, 2024

Choose a reason for hiding this comment

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

We haven't introduced yet . In this pr i have just inlmported the module for tty and color. In next pr we will introduce condition for tty as cli-program detected then we will continue using colors else we will turn off.

Copy link
Member

Choose a reason for hiding this comment

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

I think you still need the TTY check on this one, otherwise i.e. piping the help text will result in escaped characters

Copy link
Author

Choose a reason for hiding this comment

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

Alright @jviotti 👍

src/main.cc Outdated
@@ -85,101 +92,157 @@ Global Options:

For more documentation, visit https://github.com/sourcemeta/jsonschema
)EOF"};
// Initialize color usage
bool use_colors = true;
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't have a boolean like this. Instead, each command should check the command line arguments + the TTY check.

Copy link
Author

Choose a reason for hiding this comment

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

Alright ,in our code i was just going to check ones when the problem starts.Thankyou for guidance i will make sure it checks each time when command run.

src/main.cc Outdated

auto jsonschema_main(const std::string &program, const std::string &command,
const std::span<const std::string> &arguments) -> int {
if (command == "fmt") {
const std::span<const std::string> &arguments) -> int
Copy link
Member

Choose a reason for hiding this comment

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

All of these changes seem unrelated? They will also break the build, and we check formatting against ClangFormat

Copy link
Author

Choose a reason for hiding this comment

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

Thankyou ,i was also confused i will now use formated code for our simplicity and build.

Copy link
Member

Choose a reason for hiding this comment

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

If you run make on your system that should run ClangFormat as per the project's configuration and always get the formatting right

Copy link
Author

Choose a reason for hiding this comment

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

Yeah i am this one only Thankyou you are great help.😃

src/main.cc Outdated
return EXIT_SUCCESS;
}
}

auto main(int argc, char *argv[]) noexcept -> int {
try {
auto main(int argc, char *argv[]) noexcept -> int
Copy link
Member

Choose a reason for hiding this comment

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

Most of these seem to be unrelated formatting changes?

Copy link
Author

Choose a reason for hiding this comment

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

I am going to revert al these formatting. Thankyou.

src/messages.h Outdated
#include "../include/termcolor/termcolor.hpp"

// Declare color control as an external variable
extern bool use_colors;
Copy link
Member

Choose a reason for hiding this comment

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

We should avoid these kind of global variables, even more extern ones.

Copy link
Author

Choose a reason for hiding this comment

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

Alright @jviotti 👍

src/messages.cc Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Mainly for this PR, I don't think we need these extra helpers. Can you use termcolor on standard streams directly?

Copy link
Author

Choose a reason for hiding this comment

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

Yes we can do but in further steps ,we again have to change .Is is better to define all colors in one messages page so that it would be easy and maintained. Pls share your thoughts.

Copy link
Member

Choose a reason for hiding this comment

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

I think termcolor interface is already quite concise and we could use it directly when needed.

Copy link
Author

Choose a reason for hiding this comment

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

Alright @jviotti 👍

Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't be including untracked external dependencies. Please add them using DEPENDENCIES and https://github.com/sourcemeta/vendorpull

Copy link
Member

Choose a reason for hiding this comment

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

And once you add it like that, you will need to pull the dependency using CMake's find_package, like we do for other dependencies

Copy link
Author

Choose a reason for hiding this comment

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

yeaah i got it .Thankyou.

Copy link
Member

@jviotti jviotti left a comment

Choose a reason for hiding this comment

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

Left a few comments

src/main.cc Outdated

print_success("Usage: " + std::filesystem::path{program}.filename().string() + " <command> [arguments...]");

print_success(std::string(USAGE_DETAILS));
Copy link
Member

Choose a reason for hiding this comment

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

We probably shouldn't colorise the entire thing. Maybe just colorise the usage line above or something like that?

Copy link
Author

Choose a reason for hiding this comment

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

Lets just color the usage part.

@Pavankumar07s
Copy link
Author

Hiii @jviotti whats i am doing wrong ? When i am using make command it is showing 100% test passes but the workflow is breaking...can you guide me.
Screenshot from 2024-11-13 13-13-32
Screenshot from 2024-11-13 12-54-46
Screenshot from 2024-11-13 12-55-05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants