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.


    StaSh updated for 1.6 beta with ObjC functions

    Pythonista
    1.6 beta
    9
    46
    35683
    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.
    • ywangd
      ywangd last edited by

      The update comes with many new features mostly thanks to the awesome objc_util module. It is available on the GitHub repo as branch beta16.

      To install it, copy and run following line in the Pythonista prompt.

      import urllib2; exec urllib2.urlopen('http://bit.ly/gsb16').read()
      

      It installs StaSh under site-packages and copy the launch_stash.py script under ~/Documents for easier access. If it is not obvious enough, you'll need Pythonista 1.6 beta for it to work. Try a few commands like ll and grep and see the colors and styles. (please note not all commands are updated to use attributed texts).

      Features and Changes:

      • Attributed texts
        • Colors, bold, italic, underline, strikethrough. Default font size is now 14 on iPad (was 12).
      • Real external keyboard support (no more approximation)
        • Ctrl-C interrupts running command. Ctrl-D ends user input. Ctrl-P/N navigates through command history. Ctrl-A/E jump to start/end of the input line. Ctrl-U erases the input line. Ctrl-W deletes one word from the input line.
      • Killable threads
        • Running scripts can now be properly terminated by the C-C button (Ctrl-C) which raises KeyboardInterrupt.
      • Better modularity
        • Code is now splitted into 7 files. The total length is over 4000 lines.A single file really gets difficult to handle.
      • It is now a module
        • The application is now made as a module to be installed under site-packages to survive through the global variable clearing.
      • Better scrolling
      • Largely redesigned the logic of user/script IO handling.
        • The on screen and in memory buffers should now be more consistent.

      There are also drawbacks. The most noticeable one is probably the speed. On iPad Air 2, it runs OK but cat through a large file still takes quite a few seconds. I am not sure how it would work on older devices.

      This version is still at its early stage and you may expericence crash and freeze. There is still much room for improvements. I have a few already in my mind and will implement them when time permits.

      All feedbacks are welcome!

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

        I just hope the objc module survives app store review!

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

          @JonB said:

          I just hope the objc module survives app store review!

          Yep fingers crossed!

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

            I'd add the built in extended keyboard

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

              i don't think we have an easy way of forcing the built in kb to show, or target the textview. well, we might be able to find it, traversing through the UIApplication.... hmmmm

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

                I found OMKeyboardAccessoryView ...

                Tried to implement it but the result for me is the view without buttons

                import ui
                from objc_util import *
                v = ui.load_view()
                editor_view=ObjCInstance( v['textview1'])
                OMKeyboardAccessoryView = ObjCClass('OMKeyboardAccessoryView')
                accessory_view = OMKeyboardAccessoryView.alloc().initWithType_dark_('python', False).autorelease()
                editor_view.setInputAccessoryView_(accessory_view)
                v.present('sheet')
                

                The pyui file is just a view with a textview inside it

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

                  @filippocld I did think about using the builtin accessory keyboard and studied the example that @omz provided. However it turned out to be rather inadequate for following reasons:

                  • Unlike a text editor, a Terminal does not allow users to freely type any texts in any locations. It has strict control on where you can type texts. For the accessory keyboard, this means I need to register my own callbacks for the button actions and swipes. This may be possible but may not be trivial, especially when there is no documentation about its internals.

                  • The builtin accessory keyboard does not provide Control keys (e.g. Ctrl-C, Ctrl-D) or any utility buttons like history navigation.

                  • Some of the utility buttons should be context aware. For an example, behaviour of the Tab button depends on whether a script is running. This again requires a custom callback for the buttons.

                  With above being said, the extra keyboard really could use some improvements. A possible way is to create my own inputAccessoryView for better look and encapsulate the functions.

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

                    Awesome! The site-packages installation will really make integration a lot easier for scripts like the Pythonista Tools client that rely on StaSh. The previous integration method was pretty hack-ish. Nice work!

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

                      I am sorry to report that external bluetooth keyboard support is no longer working as it did in the prior version. History via Cmd up and down arrows is no longer functioning for me now. Output scrolling is kinda jerky and looks like some kind of buffering is going on that causes it to stop and start.

                      I have not seen any other issues and it looks to be functioning well running from site_packages. I made sure to delete my old stash folder in Documents and remove and re-add stash_launcher to my tools menu.

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

                        @wradcliffe Thanks a lot for the feedbacks!

                        • The cmd + up/down history navigation is removed from the new version. I replaced them with Ctrl + p/n. But it does make sense to have arrow keys involved for browsing history. So I have just added support for using only the up/down arrow keys (no need to press Cmd, just the arrow key itself). I hope this would work better for you.

                        • As for the jerky scrolling, what device do you have? How frequent did it happen? Did it happen when you type ll or cat a large file or all the time? I had a few optimisations pushed since the original post. So it may also be worthwhile to try the latest version by type and run selfupdate.py beta16 from within the shell (you may need restart the whole Pythonista app afterwards).

                        Please let me know how it works for you. Thanks!

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

                          @Gerzer Glad to hear you like the changes! I wasn't sure about the site-packages change but now it seems to make more sense.

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

                            @ywangd - Thanks for adding the simpler up arrow for history. Makes a lot of sense and has the nice benefit of preventing the user from moving the cursor off the input line.

                            With further testing, I don't see any real problem with scroll speed and smoothness. Testing using cat on a large file works fine and the speed is dictated by screen rendering time as you would expect. The jerkiness I noticed was for file system traversal. Seems slower then what I remember but it is hard to imagine how stash could be effecting that.

                            As usual, your releases are superb. Thanks for all the hard work on this.

                            One more question. How can users contribute scripts for potential inclusion into stash? I have one that I use often that can "sanatize" one or more text files that may contain odd character encodings. It is used for cases where a text file won't open properly in the editor. Here is the script ...

                            # coding: utf-8
                            """Sanitize one or more files to pure ascii and MAC EOL chars"""
                            
                            from __future__ import print_function
                            
                            import argparse
                            import fileinput
                            import os
                            import sys
                            import codecs
                            
                            def sanitize_file(fn_in, fn_out):
                            	with codecs.open(fn_in, 'rt', encoding='ascii', errors='ignore') as in_file:
                            		text = '\n'.join(line.rstrip() for line in in_file.readlines()) + '\n'
                            	with open(fn_out, 'wt') as out_file:
                            		out_file.writelines(text)
                            
                            def main(args):
                                ap = argparse.ArgumentParser()
                                ap.add_argument('files', nargs='*', help='files to be searched')
                                ns = ap.parse_args(args)
                                
                                # Do not try to sanitize directories
                                files = [f for f in ns.files if not os.path.isdir(f)]
                                
                                fileinput.close()  # in case it is not closed
                                try:
                                    for line in fileinput.input(files):
                                        line=line.rstrip()
                                        if os.path.exists(line):
                                            if fileinput.isstdin():
                                                fmt = '{lineno}: {line}'
                                            else:
                                                fmt = '{filename}: {lineno}: {line}'
                                            print(fmt.format(filename=fileinput.filename(),
                                                             lineno=fileinput.filelineno(),
                                                             line=line))
                                            sanitize_file(line, line)
                                except Exception as err:
                                    print("sanitize: {}: {!s}".format(type(err).__name__, err), file=sys.stderr)
                                finally:
                                    fileinput.close()
                            
                            if __name__ == "__main__":
                               main(sys.argv[1:])
                            
                            1 Reply Last reply Reply Quote 0
                            • ywangd
                              ywangd last edited by

                              @wradcliffe You can make a pull request to the repo for your changes:

                              • Fork the repo first
                                • navigate your browser to the repo and click Fork at the top-right corner.
                              • Make changes against the forked repo
                                • You can make any changes since forked repo is owned by you
                              • Create a pull request back to the original repo once you are done with the changes
                                • The pull request is created by clicking the green button on the forked repo's main page.
                                • Please create the pull against the dev branch of the original repo. The dev branch will be merged into master when things are stable.

                              Thanks again for the feedback. This is what I could really use to make StaSh progress.

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

                                Ran launch_stash.py and it crashes (returns to home screen) after 7 seconds.

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

                                  @ihf
                                  I cannot reproduce it. What device do you have? Are you on the latest beta (160033)? Could you please try a fresh install:

                                  • First delete any existing stash folders and launch scripts, including the new one and any old ones (v0.4.x).
                                  • Run import urllib2; exec urllib2.urlopen('http://bit.ly/gsb16').read() to install
                                  • Unload Pythonista app completely and relaunch to ensure a fresh state
                                  • Make sure you are not loading any custom resource files, e.g. .stashrc.
                                  • Now run ~/Documents/launch_stash.py

                                  Please let me know if above steps work for you.

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

                                    I will just report I have the latest version of stash, and the latest beta, and launch_stash.py works.
                                    IPad Air 2 , 128gb , wifi + cell, iOS 8.4.1

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

                                      @Phuket2 Good to know it works for you. Thanks a lot for the feedback.

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

                                        @ywangd , no problems. However there is always a but :) on the previous version I tried to find where to change the font and size used. It was described clearly, but I could not find the file that was referred to. When you have time, could you please point me in the right direction to change the font and size. My eyes are bad, so I need a bigger size

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

                                          @Phuket2
                                          You can configure the text size, but the font can no longer be changed in the new version (at least not recommended).

                                          • If you prefer to modify the source file, you can do it by change the value on Line 103 of stash.py. Default size is 14 for iPad and 12 for iPhone.
                                          • Alternatively, I'd recommend creating a .stash_config file under the stash installation root (i.e. ~/Documents/site-packages/stash/). Any settings in this file override the same settings in the source file. For an example, to increase the text size:
                                            [display]
                                            TEXT_FONT_SIZE=20
                                            

                                          The text font can no longer be configured because not every font has all of the bold, italic and bold-italic variants. If stash tries to display a non-existing font variant, it crashes the entire Pythonista app.

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

                                            @ywangd, thanks I did it in your code. I know it seems simple, but I tried the config file and failed big time. But did you mean literally '.stash_config' or 'stash_config.txt' or ...... Sorry, I was not sure

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