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

Autoscroll colorify compiler output #1139

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/tig/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct ref;
*/

#define LINE_INFO(_) \
_(COMPILER_MSG, ""), \
_(DIFF_HEADER, "diff --"), \
_(DIFF_DEL_FILE, "--- "), \
_(DIFF_ADD_FILE, "+++ "), \
Expand Down
21 changes: 21 additions & 0 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,33 @@ diff_common_highlight(struct view *view, const char *text, enum line_type type)
bool
diff_common_read(struct view *view, const char *data, struct diff_state *state)
{
const char *regex_txt;
regex_t regex;
regmatch_t pmatch[10];
int regex_flags = REG_EXTENDED, regex_err;
enum line_type type = get_line_type(data);

/* ADD2 and DEL2 are only valid in combined diff hunks */
if (!state->combined_diff && (type == LINE_DIFF_ADD2 || type == LINE_DIFF_DEL2))
type = LINE_DEFAULT;


if (type == LINE_DEFAULT)
{
/* Parse all compiler message lines, ie. such as:
*
* {file}:{line}:{col}: (note|warning|error):{message}
*
*/
regex_txt = "([^:]+):([0-9]+):(|([0-9]+):)[ \t]+(note|warning|error): (.*)(\\[-W([a-zA-Z0-8_-]+)\\]|)";
Copy link
Contributor

Choose a reason for hiding this comment

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

This is really specific. I think this should either be handled by a user-settable regex, or by an external program.
We could teach Tig to preserve ANSI escape codes in the output, then something like :!ls --color would work as well.

regex_err = regcomp(&regex, regex_txt, regex_flags);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you'd need to call regfree to avoid a memory leak


if (!regex_err)
regex_err = regexec(&regex, data, 8, pmatch, 0);

if (!regex_err)
type = LINE_COMPILER_MSG;
}
/* DEL_FILE, ADD_FILE and START are only valid outside diff chunks */
if (state->reading_diff_chunk) {
if (type == LINE_DIFF_DEL_FILE || type == LINE_DIFF_START)
Expand Down
11 changes: 10 additions & 1 deletion src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ begin_update(struct view *view, const char *dir, const char **argv, enum open_fl
bool
update_view(struct view *view)
{
bool should_autoscroll = false;
/* Clear the view and redraw everything since the tree sorting
* might have rearranged things. */
bool redraw = view->lines == 0;
Expand Down Expand Up @@ -630,12 +631,20 @@ update_view(struct view *view)
end_update(view, true);
return false;
}


if ((view->pos.offset + view->height + 1) == view->lines)
should_autoscroll = true;

if (!view->ops->read(view, &line, false)) {
report("Allocation failure");
end_update(view, true);
return false;
}

/* Autoscroll is available only in pager */
if (should_autoscroll && !strcmp(view->name, "pager"))

do_scroll_view(view, 1);
}

if (io_error(view->pipe)) {
Expand Down