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

Refactor print logic #133

Merged
merged 5 commits into from
Jun 15, 2016
Merged

Refactor print logic #133

merged 5 commits into from
Jun 15, 2016

Conversation

mptre
Copy link
Owner

@mptre mptre commented Jun 12, 2016

An attempt to solve #131 turned into a bigger change than expected, for better IMHO. See each commit messages for more info. Would really like to get feedback from all of you.

}

c = string[i];
switch (c) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since there are only two cases, do you think an if statement would make this clearer?

if (c == '\0') {
    /*
     * A null character will be present prior the
     * terminating null character if descriptions is
     * enabled.
     */
    c = ' ';
    col++;
} else if (!isu8cont(c))
    col++;

Copy link
Owner Author

Choose a reason for hiding this comment

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

Totally valid point. However, I plan on fixing output of tabs later
which is currently broken. Then the number of conditions is no longer
binary, therefore the pro-active switch.

@calleluks
Copy link
Collaborator

Hey @mptre, thanks so much for this! It looks, builds, and runs great on my system. I had one small question. Other than that this looks good to merge!

@teoljungberg Would you like to confirm that this resolves the flickering issues in tmux on your system?

@calleluks calleluks mentioned this pull request Jun 14, 2016
@teoljungberg
Copy link
Contributor

@calleerlandsson Indeed it does!

@calleluks
Copy link
Collaborator

Thanks @teoljungberg.

@teoljungberg
Copy link
Contributor

Thank you two for working on this!

@mptre
Copy link
Owner Author

mptre commented Jun 14, 2016

I sneaked in a minor cleanup, let me know what you think. Other that
than that, it's ready to be merged.

@calleluks
Copy link
Collaborator

Looks great, @mptre! Could you rebase this on the current master and squash in the mixup commit?

The match offsets are set to 0 if no match is found. But 0 is also a
valid offset. Therefore, make a existing and non-existing match disjoint
by using -1 as a indicator for a missing match.
Also, inline counting of ANSI escape sequences for two reasons:

- Performing the count while processing the input could cause incorrect
  behavior if a line is longer than the number of columns and contains
  ANSI escape sequences at a offset greater than the number of columns.
  This could be solved by only examining `MIN(columns, choice->length)`
  bytes, but it could also cause problems explained below.

- Simplifies future handling of SIGWINCH since any re-calculation of the
  number of ANSI escape sequences is no longer needed.
In a attempt to solve #131.
Since printing the query and choices are similar.
- Declarations comes first, in alphabetical order.

- Initializers comes second, one per line, in alphabetical order.
@mptre
Copy link
Owner Author

mptre commented Jun 15, 2016

Done!

@calleluks
Copy link
Collaborator

Thanks! I'll merge this.

@calleluks calleluks merged commit 9f4d257 into mptre:master Jun 15, 2016
@mptre mptre deleted the print branch June 15, 2016 14:59
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.

3 participants