Jump to content

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


Guest
 Share

Recommended Posts

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 Guest
Link to comment
Share on other sites

  • 1 year later...

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 Guest
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

×
×
  • Create New...