DEV Community

17lwinn
17lwinn

Posted on

superPyOS- the terminal

It's been a while I know, but here is the second chapter!


the terminal was the main part of the OS, it had different commands controlling parts of the system. Something so powerful i'm going to say only involved the basic parts of python like user input, IF and the os module.


1. the modules

firstly you need to import your modules, we reccommend:

import os
import io
import platform    # modules to use
import subprocess
import sys
import glob
from time import *
import logging
from datetime import datetime
Enter fullscreen mode Exit fullscreen mode

*logging will be explained later in the series.

2. the prompt

An OS prompt would be the location it is now, we can program this by using;

currentpath = os.getcwd() # get current path
Enter fullscreen mode Exit fullscreen mode

so your prompt would be:

command = input(currentpath + "> ")
Enter fullscreen mode Exit fullscreen mode

3. the commands!

Now that we have our input prompt, we can start adding commands!

each command would start as:

if command == "COMMAND":
Enter fullscreen mode Exit fullscreen mode

then below that you add your function- what do you want it to do?

for example, perhaps we want to clear the screen? we would use the OS module for that.

if command == "clear":
   os.system("clear")

Enter fullscreen mode Exit fullscreen mode

of course- we need a way to loop the script- or after each command it'll quit.

so at the VERY END, we would put:

os.system("python3 SCRIPTNAME.py")
Enter fullscreen mode Exit fullscreen mode

if you know how to use other modules, then you can link them up and start making your own beginner 'guest' operating systems!

Top comments (0)