Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a more fully-featured print... #17

Open
sgbeal opened this issue Apr 2, 2010 · 6 comments
Open

a more fully-featured print... #17

sgbeal opened this issue Apr 2, 2010 · 6 comments
Labels

Comments

@sgbeal
Copy link

sgbeal commented Apr 2, 2010

Here's a variation of Terminal.print which accepts arrays of arguments, and each argument may be a jQuery element, a function (it is run to get its contents), or "anything else" (anything handled by jQuery.append()).

This could certainly be improved upon, but this seems to work okay...

print: function() {
        var prpush = arguments.callee.prpush;
        var pr = arguments.callee.pr;
        var self = this;
        if( ! prpush );
        {
            prpush = arguments.callee.prpush = function(jout,item) {
                if( item instanceof Function ) item = item();
                jout.append(item);
            }
            pr = arguments.callee.pr = function(obj) {
                jQuery(self.config.selectDisplay).append(obj);
                self.jumpToBottom();
            }

        }
        var out = jQuery('<p>');
        if(! arguments.length) {
            pr(out);
            return;
        }
        var av = Array.prototype.slice.call(arguments, 0);
        var i = 0;
        for( ; i<av.length; ++i ) {
            prpush( out, av[i] );
            if( i != (av.length-1) ) prpush(out, ' ');
        }
        pr(out);
},
@sgbeal
Copy link
Author

sgbeal commented Apr 2, 2010

Sorry, forgot to mention that the above code doesn't use '#display' directly, but uses self.config.selectDisplay (which is "#display" for xkcd). My local copy of cli.js uses
config options for the selectors:

config: {

...
selectScreen: '#screen',
selectDisplay: '#display',
selectPrompt: '#prompt',
selectCursor: '#cursor',
selectInLine: '#inputline',
selectBottomLine: '#bottomline',
selectSpinner: '#spinner',
selectLCommand: '#lcommand',
selectRCommand: '#rcommand'
},

though they should arguably be structured like:

config:{ ... select:{screen:'#screen',...} }

@chromakode
Copy link
Owner

Nice! One question though... why are you storing the helper functions in arguments.callee instead of using closures?

I also like the move to parameterized element selectors, though I think we could make the names shorter by making them named like "config.el.screen"...

Could you please start pushing your local changes to a repository? That would make it a lot easier to merge them in.

@sgbeal
Copy link
Author

sgbeal commented Apr 2, 2010

i stuff then in callee because it saves memory, rather than re-creating the functions for each instance. i've refactored my local copy to use config.select.screen (etc), by the way.

i'll be happy to push, but i am a complete git newbie (i'm used to cvs/svn/fossil). i'm afraid that some of my current changes might break your code, so i will send it to you for approval/test before i commit. (Or how can i start a branch?)

@chromakode
Copy link
Owner

In git, each user can have their own independent repository, so you can push and maintain your own version of the tree. I can then pick and choose pieces to merge in to mine.

It's really easy to set one up -- just head over to http://github.com/repositories/new and follow the instructions.

@sgbeal
Copy link
Author

sgbeal commented Apr 2, 2010

okay, i've set up http://github.com/sgbeal/xkcdfools. i'll get my changes into there and let you know.

@chromakode
Copy link
Owner

Great! I'll be watching for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants