primitive ingame help system, still needs some more topics

This commit is contained in:
Florian Nücke 2014-01-30 19:57:58 +01:00
parent 11b9d50f08
commit 48a41440c6
33 changed files with 437 additions and 17 deletions

View File

@ -15,7 +15,7 @@ else
proxy, reaons = fs.get(args[1])
end
if not proxy then
print(reason)
io.write(reason)
return
end

View File

@ -0,0 +1,17 @@
local fs = require("filesystem")
local shell = require("shell")
local args = shell.parse(...)
if #args == 0 then
io.write("Usage: man topic\n")
io.write("Where `topic` will usually be the name of a program or library.")
return
end
local topic = args[1]
local path = "/usr/man/" .. topic
if fs.exists(path) and not fs.isDirectory(path) then
os.execute("more " .. path)
else
io.write("No manual entry for " .. topic)
end

View File

@ -2,7 +2,7 @@ local shell = require("shell")
local args = shell.parse(...)
if #args < 1 then
print("Usage: unalias <name>")
io.write("Usage: unalias <name>")
return
end
@ -12,4 +12,4 @@ if not result then
else
shell.setAlias(args[1], nil)
io.write("alias removed: ", args[1], " -> ", result)
end
end

View File

@ -6,9 +6,16 @@ if #args == 0 then
return
end
local result, reason = shell.resolve(args[1], "lua")
if result then
io.write(result)
else
io.write(reason)
for i = 1, #args do
local result, reason = shell.getAlias(args[i])
if result then
result = args[i] .. ": aliased to " .. result
else
result, reason = shell.resolve(args[i], "lua")
end
if result then
io.write(result, "\n")
else
io.write(args[i], ": ", reason, "\n")
end
end

View File

@ -7,7 +7,7 @@ local shell = {}
local cwd = "/"
local path = {"/bin/", "/usr/bin/", "/home/bin/"}
local aliases = {dir="ls", list="ls", move="mv", rename="mv", copy="cp",
del="rm", md="mkdir", cls="clear", more="less", rs="redstone",
del="rm", md="mkdir", cls="clear", less="more", rs="redstone",
view="edit -r", help="man", ["?"]="man"}
local running = setmetatable({}, {__mode="k"})
local isLoading = false
@ -63,12 +63,7 @@ local function findFile(name, ext)
return false
end
local function parseCommand(tokens)
local program, args, input, output = tokens[1], {}, nil, nil
if not program then
return
end
local function resolveAlias(program, args)
local lastProgram = nil
while true do
local alias = text.tokenize(shell.getAlias(program) or program)
@ -77,10 +72,22 @@ local function parseCommand(tokens)
end
lastProgram = program
program = alias[1]
for i = 2, #alias do
table.insert(args, alias[i])
if args then
for i = 2, #alias do
table.insert(args, alias[i])
end
end
end
return program
end
local function parseCommand(tokens)
local program, args, input, output = tokens[1], {}, nil, nil
if not program then
return
end
program = resolveAlias(program, args)
local state = "args"
for i = 2, #tokens do

View File

@ -0,0 +1,12 @@
NAME
address - display the computer's address
SYNOPSIS
address
DESCRIPTION
`address` allows printing the computer's component address. This can be useful to quickly look up a computer's address without an Analyzer. Knowing a computer's address can be useful if you wish to directly send network messages between two computers.
EXAMPLES
address
Displays the address of the computer the program is run on.

View File

@ -0,0 +1,20 @@
NAME
alias - displays and manipulates aliases for programs
SYNOPSIS
alias
alias name
alias name value
DESCRIPTION
`alias` allows listing and editing aliases for programs. An alias is an alternative name that can be used to start a program. A program can have multiple aliases. Aliases can also contain parameters and options to pass to the actual program. An alias can also, in turn, have aliases.
EXAMPLES
alias
Displays the list of all current aliases.
alias name
Displays the value the specified alias, i.e. what the specified alias stands for.
alias name value
Sets the value of the alias with the specified name.

View File

@ -0,0 +1,15 @@
NAME
cat - concatenate files and print on the standard output
SYNOPSIS
cat [FILE]...
DESCRIPTION
`cat` allows concatenating files or standard input to standard output.
EXAMPLES
cat
Copy standard input to standard output.
cat test.txt
Output contents of file test.txt.

View File

