How to go about creating a "command line" webpage?

shant93

Member
Messages
119
Reaction score
0
Points
16
I want to create a simple page consisting of essentially a text box. It would use PHP, or javascript, or another language, to compute the input and do something. For example, google apples would, well, google apples. Tweet Hello, would, tweet hello, cheezburger would open a predefined set of cheezburger network sites, url apple.com would open the apple website, and so on, and so forth.

For now I want to keep it personnal, offline. My main question is wether I should be using JavaScript (or other client-side), or PHP (or other serverside). I can think of one way to do this in PHP, which would be to run the string through a list of commands and check for a matching one, but I would like to add real-time some features like auto-complete or syntax help. Is there a way for javascript to cycle through files? Is there another client-side script that could do that? Can I do most of these on a PC, without uploading it, only running something like wampserver to run PHP, or not even that if it is JS?

Thanks in advance!

P.S. How do you get the cursor to go directly to the text box like the google home page?

Also, I plan on potentially releasing this later. What would be the most efficient scripting language for running it, considering each user would have their own specific settings for something like "search Apples" or wether they want to open in a new apge or not or anything of the sort?

--------------------
Edit:
What language would I use to run something like this in Windows' native command line environment? (Command Prompt)
 
Last edited:

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Use Ruby on Rails.

Try the interactive prompt at http://tryruby.org/

It's really neat.

It might take a bit to learn, but it's probably your best bet for something like this. JavaScript/PHP would be heavy on the server.

As to your question about the cursor: It's a attribute called autofocus in HTML5. <input type="text" autofocus="true" /> (for example)
 
Last edited:

shant93

Member
Messages
119
Reaction score
0
Points
16
That should be .org, by the way

I think I'll get to learning Ruby. I've heard of it but never really used it. Is i implementable in a local environment?
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
If by "local environment" you mean a VPS or home server: yes. It works on Windows, *nix, and OSX
 

vv.bbcc19

Community Advocate
Community Support
Messages
1,524
Reaction score
92
Points
48
Use Ruby on Rails.

Try the interactive prompt at http://tryruby.org/

It's really neat.

It might take a bit to learn, but it's probably your best bet for something like this. JavaScript/PHP would be heavy on the server.

As to your question about the cursor: It's a attribute called autofocus in HTML5. <input type="text" autofocus="true" /> (for example)

PHP is not heavy on the server.Infact its faster too.
Ruby on the Rails is the best ofcourse.
Javascript is a bit heavy but if you are with it for long..dont mind the weight on server.Just go about it.
 

shant93

Member
Messages
119
Reaction score
0
Points
16
Is ruby Serrver-Side code? If it is, I still want to know if JavaScript can go through a file, and if it can't, if there is a client-side code which can.
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
Javascript is a bit heavy but if you are with it for long..dont mind the weight on server.Just go about it.
Javascript is the lightest of them all if you're looking at them from a server standpoint, as it runs within the client rather than on the server.

Personally I would implement the main query decoding of this project in Javascript, as it is considerably more immediate than having to go back to the server every time for a response. However, for cases where using Javascript might not work as well, such as sending a tweet, I would then fall back to a PHP script that the JS then sends a tweet request to.

Edit:
Precisely what do you mean by 'JavaScript can go through a file'?
 
Last edited:

shant93

Member
Messages
119
Reaction score
0
Points
16
Precisely what do you mean by 'JavaScript can go through a file'?

I mean, when I hit enter, can JavaScript Isolate whatever comes before the first " " (space) character and search through a file for the corresponding command, supplying the arguments?
 

denzil

New Member
Messages
134
Reaction score
3
Points
0
You can't use JavaScript to access server-side files. You will need some server-side script for this. I don't think PHP will be too heavy for what you want to achieve.

edit:
I'm assuming that you want to add new commands in some sort of a database on the server, which will require server-side access I believe.
 
Last edited:

shant93

Member
Messages
119
Reaction score
0
Points
16
But I still wanted to integrate some syntax-help, so, real-time server requests (which I believe are banned), but I guess it's not extremely important, specially since I don't really have time to learn a new language for a few months and even JavaScript is practically new to me.
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
can JavaScript Isolate whatever comes before the first " " (space) character
Yes
Code:
var inputString = 'tweet hello      world';
var inputArray = inputString.split(/\s+/g); //Splits by any whitespace character
var firstItem =  inputArray[0];

search through a file for the corresponding command, supplying the arguments?
Javascript does not have direct access to any filesystem, so the command list would have to be loaded as part of the page.
Code:
var commandList = {}
commandList.tweet = function(arguments){
 //Code to send tweet
}

commandList.url = function(arguments){
 //Code to open url
}


//Search the list
var inputString = 'tweet hello      world';
var inputArray = inputString.split(/\s+/g); //Splits by any whitespace character
var firstItem =  inputArray[0];

if(typeof commandList[firstItem.toLowerCase()] == 'function'){
 var arguments = inputArray.shift();
 commandList[firstItem.toLowerCase()](arguments);
}
 
Last edited:

shant93

Member
Messages
119
Reaction score
0
Points
16
Thanks for the replies guys, really helps

Although, I may have started this a little too late because the term is about to begin, I'll try to work on this but i probably won't be able to do much.

I have a general idea of how it would work. Thanks everyone!
 

denzil

New Member
Messages
134
Reaction score
3
Points
0
I see. Do you plan on checking a database when implementing the syntax-help? If so you might need sever-side script. If you plan on hard-coding your syntax help system you could do it client-side.
 

shant93

Member
Messages
119
Reaction score
0
Points
16
Yeah, I just hadn't realised you could simply load the commands as "classes" in another JS file (or the same one, who knows) using simple PHP
 
Top