Jump to content
gil900

SciTE Console: _cin _cout for SciTE Console [ConsoleIn (!!) , ConsoleOut , ConsoleClean ..]

Recommended Posts

gil900

Hello,
This udf open for you the ability to not only write in the console (in SciTE),
It allows you to write inputs in the console.

In other words:
It is exactly like the cin function
in C++ (in namespace std) and it works on SciTE and it is better.


Example 1:
output_Eou0tV.gif.e12ce5d33a6bf29350de02

Example 2:

output_mxi55n.gif.5255187e01295a62e7f80f

 

 

Example 1 code:

#include 'SciTE Console.au3'


HotKeySet('{ESC}','Exit1')


_ConsoleClean()


Local $sTitle = 'Hello World!'
Local $sText = 'Hello!'&@CRLF&'This is some saved text...'&@CRLF&'You can change me if you want!'

_cout('Hello! what do you want to do now?')
_cout('1 = print/edit variables , 2 = change console settings , 3 = clean the console , 4 = exit')

While 1


    ;
    Switch Number(_cin(1))
        Case 1
            _cout(' -> print/edit variables:',1)
            While 1
                _cout('Enter 1.1 to show variables, 1.2 to edit them, 1.3 to exit this mode:')
                Switch Number(_cin())
                    Case 1.1
                        _cout('The string value of $sTitle is: '&$sTitle,2)
                        _cout('The string value of $sText is:')
                        _cout($sText,2)

                    Case 1.2
                        _cout('Enter some text for $sTitle: ',0)
                        $sTitle = _cin()
                        _cout('The text of $sTitle is: '&$sTitle)

                        _cout('Enter some text for $sText. Write "@@@" to finish (you can use enter now). :')
                        $sText = _cin(1,'@@@')
                        _cout('')
                        MsgBox(0,'The text is',$sText)

                    Case 1.3
                        _cout('Exited')
                        ExitLoop

                    Case Else
                        _cout('You must enter only 1.1-1.3')
                EndSwitch

            WEnd

        Case 2
            _cout(' -> Do you want to always show the line number? select y for yes, n for no: ',0)
            If _cin(1) = 'y' Then
                $gg_sc_bPrintLine = True
            Else
                $gg_sc_bPrintLine = False
            EndIf

            _cout('')

            _cout("Enter the writing speed (10 is recommended!). use 0 for instantaneous speed. WARNING: don't use big number!! : ",0)
            $gg_sc_iWriteSpeed = Int(Number(_cin()))
            _cout('Write speed set to '&$gg_sc_iWriteSpeed)
            _cin('Settings saved.')

        Case 3
            ;~          Sleep(100)
            _ConsoleClean()
        Case 4
            _cout(' -> Are you sure? Select y/Y for yes, n/N for no: ',0)
            While 1
                Switch _cin(1)
                    Case 'y','Y'
                        _cout(' -> Exiting...')
                        Sleep(500)
                        Exit
                    Case 'n','N'
                        _cout('',1,@CRLF)
                        ExitLoop
                    Case Else
                        _cout(@CRLF&' -> You must enter y/Y or n/N. Select y/Y for yes, n/N for no: ',0)
                EndSwitch
            WEnd
        Case Else
            _cout(@CRLF&'You can enter only 1-4')
    EndSwitch
WEnd












Func Exit1()
    Exit
EndFunc

 

Example 2 code (Ported from _GUIConsole) :

#include 'SciTE Console.au3'


HotKeySet('{ESC}','Exit1')

; Clean the console
_ConsoleClean()


$gg_sc_iWriteSpeed = 15 ; Set the write speed to 15 (Read more in "ARIABLES FOR THE USER" in SciTE Console.au3)

; Print some text
_cout('Some text 1 ...');,$iAddLines = 1,$sAddChar = @CRLF)

Sleep(500)
; Print some text
_cout('Some text 2 ...')

Sleep(500)

_cout('After this text there is 3 @CRLF',3)

Sleep(500)

_cout('See?')

Sleep(1000)

_cout('After this text there is 3 @TAB',3,@TAB)

Sleep(500)

_cout('See?',2)

Sleep(1000)

_cout('Now I will clean this console and write some new text...')

Sleep(1500)

; Clean the Console
_ConsoleClean()

Sleep(500)

; Create the Console GUI
; Print some text
_cout('Some text 1 ...');,$iAddLines = 1,$sAddChar = @CRLF)

Sleep(500)
; Print some text
_cout('Some text 2 ...')


While Sleep(100)
WEnd



#Region functions
Func Exit1()
    Exit
EndFunc

#EndRegion

 

UDF Download:
SciTE Console v1 (by gil900).rar

 

 

 

Edited by gil900
  • Like 2

Share this post