@ -0,0 +1,15 @@
NAME
cd - change the current working directory
SYNOPSIS
cd path
DESCRIPTION
`cd` allows changing the current working directory, i.e the directory based on which relative paths are resloved.
EXAMPLES
cd a
Changes to directory `a` in the current working directory.
cd /bin
Changes to directory `/bin`, using the specified absolute path.

View File

@ -0,0 +1,12 @@
NAME
clear - clears the terminal
SYNOPSIS
clear
DESCRIPTION
Clears any text from the screen, using the current background and foreground (text) colors and resets the cursor position to (1, 1).
EXAMPLES
clear
Clears the screen/

View File

@ -0,0 +1,16 @@
NAME
cp - copy files
SYNOPSIS
cp SOURCE DEST
cp SOURCE DIRECTORY
DESCRIPTION
`cp` allows copying single files on a filesystem and across filesystems.
EXAMPLES
cp a b
Copy file `a` to new file `b` in the same directory.
cp /home/a.txt /home/d/
Copy file `/home/a.txt` to new file `/home/d/a.txt`.

View File

@ -0,0 +1,12 @@
NAME
date - get the current time and date
SYNOPSIS
date
DESCRIPTION
Writes the current time and date to the standard output. Note that the time is measured in ingame time, with the date starting on the 1st of January 1970 as the time the world was created.
EXAMPLES
date
Displays the current date and time.

View File

@ -0,0 +1,15 @@
NAME
df - report file system disk space usage
SYNOPSIS
df [FILE]...
DESCRIPTION
`cp` allows copying single files on a filesystem and across filesystems.
EXAMPLES
df
Show global file system disk usage.
df /home /var
Show disk usage of file systems mounted at `/home` and `/var`.

View File

@ -0,0 +1,15 @@
NAME
echo - display a line of test
SYNOPSIS
echo [STRING]...
DESCRIPTION
`echo` writes the provided string(s) to the standard output.
EXAMPLES
echo test
Print `test` to the terminal.
echo "a b" > test
Writes the string `a b` to the standard output, which is redirected into file `test`.

View File

@ -0,0 +1,16 @@
NAME
label - show or change the label of file systems
SYNOPSIS
label FILE [STRING]
label -a ADDRESS [STRING]
DESCRIPTION
`label` allows reading and writing the label of file systems. The file system can either be specified by a path to or into a mount, or by its address.
EXAMPLES
label /home
Write the label of the file system mounted at `/home` to the standard output.
label -a 93f test
Change the label of the file system of which the address starts with `93f` to `test`.

View File

@ -0,0 +1,19 @@
NAME
ln - creates symbolic links
SYNOPSIS
ln FILE [TARGET]
DESCRIPTION
`ln` allows creating virtual symbolic links. A symbolic link is a reference in the file system that can be used to point to other nodes in the file system. For example, a symbolic link to a file will behave like that file: it can be opened and changed, where in reality the file the link references is changed. A symbolic link to a directory will behave as such.
Note that symbolic links can lead to cycles (recursion) in the file system structure.
Symbolic links in OpenOS are 'virtual'. They are not stored on any file system, and as such will not persist across a reboot of the computer. This also means that the can be created in virtual folders, and even on read-only file systems.
EXAMPLES
ln /bin/ls.lua
Creates a symbolic link `ls.lua` to the file `/bin/ls.lua` in the current working directory.
ln /home/magic.lua /bin/magic.lua
Creates a symbolic link to file `/home/magic.lua` in the `/bin` directory.

View File

@ -0,0 +1,21 @@
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the specified files, or the current working directory by default.
OPTIONS
-a
do not ignore entries starting with .
-l
use a long listing format
EXAMPLES
ls
Displays the contents of the current directory.
ls /bin /mnt
Displays the contents of the `/bin`/ and `/mnt` directories, one after the other.

View File

@ -0,0 +1,15 @@
NAME
man - help program, providing help on various programs and topics
SYNOPSIS
man topic
DESCRIPTION
`man` is the system's help viewer. Each help topic is normally the name of a program or library. Topics are stored as individual text files in the `/usr/man` folder. Additional help topics can be provided by creating a symbolic link to a file.
EXAMPLES
man man
Display the help for the `man` program.
man ls
Display the help for the `ls` program.

View File

@ -0,0 +1,15 @@
NAME
mkdir - make directories
SYNOPSIS
mkdir DIRECTORY...
DESCRIPTION
Create the specified directories, if they don't already exist.
EXAMPLES
mkdir a
Create directory `a` in the current directory.
mkdir /a/b c
Create directory `/a` if it doesn't already exists, then create directory `/a/b` and create directory `c` in the current directory.

