User Commands

Jan 23, 2011 at 11:03 PM

In MS4 i need code for users to type in commands.

And also i need a way for the console to go back to its original state after the user types in nonsense or a command that dosent exist.

Coordinator
Jan 24, 2011 at 9:28 AM

If you can't make a console application that does this, then you should not be asking for help to do it in COSMOS as it is pretty much exactly the same code. Make your "OS" in a C# console. Then, when it works there, come back and try it WITH THE LATEST RELEASE and then maybe someone will be more likely to help with your problem.

Jan 24, 2011 at 9:34 PM

Ok right now i got the user command thing down now all i need is a way i can be able to have the user be able to continue to type commands instead of haveing the cursor just blink.

 

If you dont get what i'm saying ,when i type a command the cursor is at a line of text i have witch is User> , now when i type a command ,For example "help",If the user types in help it would show a list of commands but after that i will not be able to see User> and I will not be able to type any more.

 

Please can some one give me some code on how to fix this.

 

Ps: The code i'm useing is shown below.

 

Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Sample OS [Version 1.0.0]");
            Console.WriteLine("Copyright <c> 2011. All Rights Reserved. ");
            Console.WriteLine(" ");
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Please type a command Below");
            Console.WriteLine(" ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("User > ");
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            string command = Console.ReadLine();
            Console.CursorTop = 6;
            Console.CursorLeft = 6;           

            if (command == "show list of commands")
               Console.WriteLine("restart-Restarts the computer.");
            Console.ReadLine();                 
            if (command == "help")
                Console.WriteLine("Pleas type in , show list of commands ");
            if (command == "cls")
            Console.Clear();
            if (command == "restart")
                Cosmos.Kernel.CPU.Reboot();
            else
                Console.WriteLine("Command not found");

Jan 25, 2011 at 2:10 AM

while (true)

{

Console.Write(">");

string a = Console.ReadLine();

if (a="help")

{

//Do whatever.

}

}

Feb 5, 2011 at 12:31 PM
Edited Feb 6, 2011 at 6:31 PM

In program.cs I have just made a function that loads another class file when my own "bootloader" has finished loading.
Like this:

Program.cs > "bootloader"
When "bootloader" is done, load command.cs

And in command.cs I have all the commands and also the input function.
The input function have I made this way:

public static void start()

{
 Console.ForegroundColor = ConsoleColor.Green;
Console.Write("OS>");
 Console.ForegroundColor = ConsoleColor.White;
Console.Write("");
string input = Console.ReadLine();
 if (input == "about")
{
   command.about(); //show about information
  command.start(); //return to input function
}
}

 

Then in command.cs I have made a public static void called "about" so it loads when the user types "about"
"command.start();" that is below "command.about();" is used for returning to the input function after vewing the about information.

Use the code below if you want something to happen when the user insters a command that not exists use this code after the input finction.

else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
 Console.WriteLine("That is not a command.");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Yellow;
command.start();
}

Here is the full code:

 

 

public static void start()

{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("OS>");
Console.ForegroundColor = ConsoleColor.White;
Console.Write("");
string input = Console.ReadLine();
if (input == "about")
{
command.about();
command.start();
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("That is not a command.");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Yellow;
command.start();
}

 

Just change "command." to "program." if you are using this in the program.cs class file.

 

Feb 6, 2011 at 10:22 AM

You might want to change that to use a while loop instead of recursion...

Feb 25, 2011 at 4:00 PM

O.O this is probably single handedly the simplest question about cosmos i have EVER seen (other than what i ask LOL)

While (true)

{

Console.WriteLine("Welcome to a NaDOS Cosmos OS");

Console.WriteLine("(Not A Disk Operating System, due to filesystem support missing lol)");

Console.Write("C:/HoldMeCloserTonyDanza>"); //Replace the string with w/e you want

string command = Console.ReadLine();

if (command == "about")

{

Console.Write("This operating system likes pie");

}

else if (command == "put whatever other command you want here") //replace the string with w/e other command you want

{

//The cake is a lie? (replace this with w/e you want this command to do)

}

//to add another command add another "if" statement here but add an "else" before it or ELSE (no pun intended)

// (continued) it will mess up the nonsence  command.

else //for nonsence commands

{

//Had to think hard on what internet meme to put here LOL

//OK so it uses the "c-c-c-comb breaker meme and it makes fun at DOS's 'Bad command' statement. LOL

Console.WriteLine("Good Command C-C-C-C-Combo Breaker!!!");

}

)

//END OF CODE

 

i hope you enjoy that lol i had fun typing it xD