Link to post
Share on other sites
gil900

Updated: added example for _cout (ported example from _GUIConsole)

Edited by gil900

Share this post


Link to post
Share on other sites
gil900

I developed a more modular way  of how to create each console "dialog"
I try to think of an concept that make it easy to implement under the Autoit limitation that is it is missing multi thread option.

There is good way to handle and create multiple GUIs, in one While loop.. but how you do it with console like this (in one While loop) ?  That's what I'm trying to solve.

 

this is what i come with:

Example:

#include 'SciTE Console.au3'
#include 'Console.au3'

HotKeySet('{ESC}','Exit1')





_ConsoleClean()





;~ Exit

Local $sTitle = 'Hello World!'
Local $sText = 'Hello!'&@CRLF&'This is some saved text...'&@CRLF&'You can change me if you want!'

;~ _cout('Hello! what do you want to do now?')
;~ _cout('1 = print/edit variables , 2 = change console settings , 3 = clean the console , 4 = exit')



HomeOptions()


Func HomeOptions()
    _cout('1 = print/edit variables , 2 = change console settings'); , 3 = clean the console , 4 = exit')

    _Console_UnRegisterAllInputs()

    _Console_RegisterInput('1',HomeOptions_PrintOrEditVars)
    _Console_RegisterInput('2',HomeOptions_ChangeConsoleSettings)


EndFunc

#Region HomeOptions_PrintOrEditVars_*

    Func HomeOptions_PrintOrEditVars()
        _cout(' -> print/edit variables:',1)
        _cout('Enter 1.1 to show variables, 1.2 to edit them, 1.3 to exit this mode:')

        _Console_UnRegisterAllInputs()

        _Console_RegisterInput('1.1',HomeOptions_PrintOrEditVars_Option_1d1)
        _Console_RegisterInput('1.2',HomeOptions_PrintOrEditVars_Option_1d2)
        _Console_RegisterInput('1.3',HomeOptions_PrintOrEditVars_Option_1d3)

    EndFunc

    ; OPTIONS:
        Func HomeOptions_PrintOrEditVars_Option_1d1()
            _cout('The string value of $sTitle is: '&$sTitle,2)
            _cout('The string value of $sText is:')
            _cout($sText,2)
        EndFunc


        Func HomeOptions_PrintOrEditVars_Option_1d2()
            _cout('Enter some text for $sTitle: ',0)
            $sTitle = _cin()
            _cout('The text of $sTitle is: '&$sTitle)

            _cout('Enter some text for $sText. Write "@@@" to finish (you can use enter now). :')
            $sText = _cin(1,'@@@')
            _cout('')
            MsgBox(0,'The text is',$sText)

        EndFunc


        Func HomeOptions_PrintOrEditVars_Option_1d3()
            _cout('Exited')
            HomeOptions()


        EndFunc

#EndRegion


#Region ChangeConsoleSettings_*
    Func HomeOptions_ChangeConsoleSettings()
        _Console_UnRegisterAllInputs()
        _cout('HomeOptions_ChangeConsoleSettings.',1)
        _cout('q = exit',1)
        _Console_RegisterInput('q',HomeOptions_ChangeConsoleSettings_exit)

    EndFunc

    Func HomeOptions_ChangeConsoleSettings_exit()
        HomeOptions()
    EndFunc
#EndRegion





While Sleep(10)

    _Console_ProcessRegisteredInputs(_cin(1))


WEnd



#cs OLD CODE

While 1


    ;
    Switch Number(_cin(1))
        Case 1
            _cout(' -> print/edit variables:',1)
            While 1
                _cout('Enter 1.1 to show variables, 1.2 to edit them, 1.3 to exit this mode:')
                Switch Number(_cin())
                    Case 1.1
                        _cout('The string value of $sTitle is: '&$sTitle,2)
                        _cout('The string value of $sText is:')
                        _cout($sText,2)

                    Case 1.2
                        _cout('Enter some text for $sTitle: ',0)
                        $sTitle = _cin()
                        _cout('The text of $sTitle is: '&$sTitle)

                        _cout('Enter some text for $sText. Write "@@@" to finish (you can use enter now). :')
                        $sText = _cin(1,'@@@')
                        _cout('')
                        MsgBox(0,'The text is',$sText)

                    Case 1.3
                        _cout('Exited')
                        ExitLoop

                    Case Else
                        _cout('You must enter only 1.1-1.3')
                EndSwitch

            WEnd

        Case 2
            _cout(' -> Do you want to always show the line number? select y for yes, n for no: ',0)
            If _cin(1) = 'y' Then
                $gg_sc_bPrintLine = True
            Else
                $gg_sc_bPrintLine = False
            EndIf

            _cout('')

            _cout("Enter the writing speed (10 is recommended!). use 0 for instantaneous speed. WARNING: don't use big number!! : ",0)
            $gg_sc_iWriteSpeed = Int(Number(_cin()))
            _cout('Write speed set to '&$gg_sc_iWriteSpeed)
            _cin('Settings saved.')

        Case 3
            ;~          Sleep(100)
            _ConsoleClean()
        Case 4
            _cout(' -> Are you sure? Select y/Y for yes, n/N for no: ',0)
            While 1
                Switch _cin(1)
                    Case 'y','Y'
                        _cout(' -> Exiting...')
                        Sleep(500)
                        Exit
                    Case 'n','N'
                        _cout('',1,@CRLF)
                        ExitLoop
                    Case Else
                        _cout(@CRLF&' -> You must enter y/Y or n/N. Select y/Y for yes, n/N for no: ',0)
                EndSwitch
            WEnd
        Case Else
            _cout(@CRLF&'You can enter only 1-4')
    EndSwitch
