I'm making a text based game in JavaScript, and I'm looking for a command line widget, with the following features:
Does anyone know about any such preexisting widget, if not, can anyone give me tips for how to make one?
It's not as tricky as you'd think to make this. I made one recently for a project, using HTML elements and jQuery JS.
I used an input element for the input line - handling special keypresses like enter and tab. For previous commands and responses I used a scrollable area which I appended new elements to as new inputs or responses were available.
I displayed the commands and responses in DIVs, which allowed for copy and pasting (and HTML formatting). I even made the responses disclosable so I'd only show the command initially and you could click on the 'expand' button to show the rest of it.
It all worked really well in the end. Just a few simple HTML elements and some jQuery code which wasn't as complex as I thought it would be when starting it. By far the most complexity and most code was in tweaking the aesthetics!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With