Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
print: replace previous line
-
@lukaskollmer , maybe not exactly what you are looking for. But have you looked at the ActivityIndicator
-
@Phuket2 Do you mean the ActivityIndicator in the ui module?
Yes I have, but I'd prefer this script not to have a GUI. -
@lukaskollmer , ok. But you don't need a ui to call it. Maybe you mean Cross platform. But ActivityIndicator, works in the console
-
@Phuket2 Do you mean the activity indicator in the status bar? The problem with that one is that it can't show progress.
-
@lukaskollmer , sorry, I have mixed things up here in my mind. I feel sure there is a simple way to do it. I just did a few tests, I can't remember what I have done in the past.
I will still have a look. But someone with more experience will come along with the answer I am sure -
In the Pythonista console this is basically impossible - the best you can do is clear the console every time before writing out the progress. In a normal terminal you would use
\b
or\r
to go back one character or to the beginning of a line, but the Pythonista console doesn't understand that.stash
uses a custom view to display text in and has more advanced terminal-like features, such as updating the current line. But before that was implemented scripts likewget
would also write out a new line for each status update. Of course that takes up more space, but it didn't bother me much. -
@lukaskollmer , sorry to screw you around. It's one of those normal days where I think I know everything and much to my suprise, I know nothing 😱
-
here is an approach that replaces the previously printed line, using objc.
https://github.com/jsbain/objc_hacks/blob/master/reprint_line.py
The text attributes get lost for some reason. it would be possible to get the previous attributes and apply after replacing the characters.... this works, but might be a tad ugly.
-
@JonB I'm trying right now, there is a
- (NSDictionary *)attributesAtIndex:(NSUInteger)location effectiveRange:(NSRangePointer)range;
method onNSTextStorage
, butobjc_util
can't call it.I don't know why, but the
attributesAtIndex:effectiveRange:
method seems to be unavailable onOMTextStorage
I'll see if I can get the attributes some other way (
NSTextStorage
inherits fromNSAttributedString
) -
That method exists on the underlying text(). You may need to call use argtypes and restype kwargs, since one of the argument encodings is a pointer to an NSRange, and objc_utils does not always handle those nicely.
I don't know that much about attributedStrings,but it would seem like it should be able to insert characters into the middle of an attributedString without having to copy over the attributes...
-
@lukaskollmer Slightly off topic, but did you finish your S3 Backup script? I needed one too and couldn't find one so wrote one - https://github.com/khilnani/s3sync.py
-
-
Thanks, will take a look!!