<?xml version="1.0" encoding="UTF-8"?>
<!--
# CLN: A simplistic CLI using XML to store commands
# Copyright (C) 2009  Niels Serup
#  
#	This file is part of CLN.
#
#	CLN is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#
#	CLN is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with CLN.  If not, see <http://www.gnu.org/licenses/>.
-->

<commands>

    <command>
        <name>exit</name>
        <name>quit</name>
        <name>die</name>
        <what>Exits CLN.</what>
        <usage></usage>
        <code>
            global done
            done = True
            
            cmd = inps[0]
            
            if cmd == 'exit':
                p = 'Exiting'
            elif cmd == 'quit':
                p = 'Quitting'
            elif cmd == 'die':
                p = 'Dying'
            put(p + '...')
        </code>
    </command>

    <command>
        <name>help</name>
        <what>Helps you. It tries at the very least.</what>
        <usage></usage>
        <code>
            w = ['', '']
            if not fullscreen:
                w[0] = 'go'
            else:
                w[0] = 'exit'
            
            if not highlighting:
                w[1] = 'enter'
            else:
                w[1] = 'exit'
            
            put('Welcome to CLN.\n\nThis is a command line application. Typing commands after the ">" sign and pressing Enter or Return will execute something. Commands are cAsE specific. Press the up or down arrow to use old commands. Type "whatis" followed by a command to find out more about that command. Type "exit" to quit CLN. Press F11 to ' + w[0] + ' fullscreen. Press PAGE UP and PAGE DOWN to scroll. Press CTRL + v to paste text into CLN. Press ALT + h to ' + w[1] + ' highlighting mode. In highlighting mode, use the arrow keys to highlight text. Use CTRL + [arrow key] to move the text cursor. Press CTRL + c to copy highlighted text. Press CTRL + a to highlight all text. When you want to exit highligting mode, either press ALT + h again, type something or press Enter.\nYou cannot use your mouse in CLN.')
        </code>
    </command>

    <command>
        <name>whatis</name>
        <name>what</name>
        <name>?</name>
        <what>Shows you the description of a command.</what>
        <usage>
            [{command} | -short] [none | -short]            
            If a command is specified as the first argument, details of that command will be shown. If no command is specified, details of all commands will be shown.
            If "-short" is specified as the first or second argument, only descriptions are shown. If no '-short' argument exists, both descriptions and command usage will be shown.
        </usage>
        <code>
            if (ilen > 1 and inps[1] == '-short') or (ilen > 2 and inps[2] == '-short'):
                shrt = True
            else:
                shrt = False
            
            if ilen > 1 and inps[1] != '-short':
                ciq = inps[1]
                if ciq == '-short' or (ilen > 2 and inps[2] == '-short'):
                    shrt = True
                else:
                    shrt = False
                
                cnode = False
                for node in command_topelem:
                    if getsubitem(node, {'tag': 'name', 'text': ciq}) != None:
                        cnode = node
                        break
                
                if cnode:
                    what = getsubitem(cnode, {'tag': 'what'})
                    usage = getsubitem(cnode, {'tag': 'usage'})
                    names = getsubitems(cnode, {'tag': 'name'})
                    
                    names_txt = ''
                    for x in names:
                        names_txt += x.text + ' / '
                    names_txt = names_txt[:-3]
                    
                    ft = names_txt + ':\n' + self.del_whitespace(what.text)
                    if not shrt and usage.text: ft += '\n\n Usage:\n' + ciq + ' ' + self.del_whitespace(usage.text)
                    
                    put(ft)
                else:
                    put('No such command seems to be existant in this metascientific program. Srsly.')
            else:
                ft = ''
                for node in command_topelem:
                    names = getsubitems(node, {'tag': 'name', 'attr:hidden': '!true'})
                    if len(names) > 0:
                        what = getsubitem(node, {'tag': 'what'})
                        usage = getsubitem(node, {'tag': 'usage'})
                        
                        names_txt = ''
                        for x in names:
                            if x.text: names_txt += x.text + ' / '
                        names_txt = names_txt[:-3]
                        
                        ft += names_txt + ':\n' + self.del_whitespace(what.text)
                        if not shrt and usage.text: ft += '\n\n Usage:\n' + names[0].text + ' ' + self.del_whitespace(usage.text)
                        ft += '\n  ------  \n'
                
                if ft != '':
                    ft = ft[:-12]
                    put(ft)
                else:
                    put('Huh? No commands? That\'s fishy.')
            
        </code>
    </command>
    
    <command>
        <name>fortune</name>
        <what>Reads a fortune.</what>
        <usage>
            [{fortune group} | {setting}] [{setting}]
            If a fortune group is not specified or if the specified fortune group doesn't exist, a random fortune will be returned.
            Specifying '-noff' as a setting will show only non-offensive fortunes.
            specifying '-off' as a setting will show only offensive fortunes.
            specifying '-what' or '?' as a setting will show a list of available fortune groups with a description.
            specifying '-what_s' or '?s' as a setting will show a list of available fortune groups with no description.
            Specifying '-what' or '?' as a setting after a fortune group will show a description of that fortune group.
        </usage>
        <code>
            put('No fortunes currently available. The fortune fetching part of CLN still needs to be developed.')
        </code>
    </command>
        
    <command>
        <name>whoami</name>
        <what>There's a chance you know it. In a far out scenario, you might actually recognise this name. "Why?", you ask. "Because it's yours!" I tell you. You scream in the horror of learning your real name. I laugh maniacly.</what>
        <usage>
            [-full]            
            Writing '-full' will return your complete name instead of simply the login name. Kind of buggy, I guess. Windows users shouldn't worry about this.
        </usage>
        <code>
            l = 'You don\'t seem to exist.'
            if ilen > 1 and inps[1] == '-full':
                et = True
            else:
                et = False
            
            if not et:
                try:
                    l = os.getlogin()
                except:
                    try: l = os.environ['USERNAME']
                    except: pass
            else:
                try:
                    l = os.environ['USERNAME']
                except:
                    pass
            put(l)
        </code>
    </command>

    <command>
        <name hidden='true'>kill</name>
        <what>Allows you to kill processes</what>
        <usage>
            [{process}]
        </usage>
        <code>
            put('Come on! This program is way to simple to involve people killing processes. And people.')
        </code>
    </command>

    <command>
        <name hidden='true'>xyzzy</name>
        <what>You are in a debris room filled with stuff washed in from the surface. A low wide passage with cobbles become plugged with mud and debris here, but an akward canyon leads upward and West. A note on the wall says "Magic Word XYZZY".</what>
        <usage></usage>
        <code>
            put("You're inside building.")
        </code>
    </command>
    
    <command>
        <name>zita</name>
        <what>Mini text adventure</what>
        <usage>[-cheat]</usage>
        <code>
            if ilen > 1 and inps[1] == '-cheat':
                ans = get('Are you sure you want to cheat?')
                if y(ans):
                    put('You won the game! 100 points!')
                else:
                    put('Too late. Cheater.')
            else:
                put('       ZITA       \n\n\n')
                put('You are standing in a forest in the middle of the night. You are unaware of how you got here. One thing you do know is that you come from the North. But you do not know what direction north is.\n\n')
                put('To the left is a pile of leaves.\n')
                a = get('>').lower()
                while a != 'get leaves' and a != 'take leaves':
                    put('Who do you think I am?\n')
                    a = get('>').lower()
                
                put('A sudden wind appears. The leaves protect me.\n')
                put('You see a light.\n')
                a = get('>').lower()
                while a == '':
                    put('\n')
                    a = get('>').lower()
                put('I try to ' + a + ', but I do not succeed. I have only one choice left.\n')
                b = get('>').lower()
                while b == '':
                    put('\n')
                    b = get('>').lower()
                if (a == b):
                    put('I once again try to ' + a + ', and this time it seems to work!\n')
                else:
                    put('I attempt to ' + b + ', and this time it seems to work!\n')
                
                put('You have won!')
        </code>
    </command>

</commands>
