Skip to content

Conversation

@staxfur
Copy link
Collaborator

@staxfur staxfur commented Feb 12, 2021

As introduced in #64 and implemented in #68: This pull-request tries to simplify the get_cursor_position() function. The code should be checked of logic mistakes. I have tried to just change the code, but don't touch the logic at all. I hope it's still intakt!

@staxfur staxfur requested a review from certik February 12, 2021 21:46
@staxfur staxfur added the enhancement New feature or request label Feb 12, 2021
@certik
Copy link
Collaborator

certik commented Feb 12, 2021

The fact that even you forgot to append std::flush and had to fix it in 4bb0f82 is an argument against #81.

@staxfur
Copy link
Collaborator Author

staxfur commented Feb 12, 2021

the fix in 4bb0f82 was due to a misstake in the old pull-request #68, I made the misstake there. I'll have to resolve that conflict in git, but will do that, after #81 was merged of closed. Like I said both is absolutely fine! I just did brain dead copy paste here, sorry for that!
I'll change it to the write() function, if you decide to drop #81.

@staxfur
Copy link
Collaborator Author

staxfur commented Feb 13, 2021

Because we dropped #81 and changed it to #87, I'll wait for #87 to get merged and then change the std::cout here back to the write function. You can take a look at the logic then @certik.

@certik
Copy link
Collaborator

certik commented Feb 23, 2021

#87 is merged, you can go ahead and finish the PR now.

@staxfur
Copy link
Collaborator Author

staxfur commented Feb 24, 2021

done!

Copy link
Collaborator

@certik certik left a comment

Choose a reason for hiding this comment

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

I think it looks good. It seems it is equivalent. I left some minor formatting suggestions.

}

void get_cursor_position(int& rows, int& cols) const
void get_cursor_position(int& rows, int& cols) const
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
void get_cursor_position(int& rows, int& cols) const
void get_cursor_position(int& rows, int& cols) const

while (i < sizeof(buf) - 1) {
while (!read_raw(&buf[i])) {
};
for (unsigned int i = 0; i < sizeof(buf) -1; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for (unsigned int i = 0; i < sizeof(buf) -1; i++) {
for (unsigned int i = 0; i < sizeof(buf) - 1; i++) {

Comment on lines 390 to 391
if (buf[i] == 'R')
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (buf[i] == 'R')
{
if (buf[i] == 'R') {

Comment on lines 392 to 395
if (i < 5)
throw std::runtime_error("get_cursor_position(): too short response");
else
buf[i] = '\0';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (i < 5)
throw std::runtime_error("get_cursor_position(): too short response");
else
buf[i] = '\0';
if (i < 5) {
throw std::runtime_error("get_cursor_position(): too short response");
} else {
buf[i] = '\0';
}

Comment on lines 407 to 408
if (buf[i] == '\0')
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

When you have multineline if / while statements, use {} to prevent a mistake in the future:

Suggested change
if (buf[i] == '\0')
break;
if (buf[i] == '\0') {
break;
}

Or put them on the same line:

Suggested change
if (buf[i] == '\0')
break;
if (buf[i] == '\0') break;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

about the {}, that's true, i sometimes forget that. There is a compiler waning on that btw.

@staxfur
Copy link
Collaborator Author

staxfur commented Mar 4, 2021

about the formating: the code base has no real coding style. Sometimes I have seen 2 spaces, sometimes 4 spaces, sometimes a new line after curly brackets, sometimes there is none. We should really use clang format for that. Then there wont be such things to check anymore.

@staxfur staxfur requested a review from certik March 4, 2021 10:30
Copy link
Collaborator

@certik certik left a comment

Choose a reason for hiding this comment

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

I think this looks good.

@staxfur staxfur merged commit 6562964 into jupyter-xeus:master Mar 11, 2021
@staxfur staxfur deleted the simplifyForLoop1 branch March 11, 2021 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants