fibonaccios/bin/sh.py
2022-11-30 19:33:05 -08:00

38 lines
1.2 KiB
Python

import fibonaccios.exceptions
import shlex
import console
def get_app_class(template):
class App(template):
def F_main(self):
self.jump('prompt')
def F_prompt(self):
self.console.write(b'FibonacciOS sh # ')
self.store['buf'] = []
self.jump('input')
def F_input(self):
raw_line = console.read(self.console, self.store['buf'])
if raw_line is not None:
line = shlex.split(raw_line.decode('ascii'))
if line:
try:
if line[0] == 'bg':
self.launch(*line[1:])
elif line[0] == 'cd':
self.chdir(line[1])
elif line[0] == 'exit':
self.exit()
else:
pid = self.launch(*line)
self.wait(pid)
self.transfer_console(pid)
except fibonaccios.exceptions.AppNotFound as e:
print('error: app not found')
self.jump('prompt')
def F_loop(self):
pass
return App