cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              body {
    margin: 0;
    height: 100vh;
}
.token.operator, .token.entity, .token.url, .language-css .token.string, .style .token.string {
    background: transparent;
}
            
          
!
            
              var term = $('body').terminal({
    less: function(url) {
        var ext = url.match(/.([^.]+)$/)[1];
        var languages = {
            js: 'javascript',
            css: 'css',
            py: 'python'
        };
        var language = languages[ext];
        if (language) {
            $.get(url).then(function(file) {
                var grammar = Prism.languages[language];
                var tokens = Prism.tokenize(file, grammar);
                var code = Prism.Token.stringify(tokens, language);
                less(term, code);
            });
        }
    }
}, {
    onInit: function() {
        this.echo('type [[b;#fff;]less <URL with CORS enabled>] ')
            .echo('try less https://codepen.io/jcubic/pen/zEyxjJ.js to see the source code of this demo')
    },
    name: 'less'
});

// prism overwrite to produce terminal formatting instead of html
(function(Token) {
    var _ = Prism;
    _.Token = function(type, content, alias, matchedStr, greedy) {
        Token.apply(this, [].slice.call(arguments));
    };
    _.Token.stringify = function(o, language, parent) {
        if (typeof o == 'string') {
            return o;
        }

        if (_.util.type(o) === 'Array') {
            return o.map(function(element) {
                return _.Token.stringify(element, language, o);
            }).join('');
        }

        var env = {
            type: o.type,
            content: Token.stringify(o.content, language, parent),
            tag: 'span',
            classes: ['token', o.type],
            attributes: {},
            language: language,
            parent: parent
        };

        if (env.type == 'comment') {
            env.attributes['spellcheck'] = 'true';
        }

        if (o.alias) {
            var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
            Array.prototype.push.apply(env.classes, aliases);
        }

        _.hooks.run('wrap', env);

        var attributes = Object.keys(env.attributes).map(function(name) {
            return name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
        }).join(' ');
        return env.content.split(/\n/).map(function(content) {
            return '[[b;;;' + env.classes.join(' ') + ']' + $.terminal.escape_brackets(content) + ']';
        }).join('\n');

    };
})(Prism.Token);

// less taken from leash http://github.com/jcubic/leash
function less(term, text, exit) {
    var export_data = term.export_view();
    var cols, rows;
    var pos = 0;
    //string = $.terminal.escape_brackets(string);
    var original_lines;
    var lines;
    var prompt;
    var left = 0;
    function print() {
        term.clear();
        if (lines.length-pos > rows-1) {
            prompt = ':';
        } else {
            prompt = '[[;;;inverted](END)]';
        }
        term.set_prompt(prompt);
        var to_print = lines.slice(pos, pos+rows-1);
        var format_start_re = /^(\[\[[!gbiuso]*;[^;]*;[^\]]*\])/i;
        to_print = to_print.map(function(line, line_index) {
            return $.terminal.substring(line, left, left+cols-1);
        });
        if (to_print.length < rows-1) {
            while (rows-1 > to_print.length) {
                to_print.push('~');
            }
        }
        term.echo(to_print.join('\n'));
    }
    function quit() {
        term.pop().import_view(export_data);
        //term.off('mousewheel', wheel);
        if ($.isFunction(exit)) {
            exit();
        }
    }
    function refresh_view() {
        cols = term.cols();
        rows = term.rows();
        if ($.isFunction(text)) {
            text(cols, function(new_lines) {
                original_lines = new_lines;
                lines = original_lines.slice();
                print();
            });
        } else {
            original_lines = text.split('\n');
            lines = original_lines.slice();
            print();
        }
    }
    refresh_view();
    var scroll_by = 3;
    //term.on('mousewheel', wheel);
    var in_search = false, last_found, search_string;
    function search(start, reset) {
        var escape = $.terminal.escape_brackets(search_string),
            flag = search_string.toLowerCase() == search_string ? 'i' : '',
            start_re = new RegExp('^(' + escape + ')', flag),
            regex = new RegExp(escape, flag),
            index = -1,
            prev_format = '',
            formatting = false,
            in_text = false;
        lines = original_lines.slice();
        if (reset) {
            index = pos = 0;
        }
        for (var i=0; i<lines.length; ++i) {
            var line = lines[i];
            for (var j=0, jlen=line.length; j<jlen; ++j) {
                if (line[j] === '[' && line[j+1] === '[') {
                    formatting = true;
                    in_text = false;
                    start = j;
                } else if (formatting && line[j] === ']') {
                    if (in_text) {
                        formatting = false;
                        in_text = false;
                    } else {
                        in_text = true;
                        prev_format = line.substring(start, j+1);
                    }
                } else if (formatting && in_text || !formatting) {
                    if (line.substring(j).match(start_re)) {
                        var rep;
                        if (formatting && in_text) {
                            rep = '][[;;;inverted]$1]' +
                                prev_format;
                        } else {
                            rep = '[[;;;inverted]$1]';
                        }
                        line = line.substring(0, j) +
                            line.substring(j).replace(start_re, rep);
                        j += rep.length-2;
                        if (i > pos && index === -1) {
                            index = pos = i;
                        }
                    }
                }
            }
            lines[i] = line;
        }
        print();
        term.set_command('');
        term.set_prompt(prompt);
        return index;
    }
    term.push($.noop, {
        resize: refresh_view,
        mousewheel: function(event, delta) {
            if (delta > 0) {
                pos -= scroll_by;
                if (pos < 0) {
                    pos = 0;
                }
            } else {
                pos += scroll_by;
                if (pos-1 > lines.length-rows) {
                    pos = lines.length-rows+1;
                }
            }
            print();
            return false;
        },
        name: 'less',
        keydown: function(e) {
            var command = term.get_command();
            if (term.get_prompt() !== '/') {
                if (e.which == 191) {
                    term.set_prompt('/');
                } else if (in_search &&
                           $.inArray(e.which, [78, 80]) != -1) {
                    if (e.which == 78) { // search_string
                        if (last_found != -1) {
                            last_found = search(last_found+1);
                        }
                    } else if (e.which == 80) { // P
                        last_found = search(0, true);
                    }
                } else if (e.which == 81) { //Q
                    quit();
                } else if (e.which == 39) { // right
                    left+=Math.round(cols/2);
                    print();
                } else if (e.which == 37) { // left
                    left-=Math.round(cols/2);
                    if (left < 0) {
                        left = 0;
                    }
                    print();
                } else {
                    // scroll
                    if (lines.length > rows) {
                        if (e.which === 38) { //up
                            if (pos > 0) {
                                --pos;
                                print();
                            }
                        } else if (e.which === 40) { //down
                            if (pos <= lines.length-rows) {
                                ++pos;
                                print();
                            }
                        } else if (e.which === 34) {
                            // Page up
                            pos += rows;
                            if (pos > lines.length-rows+1) {
                                pos = lines.length-rows+1;
                            }
                            print();
                        } else if (e.which === 33) {
                            //Page Down
                            pos -= rows;
                            if (pos < 0) {
                                pos = 0;
                            }
                            print();
                        }
                    }
                }
                if (!e.ctrlKey && !e.alKey) {
                    return false;
                }
            } else {
                // search
                if (e.which === 8 && command === '') {
                    // backspace
                    term.set_prompt(prompt);
                } else if (e.which == 13) { // enter
                    // basic search find only first
                    if (command.length > 0) {
                        in_search = true;
                        pos = 0;
                        search_string = command;
                        last_found = search(0);
                    }
                    return false;
                }
            }
        },
        prompt: prompt
    });
}
            
          
!
999px
Loading ..................

Console