Skip to content

07 What is terminal

Austin edited this page Dec 13, 2017 · 2 revisions

What is terminal?

The whole premise for terminal is to allow cross-platform compatibility. It's the "how" that lets the atom-python-run module work it's arbitrary "magic" on any system. terminal determines the Operating System and creates the proper parameters based on expected values for that particular system.

Each OS has it's own internal operations and they usually require specific calls that can typically be considered determinate. This means that we can expect those calls to always be the same.

Windows will always have cmd. Mac OS X will always use terminal.

For example. To run a program in a DOS prompt on Windows, we open a prompt and then feed it text based commands.

c:\> echo "Hello, World"
Hello, World

In Mac OS X, we open Terminal and feed it a command.

$ echo "Hello, World"
Hello, World

They both do the same thing, just in different ways.

Every OS has it's own method for handling internal instructions and the processes that handle those instructions.

In node, we can use child_process.spawn() to create a process object called ChildProcess. The only problem is that to open a Command Line Interface instance, we have to tell the OS how to do just that. Not only that, but we also have to be able to be flexible enough to run different shells. This basically means we have a problem with configuration as well.

For example, in a Win32 based system we might expect to be able to use cmd or powershell. In Linux we might expect to use gnome-terminal or konsole. We might also want that shell to execute a command for us once that instance exists.

On Windows

rem This would create a new prompt telling it to execute the command 'echo "Hello, World"'
c:\> cmd /c start echo "Hello, World"

On Linux

# This would create a new prompt telling it to execute the command 'echo "Hello, World"'
$ gnome-terminal -x echo "Hello, World

The terminal module automates the process of constructing a ChildProcess object that does just that. The object that is created is ultimately determined by the Operating System being used.

Linux is a bit a more complicated and is a bit less determinate than either Windows or Mac OS X. That's because Windows and Mac OS X only use a single Desktop Environment. Windows uses aero and Mac OS X uses quartz. Linux happens to have a wide variety of Desktop Environments; terminal targets the most common ones to create a default value based on the current Desktop Session.

In short, terminal figures out what OS it's running on, sets the default values unless instructed otherwise, and opens a local CLI to execute some type of Interpreter, REPL, Interactive Session, Binary, etc...

For further details, take a look at the How does terminal work? section of this wiki.

Clone this wiki locally