-
Notifications
You must be signed in to change notification settings - Fork 3
Add colours to status subcommand #41
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4356f4e
add colours to status subcommand
SandrineP 3ba11a4
address review comment
SandrineP 533d019
remove useless comments
SandrineP 7d2526f
switch to use termcolor
SandrineP d685503
fix log colour
SandrineP 5734f5d
remove useless include
SandrineP c9f599b
remove useleess space
SandrineP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,16 +45,16 @@ struct status_messages | |
| const std::map<git_status_t, status_messages> status_msg_map = //TODO : check spaces in short_mod | ||
| { | ||
| { GIT_STATUS_CURRENT, {"", ""} }, | ||
| { GIT_STATUS_INDEX_NEW, {"A ", "\t new file:"} }, | ||
| { GIT_STATUS_INDEX_MODIFIED, {"M ", "\t modified:"} }, | ||
| { GIT_STATUS_INDEX_DELETED, {"D ", "\t deleted:"} }, | ||
| { GIT_STATUS_INDEX_RENAMED, {"R ", "\t renamed:"} }, | ||
| { GIT_STATUS_INDEX_TYPECHANGE, {"T ", "\t typechange:"} }, | ||
| { GIT_STATUS_INDEX_NEW, {"A ", "\tnew file:"} }, | ||
| { GIT_STATUS_INDEX_MODIFIED, {"M ", "\tmodified:"} }, | ||
| { GIT_STATUS_INDEX_DELETED, {"D ", "\tdeleted:"} }, | ||
| { GIT_STATUS_INDEX_RENAMED, {"R ", "\trenamed:"} }, | ||
| { GIT_STATUS_INDEX_TYPECHANGE, {"T ", "\ttypechange:"} }, | ||
| { GIT_STATUS_WT_NEW, {"?? ", ""} }, | ||
| { GIT_STATUS_WT_MODIFIED, {" M " , "\t modified:"} }, | ||
| { GIT_STATUS_WT_DELETED, {" D ", "\t deleted:"} }, | ||
| { GIT_STATUS_WT_TYPECHANGE, {" T ", "\t typechange:"} }, | ||
| { GIT_STATUS_WT_RENAMED, {" R ", "\t renamed:"} }, | ||
| { GIT_STATUS_WT_MODIFIED, {" M " , "\tmodified:"} }, | ||
| { GIT_STATUS_WT_DELETED, {" D ", "\tdeleted:"} }, | ||
| { GIT_STATUS_WT_TYPECHANGE, {" T ", "\ttypechange:"} }, | ||
| { GIT_STATUS_WT_RENAMED, {" R ", "\trenamed:"} }, | ||
| { GIT_STATUS_WT_UNREADABLE, {"", ""} }, | ||
| { GIT_STATUS_IGNORED, {"!! ", ""} }, | ||
| { GIT_STATUS_CONFLICTED, {"", ""} }, | ||
|
|
@@ -73,7 +73,7 @@ struct print_entry | |
| std::string item; | ||
| }; | ||
|
|
||
| std::string get_print_status(git_status_t status, output_format of) | ||
| std::string get_print_status(git_status_t status, output_format of) //TODO: add colours, but depends on the status, so needs another parameter | ||
| { | ||
| std::string entry_status; | ||
| if ((of == output_format::DEFAULT) || (of == output_format::LONG)) | ||
|
|
@@ -100,7 +100,7 @@ void update_tracked_dir_set(const char* old_path, const char* new_path, std::set | |
| } | ||
| } | ||
|
|
||
| std::string get_print_item(const char* old_path, const char* new_path) | ||
| std::string get_print_item(const char* old_path, const char* new_path) //TODO: add colours, but depends on the status, so needs another parameter | ||
| { | ||
| std::string entry_item; | ||
| if (old_path && new_path && std::strcmp(old_path, new_path)) | ||
|
|
@@ -139,24 +139,27 @@ std::vector<print_entry> get_entries_to_print(git_status_t status, status_list_w | |
| return entries_to_print; | ||
| } | ||
|
|
||
| void print_entries(std::vector<print_entry> entries_to_print) | ||
| void print_entries(std::vector<print_entry> entries_to_print, bool is_long, std::string colour) | ||
| { | ||
| for (auto e: entries_to_print) | ||
| { | ||
| std::cout << e.status << e.item << std::endl; | ||
| if (is_long) | ||
| std::cout << colour << e.status << e.item << message_colour.at("colour_close") << std::endl; | ||
|
||
| else | ||
| std::cout << colour << e.status << message_colour.at("colour_close") << e.item << std::endl; | ||
| } | ||
| } | ||
|
|
||
| void print_not_tracked(const std::vector<print_entry>& entries_to_print, const std::set<std::string>& tracked_dir_set, | ||
| std::set<std::string>& untracked_dir_set) | ||
| std::set<std::string>& untracked_dir_set, bool is_long, std::string colour) | ||
| { | ||
| std::vector<print_entry> not_tracked_entries_to_print{}; | ||
| for (auto e: entries_to_print) | ||
| { | ||
| const size_t first_slash_idx = e.item.find('/'); | ||
| if (std::string::npos != first_slash_idx) | ||
| { | ||
| auto directory = e.item.substr(0, first_slash_idx); | ||
| auto directory = e.item.substr(0, first_slash_idx) + "/"; | ||
| if (tracked_dir_set.contains(directory)) | ||
| { | ||
| not_tracked_entries_to_print.push_back(e); | ||
|
|
@@ -177,7 +180,7 @@ void print_not_tracked(const std::vector<print_entry>& entries_to_print, const s | |
| not_tracked_entries_to_print.push_back(e); | ||
| } | ||
| } | ||
| print_entries(not_tracked_entries_to_print); | ||
| print_entries(not_tracked_entries_to_print, is_long, colour); | ||
| } | ||
|
|
||
| void status_subcommand::run() | ||
|
|
@@ -220,17 +223,19 @@ void status_subcommand::run() | |
| std::cout << "## " << branch_name << std::endl; | ||
| } | ||
| } | ||
|
|
||
| if (sl.has_tobecommited_header()) | ||
| { | ||
| std::string colour = message_colour.at("green"); | ||
| if (is_long) | ||
| { | ||
| std::cout << tobecommited_header << std::endl; | ||
| } | ||
| print_entries(get_entries_to_print(GIT_STATUS_INDEX_NEW, sl, true, of, &tracked_dir_set)); | ||
| print_entries(get_entries_to_print(GIT_STATUS_INDEX_MODIFIED, sl, true, of, &tracked_dir_set)); | ||
| print_entries(get_entries_to_print(GIT_STATUS_INDEX_DELETED, sl, true, of, &tracked_dir_set)); | ||
| print_entries(get_entries_to_print(GIT_STATUS_INDEX_RENAMED, sl, true, of, &tracked_dir_set)); | ||
| print_entries(get_entries_to_print(GIT_STATUS_INDEX_TYPECHANGE, sl, true, of, &tracked_dir_set)); | ||
| print_entries(get_entries_to_print(GIT_STATUS_INDEX_NEW, sl, true, of, &tracked_dir_set), is_long, colour); | ||
| print_entries(get_entries_to_print(GIT_STATUS_INDEX_MODIFIED, sl, true, of, &tracked_dir_set), is_long, colour); | ||
| print_entries(get_entries_to_print(GIT_STATUS_INDEX_DELETED, sl, true, of, &tracked_dir_set), is_long, colour); | ||
| print_entries(get_entries_to_print(GIT_STATUS_INDEX_RENAMED, sl, true, of, &tracked_dir_set), is_long, colour); | ||
| print_entries(get_entries_to_print(GIT_STATUS_INDEX_TYPECHANGE, sl, true, of, &tracked_dir_set), is_long, colour); | ||
| if (is_long) | ||
| { | ||
| std::cout << std::endl; | ||
|
|
@@ -239,44 +244,46 @@ void status_subcommand::run() | |
|
|
||
| if (sl.has_notstagged_header()) | ||
| { | ||
| std::string colour = message_colour.at("red"); | ||
| if (is_long) | ||
| { | ||
| std::cout << notstagged_header << std::endl; | ||
| } | ||
| print_entries(get_entries_to_print(GIT_STATUS_WT_MODIFIED, sl, false, of, &tracked_dir_set)); | ||
| print_entries(get_entries_to_print(GIT_STATUS_WT_DELETED, sl, false, of, &tracked_dir_set)); | ||
| print_entries(get_entries_to_print(GIT_STATUS_WT_TYPECHANGE, sl, false, of, &tracked_dir_set)); | ||
| print_entries(get_entries_to_print(GIT_STATUS_WT_RENAMED, sl, false, of, &tracked_dir_set)); | ||
| print_entries(get_entries_to_print(GIT_STATUS_WT_MODIFIED, sl, false, of, &tracked_dir_set), is_long, colour); | ||
| print_entries(get_entries_to_print(GIT_STATUS_WT_DELETED, sl, false, of, &tracked_dir_set), is_long, colour); | ||
| print_entries(get_entries_to_print(GIT_STATUS_WT_TYPECHANGE, sl, false, of, &tracked_dir_set), is_long, colour); | ||
| print_entries(get_entries_to_print(GIT_STATUS_WT_RENAMED, sl, false, of, &tracked_dir_set), is_long, colour); | ||
| if (is_long) | ||
| { | ||
| std::cout << std::endl; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| if (sl.has_untracked_header()) | ||
| { | ||
| std::string colour = message_colour.at("red"); | ||
| if (is_long) | ||
| { | ||
| std::cout << untracked_header << std::endl; | ||
| } | ||
| print_not_tracked(get_entries_to_print(GIT_STATUS_WT_NEW, sl, false, of), tracked_dir_set, untracked_dir_set); | ||
| print_not_tracked(get_entries_to_print(GIT_STATUS_WT_NEW, sl, false, of), tracked_dir_set, untracked_dir_set, is_long, colour); | ||
| if (is_long) | ||
| { | ||
| std::cout << std::endl; | ||
| } | ||
| } | ||
|
|
||
| if (sl.has_ignored_header()) | ||
| { | ||
| if (is_long) | ||
| { | ||
| std::cout << ignored_header << std::endl; | ||
| } | ||
| print_not_tracked(get_entries_to_print(GIT_STATUS_IGNORED, sl, false, of), tracked_dir_set, untracked_dir_set); | ||
| if (is_long) | ||
| { | ||
| std::cout << std::endl; | ||
| } | ||
| } | ||
| // if (sl.has_ignored_header()) | ||
| // { | ||
| // std::string colour = message_colour.at("red"); | ||
| // if (is_long) | ||
| // { | ||
| // std::cout << ignored_header << std::endl; | ||
| // } | ||
| // print_not_tracked(get_entries_to_print(GIT_STATUS_IGNORED, sl, false, of), tracked_dir_set, untracked_dir_set, is_long, colour); | ||
| // if (is_long) | ||
| // { | ||
| // std::cout << std::endl; | ||
| // } | ||
| // } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice to see use of
colourrather thancolor!