Need HELP with Dos Prompt or Text..

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Need HELP with Dos Prompt or Text..

#1 Post by Dos_Probie » 05 Jan 2013 21:32

I remember a post in the last year on here where someone changed the dos line colors, but cant seem
to find it .. Anyway I have this user input line in my batch file and would like to change the input line
[ENTER] to a different color or use a underline cursor using only native dos commands.
Does anyone know how to do this?? Thanks! 8)

Code: Select all

set /p url=Paste Your RTMP Url Here..Then Press [ENTER]:

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Need HELP with Dos Prompt or Text..

#2 Post by abc0502 » 05 Jan 2013 21:43

I think you will need to use the color function, to color this text.
Carlos and dbenham wrote two color functions, they are the newest function till now here
But I have no Idea How You'r Going to Use it in The Set /P Command :?: :!:

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Need HELP with Dos Prompt or Text..

#3 Post by abc0502 » 05 Jan 2013 22:09

Ok, I might found one, but it won't be like what you want 100%.

By using dbenham code in the same page here use this code with it, it will use the :colorPrint function in it:

Code: Select all

<NUL SET /P "=Paste Your RTMP Url Here..Then Press [" &CALL :colorPrint 0c "Enter" &ECHO ]
Set /p "url=>"
pause
exit /b
But the user will enter the url in the next line not in the same line.

<NUL SET /P "=text_here" Enables you two write multi-lines in the same line.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Need HELP with Dos Prompt or Text..

#4 Post by Ed Dyreen » 07 Jan 2013 19:16

abc0502 wrote:But the user will enter the url in the next line not in the same line.
If the lineFeed from the set command is undesired; any getKey/getLine program solves that.

Code: Select all

for /f delims^= eol^=^ %? in ( 'getLine.EXE' ) do echo.%?_
A VBS example of getLine compiled to executable;

Code: Select all

' Read a single line from StdIn and print to Stdout.
' (
   Dim sReadLine
   Do Until WScript.StdIn.AtEndOfLine
      '
      sReadLine = sReadLine &WScript.StdIn.Read(1)
      '
   Loop
   WScript.Stdout.Write( sReadLine )
' )
getKey and getLine programs exist, you could also write them yourself, not in batch though :?

Aacini
Expert
Posts: 1926
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Need HELP with Dos Prompt or Text..

#5 Post by Aacini » 08 Jan 2013 03:10

You may use my auxiliary .EXE commands to achieve what you want in two ways:

The easiest way is via TextColor.exe command that allows to set the color used by posterior DOS commands. For example:

Code: Select all

set /P "=Paste Your RTMP Url Here..Then Press [ENTER]: " <NUL
rem Set text color as black over white (reverse video):
TextColor 70
rem Read the input line in reverse video:
set /p "url="
rem Reset text color to original:
TextColor 07
pause
However, the input line will appear in color until the text is entered, so I think this is not what you want. Besides, TextColor.exe program will NOT work in certain old computers (like the mine :cry: ).

What we really want is that the field where the input line is read appear in reverse video before the text be typed. However, in order for this to work we must define the number of characters that will appear in reverse video ("field wide") and, of course, the input routine must limit the maximum input line lenght to that wide.

I previously wrote a ReadLine.bat example program that simulate SET /P command this way: it read characters until Enter key is pressed and delete the last character read with BackSpace key. I modified such routine into ReadField.bat program that achieve the previous process and also allows to optionally give an initial value that will appear in the field before the user start typing. Here it is:

Code: Select all

@echo off

rem Read a value in a visually delimited field
rem Antonio Perez Ayala

set Bell=7
set BackSpace=8
set Enter=13
set Space=32

:ReadField var="prompt" /bf wide ["initial value"]
rem        %1   %2      %3  %4     %5

setlocal EnableDelayedExpansion
Show %2
CursorPos
set initPos=%errorlevel%
ColorShow %3 %Space%*%4
CursorPos %initPos%
set len=0
if "%~5" equ "" (
   set %1=
) else (
   ColorShow %3 %5
   set "%1=%~5"
   for /L %%i in (0,1,80) do if "!%1:~%%i,1!" neq "" set /A len+=1
)

:nextKey
   GetKey
   set key=%errorlevel%
   if %key% geq %Space% (
      rem Ascii character: insert it
      if %len% lss %4 (
         ColorShow %3 %key%
         for /F "delims=" %%a in ('Show %key%') do set "%1=!%1!%%a"
         set /A len+=1
      ) else (
         rem Wide exceeded
         Show %Bell%
      )
   ) else if %key% equ %BackSpace% (
      rem Backspace: delete last character
      if defined %1 (
         ColorShow %3 %BackSpace% %Space% %BackSpace%
         set "%1=!%1:~0,-1!"
         set /A len-=1
      ) else (
         rem Empty value
         Show %Bell%
      )
   )
if %key% neq %Enter% goto nextKey
echo/
for /F "delims=" %%a in ("!%1!") do endlocal & set %1=%%a
exit /B
For example, if your RTMP Url value can have 40 characters maximum:

Code: Select all

call :ReadField url="Paste Your RTMP Url Here..Then Press [ENTER]: " /70 40
Previous Batch subroutine use these auxiliary programs: 2-Show.exe, 3-GetKey.exe, 6-CursorPos.exe and 12-ColorShow.exe; you may copy all they from this post.

NOTE: My previous version of ColorShow.exe program have a bug so it not correctly show control characters (like BS, CR and LF). I fixed it and modified the former ColorShow.exe.hex file 5 minutes before I posted this reply. If you want to use ReadField.bat routine, please download ColorShow.exe.hex file again and re-create ColorShow.exe.

Antonio

Post Reply