View File

@ -0,0 +1,12 @@
NAME
more - primitive file viewer
SYNOPSIS
more FILE
DESCRIPTION
`more` allows viewing the contents of a file one screenful at a time.
EXAMPLES
more /home/a.txt
Displays the contents of file `/home/a.txt`

View File

@ -0,0 +1,20 @@
NAME
mount - mount a file system
SYNOPSIS
mount
mount LABEL PATH
mount ADDRESS PATH
DESCRIPTION
All files accessible in OpenOS are arranged in one big tree, starting with the root node, '/'. The files are the leaves of the tree, directories are inner nodes of the tree. Files can be distributed across several devices (file system components, such as hard drives and floppies). The `mount` command is used to attach a file system to this tree. The `umount` command can be used to remove a mounted file system from the tree (note that `rm` works for this, too).
EXAMPLES
mount
Display a list of all currently mounted file systems.
mount test /home
Mounts the file system labeled `test` at `/home`.
mount 56f /var
Mounts the file system of which the address starts with `56f` at `/var`.

View File

@ -0,0 +1,19 @@
NAME
mv - move (rename) files
SYNOPSIS
mv SOURCE DEST
DESCRIPTION
Renames files - and folders, as long they remain on the same file system. Files that are 'renamed' to another file system will actually be copied, then deleted.
OPTIONS
-f
do not prompt before overwriting
EXAMPLES
mv a b
Renames file `a` to `b`.
mv /home/a /var/b
Moves file from `/home/a` to `/var/b`.

View File

@ -0,0 +1,12 @@
NAME
pwd - print name of current/working directory
SYNOPSIS
pwd
DESCRIPTION
`pwd` writes the name of the current working directory to the standard output.
EXAMPLES
pwd
Write the current directory to the terminal.

View File

@ -0,0 +1,12 @@
NAME
reboot - restarts the computer
SYNOPSIS
reboot
DESCRIPTION
`reboot` will immediately issue a reboot of the computer, shutting it down then starting it back up.
EXAMPLES
reboot
Reboots the computer.

View File

@ -0,0 +1,16 @@
NAME
resolution - get or set screen resolution
SYNOPSIS
resolution
resolution WIDTH HEIGHT
DESCRIPTION
The `resolution` program is used to write the resolution of the current primary screen to the standard output, or to change the resolution to a new value.
EXAMPLES
resolution
Displays the current screen resolution.
resoltution 30 10
Sets the screen's resolution to 30 by 10 characters.

View File

@ -0,0 +1,12 @@
NAME
rm - remove files or directories
SYNOPSIS
rm FILE...
DESCRIPTION
Removes all of the specified files, one by one. Can also be used to remove directories, mounts and symlinks.
EXAMPLES
rm a
Deletes the file `a`.

View File

@ -0,0 +1,12 @@
NAME
shutdown - shut down the computer
SYNOPSIS
shutdown
DESCRIPTION
Immediately shuts down the computer.
EXAMPLES
shutdown
Stops the computer.

View File

@ -0,0 +1,17 @@
NAME
umount - remove a file system mount
SYNOPSIS
umount PATH
umount -a LABEL
umount -a ADDRESS
DESCRIPTION
Removes either a single mount point if given the path into a mount, or all mount points for a specified file system if given the label or address of the file system.
EXAMPLES
umount /mnt/82f
Unmounts the automatically generated mountpoint at `/mnt/82f`.
unmount -a 82f
Removes all mounts of the file system for which the address starts with `82f`.

View File

@ -0,0 +1,12 @@
NAME
unalias - removes aliases for programs
SYNOPSIS
unalias name
DESCRIPTION
Allows removal of aliases created with the `alias` command.
EXAMPLES
unalias dir
Removes the `dir` alias (usually an alias for `ls`).

View File

@ -0,0 +1,12 @@
NAME
uptime - how long has the computer been running
SYNOPSIS
uptime
DESCRIPTION
Writes the time in real time hours, minutes and seconds the computer has been running to the standard output.
EXAMPLES
uptime
Displays the time the computer has been running.

View File

@ -0,0 +1,15 @@
NAME
which - locate a command
SYNOPSIS
which COMMAND
DESCRIPTION
This program writes the full path to each of the specified programs to the standard output. If a program is an alias, this is indicated. If a program cannot be found and error message will be written.
EXAMPLES
which ls
Displays `/bin/ls.lua`.
which doesntexist dir
Displays `doesntexist: file not found` and `dir: aliased to ls`.