Coder Social home page Coder Social logo

cmd2 and a-Shell about cmd2 HOT 7 CLOSED

tthkbw avatar tthkbw commented on June 2, 2024
cmd2 and a-Shell

from cmd2.

Comments (7)

kotfu avatar kotfu commented on June 2, 2024 1

I messed around in a-shell for a minute. You might try this:

  • create a new directory ~/Documents/a-shell-bin
  • add that new directory to your PATH environment variable
  • create the no-op version of stty referenced above by:
$ cd ~/Documents/a-shell-bin
$ cat > stty
#
exit 0
  • type Control-D to exit cat and write the file
  • change ~/Documents/a-shell-bin to be executable by everyone (i.e. chmod 755 stty)

from cmd2.

kotfu avatar kotfu commented on June 2, 2024

What operating system are you using? Would you mind posting your simple program? With this info I'll bet I can chase down your problem.

from cmd2.

tthkbw avatar tthkbw commented on June 2, 2024

@kotfu

I am running the program under a-Shell on a iPad Pro with iOS 16.3.1

Here's the code:

import cmd2

def setprompt():
    global current_book

    promptstr = f"<My Prompt:> "
    CmdBooks.prompt = promptstr

class CmdBooks(cmd2.Cmd):
    """Simple Command Processor"""

    def default(self, line):
        print("Invalid command; try again")

    def do_one(self, line):
        print("This is command one.")

                 
    def do_two(self, line):
        print("This is command two.")

if __name__ == "__main__":
    CmdBooks().cmdloop()

from cmd2.

kotfu avatar kotfu commented on June 2, 2024

Gotcha. Here's what's happening: occasionally control characters in the printed output can mess up your terminal. This only seems to happen on linux/bsd/unix variants. So after each command has run, cmd2 resets the terminal using the stty sane command. It only tries to execute this if the operating system isn't windows. In all our experience to date, all non-windows operating systems have included the stty command. I downloaded a-shell, and sure enough, the kernel identifes itself as darwin (a bsd variant), but there is no stty command in the default install. So when you run a command cmd2 tries to clean up the terminal, and a-shell complains because it doesn't include a stty command.

As for potential solutions, I'm not sure how we could get cmd2 to tell it was running inside of a-shell. The kernel a-shell reports looks like macOS to python. So here's some things you could try:

  • see if there is a way to install a working stty program in a-shell
  • create a shell script named stty and put it in your a-shell path. The script would contain something like:
# do nothing
exit 0

That way when cmd2 tries to run stty it will be able to run it and not generate any error message.

Another alternative might be to try iSH on your ipad. It includes a working stty program.

Hope this helps.

from cmd2.

tthkbw avatar tthkbw commented on June 2, 2024

@kotfu thank you for the help. I have played around with this today and so far haven't been successful in generating a no-op version of stty, but I'm still working on it.

With respect to determining the presence of a-Shell, I had done that for some options in my script. a-Shell has an environment variable $APPDIR that is the location of the a-Shell.app. So I did:

import os
appdir = os.getenv("APPDIR")
if appdir != None and "a-Shell" in appdir:
    in_ashell = True
else:
    in_ashell = False

For now I have modified the cmd2.py file on my iPad so that it doesn't run stty if I find I am in a-Shell--same as it does if cmd2 is running in Windows.

from cmd2.

tthkbw avatar tthkbw commented on June 2, 2024

Thanks. Before I saw your latest, I compiled a simple C program called stty:

int main(void) {
    return(0)
}

I compiled it, put it in ~/Documents/bin, and now unmodified cmd2 doesn't complain when run!

Thanks a lot for helping with this.

from cmd2.

kotfu avatar kotfu commented on June 2, 2024

Glad you were able to get it sorted, and it looks like there may be some interest from a-shell in doing something more standard to resolve the issue.

from cmd2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.