-
Notifications
You must be signed in to change notification settings - Fork 106
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
add TerminalWriter.chars_on_current_line read-only property #155
add TerminalWriter.chars_on_current_line read-only property #155
Conversation
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.
the unification with reline is needed to have correct data
def _update_chars_on_current_line(self, text): | ||
fields = text.rsplit('\n', 1) | ||
if '\n' in text: | ||
self._chars_on_current_line = len(fields[-1]) |
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.
this breaks in combination with reline
and _lastlen
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.
True, thanks
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.
Hmmm not sure what to do here. Here's reline
implementation:
def reline(self, line, **kw):
if not self.hasmarkup:
raise ValueError("cannot use rewrite-line without terminal")
self.write(line, **kw)
self._checkfill(line)
self.write('\r')
self._lastlen = len(line)
It always ends up with a \r
, so the cursor is at the start of the line; anything you write afterwards will begin from there, but it seems there are more characters on the line. What should chars_on_current_line
return in this case?
And notice that reline
always expects that it will be called multiple times for the same line only. IOW, if we want to write a "collecting" message using reline, we can only call reline()
and never write()
otherwise things will get out of sync.
As an exercise, what should be the value of chars_on_current_line
at the end of this code:
w = TerminalWriter()
w.reline('Hello World')
w.reline('pytest')
assert w.chars_on_current_line == ??
0
or 6
?
Note that the "cursor" is at the beginning of the line because of the \r
added by reline()
at this point, so if we now write:
w.write('foo')
We end up with fooest
on the terminal (this is why I mention that the only write()
which produces correct result after reline()
is write('\n')
).
Hmm perhaps the property should be named line_cursor_position
or something to avoid ambiguity?
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.
if its hard to exlain it might be a bad idea
im under the impression we are trying something at the wrong abstraction level and i'd like to avoid sinking too much time into terminalwriter
in addition we are currently spagettifying multiple concepts - we should take a step back and make what we need and what boundaries those need to have
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.
i'd like to avoid sinking too much time into terminalwriter
Perhaps we should just drop the idea of messing with TerminalWriter
and leave the hack in pytest-dev/pytest#2858?
Alternatively, we might just leave reline
as it is. reline()
is not really used in pytest or xdist, so this patch as it stands is enough for my needs in pytest-dev/pytest#2858.
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.
we can leave it as is heren but then
please document it as broken interaction and open a help wanted ticket to fix the interaction later on
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.
Sounds good, done: #164
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.
thanks for the BTS preps, for pedantic-ness, please add a todo comment with a short description and a link to that issue
Also mention pytest-dev#160 on chars_on_current_line property
725a8d2
to
d4cf79b
Compare
@RonnyPfannschmidt added the note about #160 you asked for and rebased on |
As discussed in pytest-dev/pytest#2858