Is there a way I can change the color of what the user types when they are typing it
Set /p = what user types would be a different color than the rest of the fle
Thanks
Batch change color of user input
Moderator: DosItHelp
Re: Batch change color of user input
According to the page...
Sorry, but I do not understand that part.
Maybe this could help...
http://stackoverflow.com/questions/1514 ... ut-by-user
However, I think the task is not really good to do...
Meerkat
because right now the answer is simply "yes."
Sorry, but I do not understand that part.
Maybe this could help...
http://stackoverflow.com/questions/1514 ... ut-by-user
However, I think the task is not really good to do...
Meerkat
Re: Batch change color of user input
I think he/she wants to change the color of the content written by the user at the moment its written.
Re: Batch change color of user input
At the end of the post is my attempt to achieve what I think you want.
The input of the user is colored , though the colors will be lost if the script is redirected , piped or processed with FOR /F.
But I suppose you'll want to preserve the output. The only option that I found working was (optional) writing to a file (later you can read it) . Here's the script:
The input of the user is colored , though the colors will be lost if the script is redirected , piped or processed with FOR /F.
But I suppose you'll want to preserve the output. The only option that I found working was (optional) writing to a file (later you can read it) . Here's the script:
Code: Select all
@if (@X)==(@Y) @end /* JScript comment
@echo off
setlocal
for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do (
set "jsc=%%v"
)
if not exist "%~n0.exe" (
"%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0"
)
%~n0.exe %*
endlocal & exit /b %errorlevel%
*/
import System;
import System.IO;
var arguments:String[] = Environment.GetCommandLineArgs();
var foregroundColor = Console.ForegroundColor;
var backgroundColor = Console.BackgroundColor;
var currentBackground=Console.BackgroundColor;
var currentForeground=Console.ForegroundColor;
var promptString:String="";
var outFile="";
function printHelp( ) {
print( arguments[0] + " [-f foreground] [-b background] [-p prompt string] [-o out file]" );
print( " foreground Foreground color - a " );
print( " number between 0 and 15." );
print( " background Background color - a " );
print( " number between 0 and 15." );
print( "Colors :" );
for ( var c = 0 ; c < 16 ; c++ ) {
Console.BackgroundColor = c;
Console.Write( " " );
Console.BackgroundColor=currentBackground;
Console.Write( "-"+c );
Console.WriteLine( "" );
}
Console.BackgroundColor=currentBackground;
}
function errorChecker( e:Error ) {
if ( e.message == "Input string was not in a correct format." ) {
print( "the color parameters should be numbers between 0 and 15" );
Environment.Exit( 1 );
} else if (e.message == "Index was outside the bounds of the array.") {
print( "invalid arguments" );
Environment.Exit( 2 );
} else {
print ( "Error Message: " + e.message );
print ( "Error Code: " + ( e.number & 0xFFFF ) );
print ( "Error Name: " + e.name );
Environment.Exit( 666 );
}
}
function numberChecker( i:Int32 ){
if( i > 15 || i < 0 ) {
print("the color parameters should be numbers between 0 and 15");
Environment.Exit(1);
}
}
function parseArgs(){
if ( arguments.length == 1 || arguments[1].toLowerCase() == "-help" || arguments[1].toLowerCase() == "-help" ) {
printHelp();
Environment.Exit(0);
}
for (var i=1;i<arguments.length-1;i=i+2){
try{
switch(arguments[i].toLowerCase()){
case '-f':
foregroundColor=Int32.Parse(arguments[i+1]);
break;
case '-b':
backgroundColor=Int32.Parse(arguments[i+1]);
break;
case '-p':
promptString=arguments[i+1];
break;
case '-o':
outFile=arguments[i+1];
break;
default:
Console.WriteLine("Invalid Argument "+arguments[i]);
break;
}
}catch(e){
errorChecker(e);
}
}
}
parseArgs();
numberChecker(backgroundColor);
numberChecker(foregroundColor);
Console.BackgroundColor = backgroundColor ;
Console.ForegroundColor = foregroundColor ;
Console.Write(promptString);
var key;
var input="";
do {
key = Console.ReadKey(true);
if ( (key.KeyChar.ToString().charCodeAt(0)) >= 20 && (key.KeyChar.ToString().charCodeAt(0) <= 126) ) {
input=input+(key.KeyChar.ToString());
Console.Error.Write(key.KeyChar.ToString());
}
} while (key.Key != ConsoleKey.Enter);
Console.Error.WriteLine();
Console.BackgroundColor = currentBackground;
Console.ForegroundColor = currentForeground;
try {
if (outFile != ""){
File.WriteAllText(outFile , input);
}
}catch(e){
errorChecker(e);
}
Re: Batch change color of user input
Dear foxdrive than you this was just what I was looking for but is there a way to change the colors used in the code? Thanks
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Batch change color of user input
Meerkat wrote:According to the page...because right now the answer is simply "yes."
Sorry, but I do not understand that part.
The way it was written, the question was effectively, "can ___ be done in batch?"
The answer is yes, it can be done in batch.