WEnd

#ce










Func Exit1()
    Exit
EndFunc

 

And the new UDF I just made - Console.au3. I have no idea how to call it.

Global Enum _
    $__Console_aInputs_idx2_sHotString, _
    $__Console_aInputs_idx2_Func, _
    $__Console_aInputs_idx2max

Global $__Console_aInputs[1][$__Console_aInputs_idx2max]







Func _Console_RegisterInput($sHotString,$Function)
    ; Look for the function index
    Local $iFuncIndex
    For $a = 1 To $__Console_aInputs[0][0]
        If $__Console_aInputs[$a][$__Console_aInputs_idx2_Func] <> $Function Then ContinueLoop
        $iFuncIndex = $a
    Next

    If Not $iFuncIndex Then
        $__Console_aInputs[0][0] += 1
        ReDim $__Console_aInputs[$__Console_aInputs[0][0]+1][$__Console_aInputs_idx2max]
        $iFuncIndex = $__Console_aInputs[0][0]
    EndIf

    $__Console_aInputs[$iFuncIndex][$__Console_aInputs_idx2_sHotString] = $sHotString
    $__Console_aInputs[$iFuncIndex][$__Console_aInputs_idx2_Func] = $Function

EndFunc

Func _Console_ProcessRegisteredInputs(ByRef $sInput)
    ;If Not $__Console_aInputs[0][0] Then Return

    For $a = 1 To $__Console_aInputs[0][0]
        If $sInput <> $__Console_aInputs[$a][$__Console_aInputs_idx2_sHotString] Then ContinueLoop
        Return $__Console_aInputs[$a][$__Console_aInputs_idx2_Func]()
    Next

EndFunc



Func _Console_UnRegisterAllInputs()
    ReDim $__Console_aInputs[1][$__Console_aInputs_idx2max]
    $__Console_aInputs[0][0] = 0
EndFunc

 

Edited by gil900

Share this post


