Hi to all, Hi Jeb
I found this very interesting! I have not much know of Dos Batch, but i use it.
My current project is a front-end/wrapper for x264 in batch and in this project there a part that use a lot of variables.
I need to look value of variable and navigate on screen is the best i wish. I need to navigate via TAB. Each variable has a list of value and i need to choose and the SPACE is a good key.
For each set of variable i need a set of value. But i need to have multiple sets to figure out on the screen.
I think that this is possible whit this moving up or other
This script is a start , a demo . I used trick , fake to get result.
But i have a few of questions
Code: Select all
@if (@X)==(@Y) @end /* Harmless hybrid line that begins a JScript comment
@echo off
if "%~1"=="intern" (
call %2
exit
)
setlocal & setlocal EnableDelayedExpansion
rem coordinate start from 0, need to adjust!!
call :init-virtual-monitor
:thread1
set /a X1=40, Y1=20
for /l %%i in (1,1,250) do (
set /a "x1=X1-3+!random! %% 6","Y1 = Y1 -1 + (!random! %% 2)"
if !x1! lss 0 set /a x1=69
if !y1! lss 0 set /a y1=39
call :virtual-echo !x1! !y1! "\____"
)
call :virtual-echo 30 5 "===================="
call :virtual-echo 30 6 "| |"
call :virtual-echo 30 7 "===================="
call :gotoxy 32 6
call :begin-insert-getkey-mode
call :wait
call :wait
set /p "x=Enter x: "
rem call :getkey & rem echo %key% !key!
For /L %%i in (1,1,35) do echo(
echo X=!x!
rem call :Send 13
rem echo end1
exit /b
:thread2
set /p var=
rem Thread2 ends now
exit /b
############### High level
:echost
set /a y=%random% %% 20 + 1
call :ruotadx %y%
call :virtual-echo 1 %y% %%st[%y%]%%
exit /b
:ruotadx y
for /F "delims=" %%P in ("st[%1]") DO set "st[%1]=...!%%P!"
for /F "delims=" %%P in ("st[%1]:~0,30") DO set "st[%1]=!%%P!"
exit /b
###############
############### Low level
:virtual-echo xcord ycord text [/n]
rem per faster output we can make a queue and order it and print it in time (50-100ms)
call :gotoXY %1 %2
call :echo-no-nl %3
rem update screen buffer
set "string=%~3"
call:strLen string len
set /a len=len+%1
for /F "delims=" %%P in ("sb%2:~!len!") do set "resto=!%%P!"
for /F "delims=" %%P in ("sb%2:~0,%1") do set "sb%2=!%%P!%~3!resto!"
exit /b
:begin-insert-getkey-mode
rem there is a way to end thread2 using a pipe? or a quicly method?
set /a tmpY=!virtual_y!-1
call :gotoxy !virtual_x! !tmpY!
call :Send 13
set /a tmpY=!virtual_y!+1
for /F "delims=" %%P in ("sb!tmpY!:~0,!virtual_x!") do set "stringa=!%%P!"
call ::echo-no-nl "!stringa!"
exit /b
:gotoXY x y
rem check the current virtual position and choose for absolute or relative positioning. For now use absolute
call :Send 27
rem start from 1 = %2 - 1
for /l %%i in (1,1,%2) do (echo()
rem controllare coordinata
for /F "delims=" %%P in ("sb%2:~0,%1") do set "stringa=!%%P!"
rem call :echo-no-nl "!stringa!"
%echo-no-nl-macro_%!stringa!
set /a virtual_X=%1,virtual_Y=%2
exit /b
:echo-no-nl string
rem bug seven space
rem http://stackoverflow.com/questions/13488592/in-dos-how-to-set-p-with-a-string-starting-with-spaces
rem per i file : http://stackoverflow.com/questions/9864620/in-batch-how-do-i-create-spaces-at-the-beginning-of-a-input-prompt-string
<nul set /p "var=.%BS%%~1"
exit /b
:GetKey
call :begin-insert-getkey-mode
set "key="
for /F "usebackq delims=" %%L in (`xcopy /L /w "%~f0" "%~f0" 2^>NUL`) do (
if not defined key set "key=%%L"
)
set "key=%key:~-1%"
exit /b
:Send
cscript //E:JScript //nologo "%~f0" %1
exit /b
:wait
ping localhost -n 2 > nul
exit /b 0
:init-virtual-monitor
mode con: cols=80 lines=50
:: Define BS to contain a backspace
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "BS=%%A"
set echo-no-nl-macro_=^<nul set /p var=.%BS%
call :virtual-cls
start /b "" "%~f0" intern :thread2
call :wait
call :Send 27
for /L %%# in (0 1 39) do echo !sb%%#!
call :Send 27
set /a virtual_insert_mode=0
exit /b
:virtual-cls
cls
rem FARE: get linee colonne "mode con" ora fisse a 40
rem 012345678|012345678|012345678|012345678|012345678|012345678|012345678|012345678|
for /L %%# in (0 1 0) do set "sb%%#= + + + + + + + |"
for /L %%# in (1 1 39) do set "sb%%#= |"
set /a virtual_X=0,virtual_Y=0
exit /b
:strLen -- returns the length of a string via binary search, maximum length 1023
:: -- %~1: in - varible name of a string variable
:: -- %~2: out- string length
SETLOCAL
set str=A!%~1!& rem keep the A up front to ensures we get the length and not the upper bond
rem it also avoids trouble in case of empty string
set len=0
set /a n=1024
set /a n^>^>=1, len+=n
if !str:~%len%!. == . set /a len-=n
set /a n^>^>=1, len+=n
if !str:~%len%!. == . set /a len-=n
set /a n^>^>=1, len+=n
if !str:~%len%!. == . set /a len-=n
set /a n^>^>=1, len+=n
if !str:~%len%!. == . set /a len-=n
set /a n^>^>=1, len+=n
if !str:~%len%!. == . set /a len-=n
set /a n^>^>=1, len+=n
if !str:~%len%!. == . set /a len-=n
set /a n^>^>=1, len+=n
if !str:~%len%!. == . set /a len-=n
set /a n^>^>=1, len+=n
if !str:~%len%!. == . set /a len-=n
set /a n^>^>=1, len+=n
if !str:~%len%!. == . set /a len-=n
set /a n^>^>=1, len+=n
if !str:~%len%!. == . set /a len-=n
( ENDLOCAL & REM RETURN VALUES
IF "%~2" NEQ "" SET %~2=%len%
)
GOTO:EOF
//
***jscript part****/
var WshShell = WScript.CreateObject("WScript.Shell");
var args=WScript.Arguments;
WshShell.SendKeys(String.fromCharCode(args.Item(0)));
Output
Code: Select all
+ \____________\____ + + + \_______ |
\________ \____ |
\_\\____ \_\_____ |
\___\_____ \____ |
\_\_____ \____ |
\_\_==================== \____ |
\_| Enter x: 123 | \\\____ |
\==================== \____ |
\_______ \____ |
\_\________ \____ |
\____\\____ \____ |
\_________ \_____ |
\____\\_____ \____ |
\____ \____ \____ |
\____ \\_____ \____ |
\______________ \____ |
\____ \_____\____ \_______ |
\\____ \____\_\____ |
\____ \____ \_____________ |
\\____ \_______ \____ |
\____ \____ \____ \____ |
\_________ \__\_\____ |
\____ \___\____ |
\_\____ \__\\______ |
\____ \__\_______ |
\\______ \____\_____ |
\____ \____ \____ |
\____ \_\_____ \____ |
\____ \____ \\____ |
\_______ \____ \__________ |
\______ \____ \____ |
\\\____ \\____ \\____ |
\______ \____ \____ |
\____ \____ \____ |
\____ \____________ \\\____ |
\__________ \____ \____ |
\_______ \____ \\\____ |
\____ \____ \____ |
\_______________ \_\____ \____ |
\____ \_\____ \____ |
X=123
E:\x264\provini>
I have used a virtual screen buffer for now because i need to restart the thread2 and cls the screen. But there is another method?
I think to use e INSERT mode like "vi". In insert mode the thread2 is off.
There is a method for close thread2 via pipe? or escape for set/p temporarily?
There is a method for go ahead the cursor in the screen without clear the text below?
EDIT:
I have modify your script and have subst the set /p of thread2 with a echo(>nul and seem that work in same way!
Why?
Code: Select all
@if (@X)==(@Y) @end /* Harmless hybrid line that begins a JScript comment
@echo off
if "%~1"=="intern" (
call %2
exit
)
start /b "" "%~f0" intern :thread1
start /b "" "%~f0" intern :thread2
goto :eof
:thread1
cls
echo Line1
call :wait
call :wait
call :Send 27
echo Line2
echo Line3
echo Line4
echo Line5
echo Line6
call :wait
call :Send 27
for /L %%n in ( 1 1 10) DO (
<nul set /p "=."
call :wait
)
call :Send 13
exit /b
:thread2
call :wait
rem set /p var=
echo(>nul
echo Thread2 ends now
exit /b
:Send
cscript //E:JScript //nologo "%~f0" %1
exit /b
:wait
ping localhost -n 2 > nul
exit /b 0
//
***jscript part****/
var WshShell = WScript.CreateObject("WScript.Shell");
var args=WScript.Arguments;
WshShell.SendKeys(String.fromCharCode(args.Item(0)));
EDIT2: Mistake! Ok there is a main thread !