gil900

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

3 posts in this topic

#1 ·  Posted (edited)

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
2 people like this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Edited by gil900

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

    • Skysnake
      By Skysnake
      Scite comes up occasional, almost incidentally, in some support topics.  I have not found a "Scite" topic in the forums, so this is where I will start.  I have recently been using Scite intensively, specifically with a large project and I have certain issues.  I know that Scite is not an AutoIt product, but it is so closely integrated to the core release that it makes sense to raise issues and request support here.  If this is not the right please refer me to the right forum.
      Thx
       
      Skysnake
    • TrashBoat
      By TrashBoat
      I've messed around in scite theme settings and it left this blue bar , how can i get rid of it?
      Image (imgur)
       

    • rudi
      By rudi
      Hello,
      very propably this has been asked before, well, I miss the thread(s) ...
      Is there a command line switch to tell the SciTE setup EXE to install silently ("/S") *AND* to end up with "edit" (instead of "run") as system wide default action for *.au3 files?
       

       
      As it can be done with the config tool:
      https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/SciTEConfigb1.PNG
       
      Regards, Rudi.
    • tremolux66
      By tremolux66
      I use a monospace font for editing AutoIt scripts in SciTE (currently, CourierNew 9pt). Regardless of what font size I set in the configuration, when I start SciTE to resume editing the script text is one size smaller than I specified. When I type Ctrl+<numpad-slash> the text changes to the desired size. The same is true of the output pane, and I have to reset the size for both areas every time I start SciTE.
      IIRC, I've made few other changes to the configuration (e.g., changed the search highlight color and disabled Tidy), so this behavior seems odd. About SciTE says it's version 3.6.0 (Aug. 4, 2015).
      Any idea how to fix this?
    • user4157124
      By user4157124
      As they're opinion-based to some degree; how are AutoIt's best practices decided and do suggestions get considered?
      Some suggestions :
      For...To...Step...Next -loop variable-naming like $iN ($i1, $i2, etc.) : conforms to recommended naming convention, identifies level (albeit inverted to ExitLoop and ContinueLoop's convention) and enables SciTE selection-highlighting (requires minimum of 3 characters). Minimize logic in global scope, separate data & settings from logic, use of vertical space, project organization (folder structure, resource- and include file management). Example (loop variable-naming, minimizing logic in global scope and separation of settings from logic) :
      #include <Array.au3> Global Enum $RANDOM_RETURNFLOAT, _ $RANDOM_RETURNINTEGER Global Enum $EXITCODE_NONE Global Const $g_sChar0 = '-' Global Const $g_sChar1 = '+' Global Const $g_iAmountX = 10 Global Const $g_iAmountY = $g_iAmountX Main() Func Main() Local $aArray[$g_iAmountY][$g_iAmountX] For $i1 = 0 To $g_iAmountY - 1 For $i2 = 0 To $g_iAmountX - 1 $aArray[$i1][$i2] = Random(0, 1, $RANDOM_RETURNINTEGER) ? $g_sChar1 : $g_sChar0 Next Next _ArrayDisplay($aArray) Exit $EXITCODE_NONE EndFunc Example (project organization) :
      + project_folder + bak [backup files] + bin [distributed binaries and dependencies] + inc [non-standard include files] + res [resource files (icons, file+install files, etc.)] + usr [configuration files, databases, etc.] - script.au3 - script.exe Example (use of vertical space) :
      Func _DigitalRoot($iNum) Local $sNum = '' Local $aNum While $iNum > 9 $sNum = String($iNum) $aNum = StringSplit($sNum, '') $iNum = 0 For $i1 = 1 To $aNum[0] $iNum += Int($aNum[$i1]) Next WEnd Return $iNum EndFunc