Jump to content

Command Interpreter in AutoIt (As Secure says)


i542
 Share

Recommended Posts

  • Replies 87
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I have finished modifying the document, and I have attached my own version with some extra functions:

Commands are:

help /?

color blue, purple, pink, rose, green, white, black

cd open/close

beep, frequency, duration

popup, title, message

gui, width, height

exit

about

computer

I made a refactory in your help. I think it would be improved later.

;by Secure_ICT
#include <GuiConstants.au3>

#NoTrayIcon

$font = "Courier New"

$gui = GUICreate("My Programming Command Line", 482, 250, -1,-1)
GUISetIcon("shell32.dll", 42)
$txt = GUICtrlCreateEdit("", 0, 0, 481, 217, $ES_READONLY + $WS_VSCROLL)
GUICtrlSetFont (-1, 9, 400, 4, $font)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetColor(-1, 0xffffff)
GUICtrlSetData($txt, "> Welcome to mycommand line, you are logged in as: " & @UserName & @CRLF)
$cLine = GUICtrlCreateInput("", 5, 224, 380, 21)
GuiCtrlSetData($cLine, ">", "")
$Execute = GUICtrlCreateButton("Execute", 390, 221, 89, 25, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)

While 1
   $msg = GuiGetMsg()
   Select
   Case $msg = $GUI_EVENT_CLOSE
       ExitLoop
   Case $msg = $Execute
       $string = StringSplit(GuiCtrlRead($cLine), Chr(44))
        Switch $string[1]
            Case ">clear"
                _ConsoleWrite("> Clearing...")
                Sleep(1000)
                GUICtrlSetData($txt, "", "")
                GuiCtrlSetData($cLine,">", "")
            Case ">echo"
                $string[2] = _TrimSpaces($string[2])
                _ConsoleWrite($string[2])
                GuiCtrlSetData($cLine, ">", "")
            Case ">beep"
                $string[2] = _TrimSpaces($string[2])
                Beep($string[2], $string[3])
                _ConsoleWrite("> Beep successfull")
                GUICtrlSetData($cLine, ">", "")
            Case ">exit"
                _ConsoleWrite("> Goodbye.")
                Sleep(1000)
                Exit
            Case ">computer"
                _ConsoleWrite("> Your username is: " & @Username)
                _ConsoleWrite("> Your computer name is: " & @ComputerName)
                _ConsoleWrite("> Your Operating System is: " & @OSVersion)
                _ConsoleWrite("> Service Pack is: " & @OSServicePack)
                _ConsoleWrite("> OS Build: " & @OSBuild)
                _ConsoleWrite("> Language: " & @OSLang)
                GuiCtrlSetData($cLine, ">", "")
            Case ">about"
                _ConsoleWrite("> My Programming Language")
                _ConsoleWrite("> Created with i542's Programming Language System")
                _ConsoleWrite("> This language is licensed to: Secure_ICT")
                GuiCtrlSetData($cLine, ">", "")
            Case ">gui"
                $checkline = GUICtrlRead($cLine)
                If $checkline = ">gui" Then
                    _ConsoleWrite("> You have not specified width and height to create a GUI.")
                Else
                _ConsoleWrite("> Creating GUI")
                Sleep(1000)
                _NewGUI()
                EndIf
                GUICtrlSetData($cLine, ">", "")
            Case ">popup"
                MsgBox(0, $string[2], $string[3])
                GUICtrlSetData($txt,"<Popup Executed Successfully>" & @CRLF, GuiCtrlRead($txt))
                GuiCtrlSetData($cLine, ">", "")
            Case ">title"
                WinSetTitle($gui, "", $string[2])
                GuiCtrlSetData($cLine, ">", "")
            Case ">color green"
                GUICtrlSetBkColor($txt, 0xaaffbb)
                GUICtrlSetColor($txt, 0x000000)
                GuiCtrlSetData($cLine, ">", "")
            Case ">color white"
                GUICtrlSetBkColor($txt, 0xffffff)
                GUICtrlSetColor($txt, 0x000000)
                GuiCtrlSetData($cLine, ">", "")
            Case ">color blue"
                GUICtrlSetBkColor($txt, 0x00ffff)
                GUICtrlSetColor($txt, 0x000000)
                GuiCtrlSetData($cLine, ">", "")
            Case ">color rose"
                GUICtrlSetBkColor($txt, 0xddacaa)
                GUICtrlSetColor($txt, 0x000000)
                GuiCtrlSetData($cLine, ">", "")
            Case ">color pink"
                GUICtrlSetBkColor($txt, 0xddacee)
                GUICtrlSetColor($txt, 0x000000)
                GuiCtrlSetData($cLine, ">", "")
            Case ">color black"
                GUICtrlSetBkColor($txt, 0x000000)
                GUICtrlSetColor($txt, 0xffffff)
                GuiCtrlSetData($cLine, ">", "")
            Case ">cd open"
                $drive = DriveGetDrive("CDROM")
                CDTray($drive, "open")
                _ConsoleWrite("CD Tray Opened")
                GuiCtrlSetData($cLine, ">", "")
            Case ">cd close"
                CDTray("H:\", "closed")
                _ConsoleWrite("CD Tray Closed")
                GuiCtrlSetData($cLine, ">", "")
            Case ">computer"
                _ConsoleWrite("> Syntax: computer")
                _ConsoleWrite("> Shows the computer information")
                _ConsoleWrite("> Remarks: none")
                GuiCtrlSetData($cLine, ">", "")
            Case ">"
                _ConsoleWrite("> You forgot to add a command")
                GuiCtrlSetData($cLine, ">", "")
            Case ">gui"
                _ConsoleWrite("> You haven't added any values to the width and height.")
                _ConsoleWrite("> Example: >gui, 400, 500")
                GuiCtrlSetData($cLine, ">", "")
            Case Else
                If Help( $string[1] ) = 0 Then
                    _ConsoleWrite("Error with syntax: " & $string[1])
                    _ConsoleWrite("Use help /? to find help!")
                EndIf
                GuiCtrlSetData($cLine, ">", "")
        EndSwitch
   EndSelect
WEnd

Func _ConsoleWrite($text)
   GUICtrlSetData($txt, $text & @crlf, GUICtrlRead($txt))
EndFunc

Func _TrimSpaces(ByRef $parameter)
   Local $string
   $string = StringSplit($parameter, "")
   If $string[1] = Chr(44) then
       $string = StringtrimLeft($parameter,1)
       Return $string
   Else
       Return $parameter
   EndIf
EndFunc

Func _NewGUI()
$nGUI = GuiCreate("New GUI", $string[2], $string[3], -1, -1)
GuiSetState(@SW_SHOW)

While WinActive($nGUI)
    $gMsg = GuiGetMsg()
    Switch $gMsg
    Case $GUI_EVENT_CLOSE
        GUIDelete($nGUI)
    EndSwitch
WEnd
EndFunc

Func Help( $Cmd )
    Local $ParamList = StringSplit( $Cmd, " " )
    If $ParamList[0] Then
        If $ParamList[1] = ">help" Then
            If $ParamList[0] >= 2 Then
                Switch $ParamList[2]
                    Case "/echo"
                        _ConsoleWrite("> Syntax: echo, <text>")
                        _ConsoleWrite("> Places text in this control")
                        _ConsoleWrite("> Remarks: none")
                    Case "/popup"
                        _ConsoleWrite("> Syntax: popup, <title>, <text>")
                        _ConsoleWrite("> Makes a popup appear")
                        _ConsoleWrite("> Remarks: none")
                    Case "/clear"
                        _ConsoleWrite("> Syntax: clear")
                        _ConsoleWrite("> Clears all of the text in the control")
                        _ConsoleWrite("> Remarks: none")
                    Case "/exit"
                        _ConsoleWrite("> Syntax: exit")
                        _ConsoleWrite("> Closes the command window")
                        _ConsoleWrite("> Remarks: none")
                    Case "/beep"
                        _ConsoleWrite("> Syntax: beep {Frequency, Duration}")
                        _ConsoleWrite("> Plays back a beep to the user")
                        _ConsoleWrite("> Remarks: Requires numbers e.g. beep, 500, 1000")
                    Case "/color"
                        _ConsoleWrite("> Syntax: color {rose, black, white, green, blue}")
                        _ConsoleWrite("> Changes the background colour")
                        _ConsoleWrite("> Remarks: Select one color e.g. color green")
                    Case "/cd"
                        _ConsoleWrite("> Syntax: cd {open,close}")
                    Case "/title"
                        _ConsoleWrite("> Syntax: title {new title}")
                        _ConsoleWrite("> Changes the window title")
                        _ConsoleWrite("> Remarks: Example; title, James Brooks Programming Command Line")
                    Case "/gui"
                        _ConsoleWrite("> Syntax: gui {width, height}")
                        _ConsoleWrite("> Creates a GUI")
                        _ConsoleWrite("> Remarks: A random GUI.")
                    Case Else
                        _ConsoleWrite("> Syntax: help {command in which you need help}")
                        _ConsoleWrite("> Shows the help information and example. Commands are, help {color, exit, clear, popup, echo, beep}")
                        _ConsoleWrite("> Remarks: Shows help info e.g help /exit")
                EndSwitch
            Else
                _ConsoleWrite("> Syntax: help {command in which you need help}")
                _ConsoleWrite("> Shows the help information and example. Commands are, help {color, exit, clear, popup, echo, beep}")
                _ConsoleWrite("> Remarks: Shows help info e.g help /exit")
            EndIf
            return 1
        EndIf
    EndIf
    return 0
EndFunc

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator

VW Bug user

Pinheiral (Pinewood) city:

http://pt.wikipedia.org/wiki/Pinheiral

Link to comment
Share on other sites

Why have you changed it like that?

It's an example to show how it would be organized. Each "function" of program must be separated from main code, for future maintenance.

Well.. I think....

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator

VW Bug user

Pinheiral (Pinewood) city:

http://pt.wikipedia.org/wiki/Pinheiral

Link to comment
Share on other sites

I suppose, it looks neater.

Yes.

If the treatment for each function is separated, the main code is more easy to read.

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator

VW Bug user

Pinheiral (Pinewood) city:

http://pt.wikipedia.org/wiki/Pinheiral

Link to comment
Share on other sites

thank you! :)

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator

VW Bug user

Pinheiral (Pinewood) city:

http://pt.wikipedia.org/wiki/Pinheiral

Link to comment
Share on other sites

Er, none of your cd-drives will ever close unless your cd-drive is h:. Its hardcoded in:/

Link to comment
Share on other sites

where????

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator

VW Bug user

Pinheiral (Pinewood) city:

http://pt.wikipedia.org/wiki/Pinheiral

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...