Link to post
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

  • Similar Content

    • Jos
      By Jos
      7/8/2018: Uploaded a new SciTe4AutoIt3.exe v18.708.1148.0 installer.
      It has been over a year since the last update of the full SciTE4AutoIt3 installer whch mainly had to do with the fact that Neil was moving toward v4 of SciTE and I wanted to wait for a stable version.
      Any help with testing this version before general release is appreciated.
      Also any feedback is welcome in caseI missed something or suggestions for improvement before releasing.
      ==> SciTE4AutoIt3 v18.708.1148.0
      Enjoy,
      Jos

      Addition/Changes/Fixes in the current installer:
      -------------------------------------------------------------------------------------------------- 8-7-2018 *** Merged the SciTE v 4.1.0 by Neil Hodgson with our own version of SciTE. (Jos)     This is a major change from the previous version so ensure you update all files including LUA or else you will get errors!     - SciLexer au3: Fixed issues with nested CommentBlocks not always showing the correct color.     - SciLexer au3: Change any line starting with # and no recognised keyword to be shown with the Pre-Processor in stead of default.     - Changed Shortcut for AU3INFO to Ctrl+Shift+F6.     - Moved the session restore logic for (save.session.advanced=1)into SciTE in stead of LoadSession.lua as that was clearing the recent files list of the last session       when opening a file by double cliking it. This is fixed with this change.       Default remains 0 so when a file is double clicked the last session isn't restored unless you add this to SciTEuser.properties:       "save.session.advanced=1"     - updated Tools.lua replacing [s%] with [ /t] to avoid empty lines being stripped by those functions. (Thanks Enyby) *** Updated AutoIt3Wrapper v18.708.1148.0 (Jos)     - 17.224.935.1 Added /autoit3dir to au3stripper commandline, when provided to AutoIt3Wrapper., to ensure the included files are for the correct AutoIt3 directory     - 17.224.935.2 Added directives:          #AutoIt3Wrapper_Res_CompanyName=          ;Company field          #AutoIt3Wrapper_Res_LegalTrademarks=      ;Trademark field     - 17.224.935.5 Fixed Versioning when files contain backets ->  ()     - 17.224.935.6 Added support for :          #AutoIt3Wrapper_Au3stripper_Stop_OnError=        ;(Y/N) Continue/Stop on Warnings.(Default=N)     - 17.224.935.7 added INI support for:           [Other]            Au3Stripper_Stop_OnError=n     - 17.224.935.10 Minor changes in console messages     - 17.224.935.11 Modifications from JPM:         - add #AutpIt3Wrapper_Res_Cursor_Add         - "clean" a little bit AutoIt3Wrapper.au3 *** Updated Au3Stripper v18.708.1148.0 (Jos)     - 17.224.935.1 Fixed crash when an include file contains longer record than 4096 characters.     - 17.224.935.2 Changed /rsln to replace @ScriptLineNumber in the Master script with "XXX/YYY". XXX is the master script linenumber, YYY is the Merged script linenumber.     - 17.224.935.3 Fixed issue detecting #cs #ce when a space was missing after the directive.     - 17.224.935.4 Changed Close/Open logic for Tracelog to (hopefully) avoid the hardcrash.     - 17.224.935.5 improved speed avoiding rereading include files to determine the max rec len.     - 17.224.935.6 improved speed by re-coding the check for long records.     - 17.224.935.7 Made sure the returncode is the highest from all iterations in stead of the last iteration.     - 17.224.935.8 fix for reported bug: https://www.autoitscript.com/trac/autoit/ticket/3623#comment:4     - 17.224.935.9 added support for #autoit3wrapper_autoit3dir     - 17.224.935.10 Fixed support for #autoit3wrapper_autoit3dir when followed by linecomment                     Stop processing when include file isn't found.     - 18.624.1847.1 strip the leading and trailing double quotes from the autoit3dir directive to avoid an error when they are specified.     - 18.624.1847.2 Fixed Hardcrash in the Include logic     - 18.624.1847.3 Fixed Hardcrash in Func stripping logic by enlarging the base table size     - 18.702.1556.1 Fixed regression bug with the Translate option.     - 18.703.1808.2 Fixed regression bug with the Stripping FUNC logic for the first found FUNC. *** Updated SciTEConfig v18.708.1148.0 (Jos)     - 17.224.935.1 No updates *** Updated Tidy v18.708.1148.0 (Jos)     - 17.224.935.1 Added option  to copy comments from #CS to #CE. Default is to copy the comments.                    Added Tidy Parameters:  /Skip_CE_Comment or /scec will skip this copy action                    Added INI option:                      * * *  Add comment to #CE/#CommentEnd and make it the same as the #CS/CommentStart Comments.                      ce_comment=1     - 17.224.935.2 Fix issue with Copy comments on comment start - end     - 17.224.935.4 Fix another issue with Copy comments on comment start - end -------------------------------------------------------------------------------------------------- ==> ScitillaHistory page containing all SciTE-Scintilla updates.
      ==> Visit the SciTE4AutoIt3 Download page for the latest versions
      ==> Check the online documentation for an overview of all extra's you get with this installer.
    • sumanth1980
      By sumanth1980
      Here i am wrote a simple lines to install basic applications but when i clicked on one application/program to install it was working fine but when i cancel the program in the middle to install another program it was not working. I am not an expert in this but i want a solution for this ... Can any one help me on this....
      ORG-1.au3
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I was trying to insert function header to the functions of my script, but, in the SciTE console, this appears:
      Function or struct definition not found, unable to insert header. @Jos Any suggestion?
      Thanks in advance.

      Best Regards.
    • cheeroke
      By cheeroke
      Hi I am not sure how to call it properly, but for those of you who use SciTE, when you typing built in function and about to pass parameters to it you can see popup with all the ones which can be passed.
      Question: how to create something like that for my own functions?
       
      Thanks
    • therks
      By therks
      Does SciTE have string or number ids for the recent file menu items?
      I was hoping to add shortcuts (using the user.shortcuts properties) to the most recent item, but the documentation doesn't list any id's for those items (unless I overlooked?).
      Also, did anyone else notice that the index listing for the SciTE doc doesn't work properly?
      It appears it's linking to this: mk:@MSITStore:C:\Program%20Files\AutoIt3\SciTE\Scite4AutoIt3.chm::/SciTEDocumentation.html
      When it should be this? mk:@MSITStore:C:\Program%20Files\AutoIt3\SciTE\Scite4AutoIt3.chm::/Scitedoc/SciTEDoc.html
×