% % PCC on a TTY (text console) % % This module provides a text console for PCC. Basically, it shows a % prompt and lets you enter commands. You can enter as many commands as % you wish, confirm each one with [Enter]. [ESC] exits the console. So, % if you want to run PCC on the command line, do % cc GAME PLAYER /rk Load "tty.q" % % In addition, this module provides a few commands that are useful on the % console. In GUI mode, you should use the GUI equivalent, so there's no % point in loading this file into the GUI. % % + `ListPlanets "expr"': lists all planets matching expr. For example, % `ListPlanets "mined.n > 100"' lists all planets with more than 100 kt % Neutronium. This function contains a pager (stops every 24 elements); % if your screen has more lines, you can configure that using the % variable `tty.PageSize'. In GUI mode, use the search function instead % of this function. % + `ListShips "expr"': does the same for ships. % + `pl id': go to planet #id. All the following commands will apply to % that planet. This is like opening a control screen. `pl' without % parameters goes back to "top level". % + `sh id': likewise for ships. % % In addition, the following shortcuts exist: % + `..': when on a planet/ship, this goes back to top-level % + `?a, b, c...': shortcut for `Print'. Unlike the normal PCC console, % the result of an expression you enter is not automatically displayed. % You have to print them explicitly. % % This module requires PCC 1.0.19. Older PCCs do not support input in % text mode. % % + 03/Sep/2003: some clean-up; added pager % + 07/Jan/2003: help; this script is now part of CCS % + 05/Jan/2003: fix: empty lines would crash this when entered in % ship/planet level % + 28/Apr/2002: first version % % This script uses only variables named `tty.XXX' to avoid clashes with % user variables. % % Todo: some sort of input history, with `bang' commands, would be nice. % Somehow like in csh/bash. % If System.GUI Then Print "[tty.q not loading]" Return EndIf Print "[tty.q 03/Sep/2003 -- PCC 1.1.6]" Local tty.Line, tty.Prefix, tty.Title Local tty.PageSize = 24 % This is the pager. It requires the caller to provide two % variables, tty.Break and tty.N. tty.Break will be set to true % when the user chose to exit Sub tty.Pager Local UI.Result If IsEmpty(tty.PageSize) Or tty.PageSize=0 Then Exit If IsEmpty(tty.N) Then tty.N:=0 tty.N := tty.N + 1 If tty.N Mod tty.PageSize = 0 Then UI.Message "Continue?", "Pager", "Yes No" If UI.Result=2 Then tty.Break:=1 EndIf EndSub Sub ListPlanets (tty.Expr) Local tty.Res, tty.Break, tty.N ForEach Planet Do Try tty.Res := 0 Eval 'tty.Res:=' & tty.Expr If tty.Res Then Print Id, ": ", Name tty.Pager If tty.Break Then Break EndTry Next EndSub Sub ListShips (tty.Expr) Local tty.Res, tty.Break, tty.N ForEach Ship Do Try tty.Res := 0 Eval 'tty.Res:=' & tty.Expr If tty.Res Then Print Id, ": ", Name tty.Pager If tty.Break Then Break EndTry Next EndSub Sub pl (Optional pid) If IsEmpty(pid) Then tty.Prefix := tty.Title := z(0) Else If Planet(pid).Id Then tty.Prefix := 'With Planet(' & pid & ')Do ' tty.Title := ': planet ' & pid Else Print "Error: No such planet (#" & pid & ")" EndIf EndIf EndSub Sub sh (Optional sid) If IsEmpty(sid) Then tty.Prefix := tty.Title := z(0) Else If Ships(sid).Id Then tty.Prefix := 'With Ship(' & sid & ')Do ' tty.Title := ': ship ' & sid Else Print "Error: No such ship (#" & sid & ")" EndIf EndIf EndSub Sub help Print " PCC Command Line" Print Print " Enter commands, and confirm with [Enter]. [ESC] will" Print " exit back to DOS (after confirmation)." Print Print " Special commands recognized:" Print " ?x,y,z display x,y,z (same as 'Print x,y,z')" Print " pl 123 go to planet 123" Print " sh 123 go to ship 123" Print " .. go back to top level" Print " help this help screen" EndSub % Our own `UI.Input' wrapper. First, this does the exit confirmation; % second, we don't want to mess with the global `UI.Result', so users % can use it for their own purposes. Sub tty.GetLine (prompt) Local UI.Result Do UI.Input prompt, "", 200 If IsEmpty(UI.Result) Then UI.Message "Exit console?", "Confirm", "Yes No" If UI.Result=1 Then tty.Line := z(0) Return EndIf Else Break EndIf Loop tty.Line := UI.Result EndSub Print "=== PCC TTY Console ===" Print "Enter commands and confirm with [Enter], or exit with [ESC]." Print "Type \"help\" for help." Do tty.GetLine "PCC" & tty.Title If IsEmpty(tty.Line) Then Break Try tty.Line := Trim(tty.Line) If tty.Line='' Or Left(tty.line, 1)='%' Then Continue If Left(tty.Line, 1) = '?' Then tty.Line := 'Print ' & Mid(tty.Line, 2) If tty.Line = '..' Then tty.Prefix := tty.Title := z(0) Else Eval tty.prefix & tty.Line EndIf Else Print "ERROR: ", System.Err EndTry Loop