omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    print
    5
    14
    8854
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Phuket2
      Phuket2 @lukaskollmer last edited by

      @lukaskollmer , maybe not exactly what you are looking for. But have you looked at the ActivityIndicator

      1 Reply Last reply Reply Quote 0
      • lukaskollmer
        lukaskollmer last edited by lukaskollmer

        @Phuket2 Do you mean the ActivityIndicator in the ui module?
        Yes I have, but I'd prefer this script not to have a GUI.

        Phuket2 1 Reply Last reply Reply Quote 0
        • Phuket2
          Phuket2 @lukaskollmer last edited by

          @lukaskollmer , ok. But you don't need a ui to call it. Maybe you mean Cross platform. But ActivityIndicator, works in the console

          1 Reply Last reply Reply Quote 0
          • lukaskollmer
            lukaskollmer last edited by

            @Phuket2 Do you mean the activity indicator in the status bar? The problem with that one is that it can't show progress.

            Phuket2 2 Replies Last reply Reply Quote 0
            • Phuket2
              Phuket2 @lukaskollmer last edited by

              @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

              1 Reply Last reply Reply Quote 0
              • dgelessus
                dgelessus last edited by

                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 like wget 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.

                1 Reply Last reply Reply Quote 0
                • Phuket2
                  Phuket2 @lukaskollmer last edited by

                  @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 😱

                  1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB last edited by

                    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.

                    1 Reply Last reply Reply Quote 1
                    • lukaskollmer
                      lukaskollmer last edited by lukaskollmer

                      @JonB I'm trying right now, there is a - (NSDictionary *)attributesAtIndex:(NSUInteger)location effectiveRange:(NSRangePointer)range; method on NSTextStorage, but objc_util can't call it.

                      I don't know why, but the attributesAtIndex:effectiveRange: method seems to be unavailable on OMTextStorage

                      I'll see if I can get the attributes some other way (NSTextStorage inherits from NSAttributedString)

                      1 Reply Last reply Reply Quote 0
                      • JonB
                        JonB last edited by

                        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...

                        1 Reply Last reply Reply Quote 0
                        • khilnani
                          khilnani last edited by

                          @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

                          1 Reply Last reply Reply Quote 0
                          • lukaskollmer
                            lukaskollmer last edited by

                            @khilnani yes. You can find it here. I commented out two lines that use the reprint line script from @JonB if you have it installed as well, just uncomment the import and the second print line in the upload progress function

                            1 Reply Last reply Reply Quote 0
                            • khilnani
                              khilnani last edited by

                              Thanks, will take a look!!

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post
                              Powered by NodeBB Forums | Contributors