1

I was wondering how I would display the contents of a textfile in the terminal output because I have no idea how to go about it. I want it to work like "more [filename]" The files would be in the same directory as the html script.

Here is my current code*: http://pastebin.com/iN4AXUs9

*I used pastebin as the formatting was messing up when I pasted it here.

Thanks

AIAU Dev
  • 13
  • 4
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Jun 02 '15 at 07:33

1 Answers1

0

Try:

var c = $.terminal.splitCommand(cmd);
if (c.name == "more") {
    $.get(c.args[0], function(file) {
        term.echo(file);
    });
}

It will display whole file all at one, if you want something similar to more command you will need to split the file into pages. Maybe something like this:

     var export_data = term.export_view();
     $.get(c.args[0], function(file) {
        var i = 0;
        var lines = file.split('\n');
        term.clear().echo(lines.slice(i, i+term.rows()).join('\n'));
        term.push($.noop, {
            keydown: function(e) {
                if (e.which == 32) {
                    i++;
                    term.clear().echo(lines.slice(i, i+term.rows()).join('\n'));
                } else if (e.which == 27) {
                    term.pop().import_view(export_data);
                }
                return false;
            }
        });

     });

If you want to have more then 2 lines displayed then you need to resize the terminal:

   var terminal = $('...').terminal(...);
   var $win = $(window);
   $win.resize(function() {
       var height = $win.height();
       terminal.innerHeight(height);
   }).resize();
   terminal.resize();
jcubic
  • 61,973
  • 54
  • 229
  • 402
  • Both worked. Just a quick question with the second one (mulitlines), is it possible to change the amount of lines that are shown. Currently it only shows 2 lines of the document. – AIAU Dev Jun 02 '15 at 01:53
  • And one other thing! Is there a way to interrupt the displaying of a text file with a certain keystroke or when the text file is finished because currently there is no way to go back to the normal terminal without refreshing the page – AIAU Dev Jun 02 '15 at 02:00
  • @AIAUDev updated the answer with a fix. I forget that pause disable keystrokes you need to remove pause and resume and you will have exit using Escape key. – jcubic Jun 02 '15 at 07:06