# A very simple console program. I could make it flashier but I can't be
# bothered.

proc main
var line com

print [format "\n~BB*** AVIOS CONSOLE ***\n\n"]
while 1
	print ">"
	input line
	if line=""; continue; endif
	set com [head line]
	choose com
		value "ps"; call ps_proc; break
		value "kill"; call kill_proc [tail line]; break;
		value "exit"; exit 0

		default
		printnl "Unknown command"
	chosen
wend
endproc



proc ps_proc
var pid pname cnt info

print [format "\n~BB*** Processes at %s ***\n\n" [gettime time]]
foreach pid pname in $pcs
	set info [pcsinfo pid]
	printnl [format "~FY%-4d  ~FG%-10s  ~FT%s" pid pname [elements info 2 [count info]]]
nexteach
printnl [format "\nTotal of %d processes.\n" $pcs_count]
endproc



proc kill_proc killid
var pid pname err

if killid=""
	printnl "Kill which process?";  return
endif
foreach pid pname in $pcs
	if killid=pid
		if [set err [trap [kill pid]]]
			printnl "Unable to kill process.";  return
		endif
		printnl "Process killed."
		return
	endif
nexteach
printnl "Process does not exist."
endproc	


