CUI - UDF

  • Hallo^^,

    ich habe mal eine kleine UDF gebastelt da AutoIt wenig möglichkeiten bietet eine Console schön zu gestalten :)

    Das ist erst meine 2te UDF also erwartet nicht zuviel *gg*

    UDF
    [autoit]

    Global $sBatPath, $sTitle
    #cs=====================CUI UDF===============================================

    [/autoit] [autoit][/autoit] [autoit]

    Credits: Christopher Kaster <Kasoki> : kasoki.de | [email='kasoki@arcor.de'][/email]

    [/autoit] [autoit][/autoit] [autoit]

    This is an UDF to use a better CUI System.

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ToDo:
    - I must work on a Read Command ;)
    - More Comming soon.

    [/autoit] [autoit][/autoit] [autoit]

    -------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    Copyright by Kasoki 2009. All Rights Reserved.
    #ce============================================================================
    ;==============================================================================
    ;
    ; Function: _CUI_Create($title)
    ; Parameters: $title - The title of our Console.
    ; Description: Creates a CUI with a title
    ;
    ; AutoIt Ver: 3.3 or higher
    ; Last Updatet: 20.06.09 - 16:54
    ;
    ; Author: Christopher Kaster <kasoki>
    ;
    ;==============================================================================
    Func _CUI_Create($title)
    $sBatPath = @TempDir & "/tmpCUI_" & $title & ".bat"
    FileDelete($sBatPath)
    Global $fFile = FileOpen($sBatPath,1)
    FileWrite($fFile, "@echo off" & @CRLF & "TITLE " & $title & @CRLF)
    FileClose($fFile)
    $sTitle = $title
    EndFunc ;==>
    ;==============================================================================
    ;
    ; Function: _CUI_Write($sText)
    ; Parameters: $sText - The text which will write into the Console
    ; Description: Write a Text into the Console
    ;
    ; AutoIt Ver: 3.3 or higher
    ; Last Updatet: 20.06.09 - 16:54
    ;
    ; Author: Christopher Kaster <kasoki>
    ;
    ;==============================================================================
    Func _CUI_Write($sText)
    $hWrite = FileOpen($sBatPath,1)
    FileWrite($hWrite, "echo " & $sText & @CRLF)
    FileClose($hWrite)
    EndFunc ;==>
    ;==============================================================================
    ;
    ; Function: _CUI_Command($sCommand)
    ; Parameters: $sCommand - With this Command you can use the CMD Commands.
    ; Description: Use a CMD Command (Example: CD (Choose Directionary))
    ;
    ; AutoIt Ver: 3.3 or higher
    ; Last Updatet: 20.06.09 - 16:54
    ;
    ; Author: Christopher Kaster <kasoki>
    ;
    ;==============================================================================
    Func _CUI_Command($sCommand)
    $fCommand = FileOpen($sBatPath,1)
    FileWrite($fCommand, $sCommand & @CRLF)
    FileClose($fCommand)
    EndFunc ;==>
    ;==============================================================================
    ;
    ; Function: _CUI_SetColor($cBackground, $cTextcolor)
    ; Parameters: $cBackground - Change the Backgroundcolor (Example: black)
    ; $cTextcolor - Change the Textcolor (Example: white)
    ; Description: Change the Color of Text and Background.
    ;
    ; AutoIt Ver: 3.3 or higher
    ; Last Updatet: 20.06.09 - 16:54
    ;
    ; Author: Christopher Kaster <kasoki>
    ;
    ;==============================================================================
    Func _CUI_SetColor($cBackground, $cTextcolor)
    Switch $cBackground
    Case "black"
    $bgcolor = 0
    Case "darkblue"
    $bgcolor = 1
    Case "darkgreen"
    $bgcolor = 2
    Case "bluegreen"
    $bgcolor = 3
    Case "darkred"
    $bgcolor = 4
    Case "purple"
    $bgcolor = 5
    Case "ocher"
    $bgcolor = 6
    Case "lightgray"
    $bgcolor = 7
    Case "darkgray"
    $bgcolor = 8
    Case "blue"
    $bgcolor = 9
    Case "green"
    $bgcolor = "A"
    Case "cyan"
    $bgcolor = "B"
    Case "red"
    $bgcolor = "C"
    Case "magenta"
    $bgcolor = "D"
    Case "yellow"
    $bgcolor = "E"
    case "white"
    $bgcolor = "F"
    EndSwitch
    Switch $cTextcolor
    Case "black"
    $fgcolor = 0
    Case "darkblue"
    $fgcolor = 1
    Case "darkgreen"
    $fgcolor = 2
    Case "bluegreen"
    $fgcolor = 3
    Case "darkred"
    $fgcolor = 4
    Case "purple"
    $fgcolor = 5
    Case "ocher"
    $fgcolor = 6
    Case "lightgray"
    $fgcolor = 7
    Case "darkgray"
    $fgcolor = 8
    Case "blue"
    $fgcolor = 9
    Case "green"
    $fgcolor = "A"
    Case "cyan"
    $fgcolor = "B"
    Case "red"
    $fgcolor = "C"
    Case "magenta"
    $fgcolor = "D"
    Case "yellow"
    $fgcolor = "E"
    case "white"
    $fgcolor = "F"
    EndSwitch
    $color = FileOpen($sBatPath,1)
    FileWrite($color, "COLOR " & $bgcolor & $fgcolor & @CRLF)
    FileClose($color)
    EndFunc ;==>
    ;==============================================================================
    ;
    ; Function: _CUI_ChangeTitle($sNewTitle)
    ; Parameters: $sNewTitle - The new Title of our Console.
    ; Description: Change the title from our CUI
    ;
    ; AutoIt Ver: 3.3 or higher
    ; Last Updatet: 20.06.09 - 16:54
    ;
    ; Author: Christopher Kaster <kasoki>
    ;
    ;==============================================================================
    Func _CUI_ChangeTitle($sNewTitle)
    $sTitle2 = FileOpen($sBatPath,1)
    FileWrite($sTitle2, "TITLE " & $sNewTitle & @CRLF)
    FileClose($sTitle)
    $sTitle = $sNewTitle
    EndFunc ;==>
    ;==============================================================================
    ;
    ; Function: _CUI_Run($iDelay)
    ; Parameters: $iDelay - The Sleep Delay (How long must i wait before i start the console
    ; Description: Start our Console.
    ;
    ; AutoIt Ver: 3.3 or higher
    ; Last Updatet: 20.06.09 - 16:54
    ;
    ; Author: Christopher Kaster <kasoki>
    ;
    ;==============================================================================
    Func _CUI_Run($iDelay)
    Sleep($iDelay)
    $fLoop = FileOpen($sBatPath,1)
    FileWrite($fLoop, ":Loop" & @CRLF & "goto :Loop" & @CRLF)
    FileClose($fLoop)
    Run($sBatPath)
    WinWaitClose($sTitle)
    EndFunc ;==>
    ;===============================================================================

    [/autoit]
    Example
    [autoit]

    #include "CUI.au3"

    [/autoit] [autoit][/autoit] [autoit]

    _CUI_Create("Kasokis CUI UDF Example") ;Console Title
    _CUI_SetColor("black","darkgreen") ;Background Color: black and Textcolor: darkgreen
    _CUI_Write('#### _CUI_WRITE("TEXT") ####') ;Write a Text
    _CUI_Command("ECHO MIT _CUI_COMMAND('ECHO Könnt ihr CMD Commands nutzen')"); Use the Command ECHO (Write)
    _CUI_Run(5) ;Run after 5ms

    [/autoit]


    Lg

    Kasoki :)

  • Also bei mir komt ein fehler

    Code
    $color = FileOpen($sBatPath,1)
    $color = FileOpen(^ ERROR
  • Aus: _CUI_Create ()

    [autoit]

    FileDelete($sBatPath)
    Global $fFile = FileOpen($sBatPath,1)

    [/autoit]


    Da wird eine Datei geöffnet, die soeben gelöscht wird - oder sehe ich das falsch?

    MfG. tobi_girst

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »tobi_girst« (Morgen, 25:63)

  • siehst du falsch ^^ bevor sie entsteht wird sie gelöscht das ist dafür da falls du das programm mehrmals startest das die alte temporäre datei weg ist

    ich hab das ganze ja ausgiebig getestet und bei mir funktionierte alles einwandfrei :)

  • Ich mache gerade auch ein CUI - UDF, der Unterschied ist aber das ich win32 Funktionen benutzte, so kann man die Farbe des Textes quasi live ändern, im moment muss ich es aber noch schaffen den Ouput von ConsoleWrite umzuleiten, so das nicht alle Scripts als Consolen Exe compiled werden müssen.

  • also bei dem beispiel kommt bei mir nur 1 schwarzes fenster und verschwindet schnell wieder , soll dass so sein ? oder wie soll das aussehen :?:

  • Das mehrfache Starten kannst du mit

    [autoit]

    _singleton

    [/autoit]

    unterbinden.
    MfG

    MfG. tobi_girst

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »tobi_girst« (Morgen, 25:63)

  • Kasoki habe da noch nen fast fertigen Befehl für gemacht da würde nur noch der
    befehl fehln wass kommen soll wenn das passwort richtig ist^^ O.o meine 1 UDF (naya so halb)

    Spoiler anzeigen
    [autoit]


    ;===============================================================================
    ; Function: _CUI_PW($Text,$Password,$Befehl)
    ; Parameters: $Text - The message of the "dialog"
    ; $Password - The password (needed for the command)
    ; $Befehl - The command (Example: Start [your programm] )
    ; Description: Sets a Password for following Command
    ;
    ; AutoIt Ver: 3.3.0.0 or higher
    ;
    ; Author: Johnnyboyy (Autoit.de member)
    ;
    ;==============================================================================
    Func _CUI_PW($Text,$Password,$Befehl)
    $Data = FileOpen($sBatPath,1)
    FileWrite($Data,"set /p PW=" &$Text & @CRLF)
    FileWrite($Data,"if %PW%=="&$Password& " " &$Befehl& @CRLF)
    FileWrite($Data,"pause >nul")
    FileClose($Data)
    EndFunc

    [/autoit]


    Example/Beispiel

    Spoiler anzeigen
    [autoit]


    #include <CUI.au3>
    _CUI_Create("Creator")
    _CUI_Write("my first CUI with autoit")
    _CUI_PW("What is the Password ? = ","1234","start Firefox")
    ; start Firefox startet den Firefox browser, da ich noch nicht lange
    ; mit batch arbeite weis ich nicht wie mansachen downloaded sons wär´n beispiel da
    _CUI_Run(100)

    [/autoit]
    [autoit]


    #cs-----------------------------------------------------------------------------
    Hilfe ist immer gut also nimmt sie an ^^
    #ce-----------------------------------------------------------------------------

    [/autoit]

    6 Mal editiert, zuletzt von johnnyboyy (27. Juni 2009 um 13:30)