fibonaccios/bin/sh.py

36 lines
1.1 KiB
Python
Raw Normal View History

2022-11-29 19:32:41 -08:00
import circuitos.exceptions
2022-11-29 19:18:17 -08:00
import shlex
import console
2022-11-29 19:32:41 -08:00
def get_app_class(template):
class App(template):
def F_main(self):
self.jump('prompt')
2022-11-29 19:18:17 -08:00
2022-11-29 19:32:41 -08:00
def F_prompt(self):
self.console.write(b'CicuitOS sh # ')
self.store['buf'] = []
self.jump('input')
2022-11-29 19:18:17 -08:00
2022-11-29 19:32:41 -08:00
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.os.launch(*line[1:])
elif line[0] == 'exit':
self.exit()
else:
pid = self.os.launch(*line)
self.wait(pid)
self.transfer_console(pid)
except circuitos.exceptions.AppNotFound as e:
print('error: app not found')
self.jump('prompt')
2022-11-29 19:18:17 -08:00
2022-11-29 19:32:41 -08:00
def F_loop(self):
pass
return App