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.

            
              /**
 * jQuery Plugin for text based dialogs that look
 * like dialog linux command. It use cmd plugin from
 * jQuery Terminal
 *
 * Copyright (c) 2017 Jakub Jankiewicz <http://jcubic.pl/me>
 *
 * Linceses under MIT license
 */
body {
    margin: 0;
    height: 100vh;
    --size: 1.5;
}
.dialog {
    background-color: #00a;
    position: relatieve;
    font-size: 12px;
    line-height: 14px;
    margin: 0;
}
.dialog, .dialog button {
    font-family: monospace;
}
.dialog > :not(.box) {
    display: none;
}
.dialog .cmd {
    --color: #000;
    --background: #aaa;
    padding: 0;
}
.dialog .cmd > span:not(.prompt) {
    float: none;
}
@supports (--css: variables) {
    .dialog, .dialog button {
        font-size: calc(var(--size, 1) * 12px);
        line-height: calc(var(--size, 1) * 14px);
    }
}
.dialog > .box {
    background-color: #aaa;
    float: left;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    -webkit-box-shadow: calc(var(--char-width) * 2px) calc(var(--char-height) * 1px) black;
    box-shadow: calc(var(--char-width) * 2px) calc(var(--char-height) * 1px) black;
}
.dialog .box .light {
    color: #fff;
}
.dialog .box .dark {
    color: #000;
}
.dialog .line {
    float: left;
    clear: both;
    white-space: nowrap;
}
.dialog .box > .input .left,
.dialog .box > .input .top,
.dialog .box > .input .bottom,
.dialog .box > .input .cmd,
.dialog .box > .input .right {
    display: inline-block;
}
.dialog .box > .buttons-line .left,
.dialog .box > .buttons-line .buttons,
.dialog .box > .buttons-line .right {
    float: left;
}
.dialog .box > .input .cmd {
    float: none;
    margin-bottom: -4px;
}
.dialog .box .title {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    text-align: center;
    overflow: hidden;
}
.dialog .box .title span {
    background-color: #aaa;
}
.dialog .box .header span {
    display: inline-block;
}
.dialog .box .buttons {
    display: flex;
    justify-content: space-around;
}
.dialog .box button {
    margin: 0;
    padding: 0;
    border: none;
    color: #555;
    min-width: 87px;
}
.dialog .box button:active,
.dialog .box button {
    outline: none;
}

.dialog .box button:before {
    content: '<';
    float: left;
}
.dialog .box button:after {
    content: '>';
    float: right;
}
.dialog .box button:before,
.dialog .box button:after {
    display: inline-block;
    color: #000;
}
.dialog .box button,
.dialog .box button:before,
.dialog .box button:after {
    background-color: transparent;
}
.dialog .box button:not(.active) .mark {
    color: #a00;
}
.dialog .box button.active,
.dialog .box button.active:before,
.dialog .box button.active:after {
    background-color: #00a;
}
.dialog .box button.active {
    color: #ff5;
}
.dialog .box button.active:before,
.dialog .box button.active:after {
    color: #fff;
}
.dialog .box button.active.selected .mark {
    color: #00a;
    background: #fff;
}

            
          
!
            
              /**
 * jQuery Plugin for text based dialogs that look
 * like dialog linux command. It use cmd plugin from
 * jQuery Terminal
 *
 * Copyright (c) 2017 Jakub Jankiewicz <http://jcubic.pl/me>
 *
 * Linceses under MIT license
 */
/* global jQuery setTimeout  */
(function($) {
    $.dialog = {
        defaults: {
            cols: 50,
            rows: 8,
            title: '',
            message: '',
            cancel: $.noop
        },
        strings: {
            ok: '_OK',
            cancel: '_Cancel'
        }
    };
    function get_char_size() {
        var temp = $('<div class="dialog temp"><div class="box"><span>'+
                     '&nbsp;</span></div></div>').appendTo('body');
        var rect = temp.find('span')[0].getBoundingClientRect();
        var result = {
            width: rect.width,
            height: rect.height
        };
        temp.remove();
        return result;
    }
    function chunks(str, length) {
        if (str.length <= length) {
            return [str];
        }
        var num_chunks = Math.ceil(str.length / length);
        var result = [];
        for(var i = 0, o = 0; i < num_chunks; ++i, o += length) {
            result.push(str.substr(o, length));
        }
        return result;
    }
    function str_repeat(str, n) {
        return new Array(n).join(str);
    }
    $.fn.dialog = function(fn, options) {
        fn = fn || $.noop;
        var chars = {
            hor: '─',
            ver: '│',
            nw: '┌',
            cw: '├',
            sw: '└',
            ne: '┐',
            ce: '┤',
            se: '┘'
        };
        var settings = $.extend({}, $.dialog.defaults, options || {});
        var cols = settings.cols > 20 ? settings.cols : 20;
        var rows = settings.rows > 8 ? settings.rows : 8;
        function line(container, left, right, options) {
            var settings = $.extend({
                bottom: false,
                reverse: false,
                length: cols
            }, options || {});
            var first, second;
            if (settings.bottom) {
                first = left;
                second = str_repeat(chars.hor, settings.length - 2) + right;
            } else {
                first = left + str_repeat(chars.hor, settings.length - 2);
                second = right;
            }
            container.append('<span class="' +
                             (settings.reverse ? 'dark' : 'light') +
                             '">' + first + '</span>');
            container.append('<span class="' +
                             (settings.reverse ? 'light' : 'dark') +
                             '">' + second + '</span>');
        }
        function update_css_var() {
            self[0].style.setProperty('--char-width', char_size.width);
            self[0].style.setProperty('--char-height', char_size.height);
        }
        if (this.length > 1) {
            var args = [].slice.call(arguments);
            return this.each(function() {
                $.fn.dialog.apply(this, args);
            });
        }
        var char_size = get_char_size();
        var self = $(this).addClass('dialog');
        update_css_var();
        var box = $('<div class="box"/>');
        var top = $('<div class="top"/>').appendTo(box);
        line(top, chars.nw, chars.ne);

        var width;

        var title = $('<div class="title"><span>' + settings.title +
                      '</span></div>').appendTo(box);

        if (settings.message) {
            var header = $('<div class="header"/>').appendTo(box);
            var size = cols - 5;
            width = char_size.width * size;
            chunks(settings.message, size).forEach(function(line) {
                var $line = $('<div class="line"/>').appendTo(header);
                $line.append('<span class="left light">' + chars.ver +
                             '&nbsp;</span>');
                $('<span>' + line + '</span>').width(width).appendTo($line);
                $line.append('<span class="left dark">&nbsp;' + chars.ver +
                             '</span>');
            });
        }

        var input = $('<div class="input"/>').appendTo(box);

        var input_line = $('<div class="line"/>').appendTo(input);
        var input_left = $('<div class="left light">' + chars.ver +
                           '&nbsp;</div>').appendTo(input_line);
        var input_top = $('<div class="top"/>').appendTo(input_line);
        line(input_top, chars.nw, chars.ne, {length: cols-4, reverse: true});
        var input_right = $('<div class="right dark">&nbsp;' + chars.ver +
                            '</div>').appendTo(input_line);

        input_line = $('<div class="line"/>').appendTo(input);
        $('<div class="left light">' + chars.ver + '&nbsp;</div>')
            .appendTo(input_line);
        $('<div class="left dark">' + chars.ver + '</div>')
            .appendTo(input_line);
        fn = fn.bind(self);
        width = char_size.width * (cols - 7);
        var cmd = $('<div/>').width(width).appendTo(input_line).cmd({
            prompt: '',
            commands: fn,
            keydown: function() {
                setTimeout(function() {
                    cmd.scrollLeft(cmd.prop('scrollWidth'));
                }, 0);
            },
            keymap: {
                UP: up,
                ARROWUP: up,
                DOWN: down,
                ARROWDOWN: down
            }
        });
        cmd.on('click', function() {
            cmd.enable();
            buttons.find('.selected, .active').removeClass('selected active');
            buttons.find('.ok').addClass('active');
        });
        $('<div class="right light">' + chars.ver + '</div>')
            .appendTo(input_line);
        $('<div class="right dark">&nbsp;' + chars.ver + '</div>')
            .appendTo(input_line);

        input_line = $('<div class="line"/>').appendTo(input);
        $('<div class="left light">' + chars.ver + '&nbsp;</div>')
            .appendTo(input_line);
        var input_bottom = $('<div class="bottom"/>').appendTo(input_line);
        line(input_bottom, chars.sw, chars.se, {
            length: cols-4,
            reverse: true,
            bottom: true
        });
        $('<div class="right dark">&nbsp;' + chars.ver + '</div>')
            .appendTo(input_line);

        var separator = $('<div class="separator"/>').appendTo(box);
        line(separator, chars.cw, chars.ce);

        var button_line = $('<div class="buttons-line"/>').appendTo(box);
        $('<div class="left light">' + chars.ver + '</div>')
            .appendTo(button_line);
        width = char_size.width * (cols - 3);
        var buttons = $('<div class="buttons"/>')
            .appendTo(button_line).width(width);
        function tag(str) {
            return str.replace(/_(.)/, '<span class="mark">$1</span>');
        }
        $('<button class="ok active">' + tag($.dialog.strings.ok) +
          '</button>').appendTo(buttons);
        $('<button class="cancel">' + tag($.dialog.strings.cancel) +
          '</button>').appendTo(buttons);
        $('<div class="right dark">' + chars.ver +
          '</div>').appendTo(button_line);

        buttons.on('click', '.ok', function() {
            cmd.disable();
            $(this).addClass('selected active').next()
                .removeClass('selected active');
            fn(cmd.get());
        }).on('click', '.cancel', function() {
            cmd.disable();
            $(this).addClass('selected active').prev()
                .removeClass('selected active');
            settings.cancel.call(self, cmd.get());
        });
        function up() {
            setTimeout(function() {
                cmd.disable();
            }, 0);
            var active = buttons.find('.cancel').addClass('selected active')
                .prev().removeClass('selected active');
        }
        function down() {
            setTimeout(function() {
                cmd.disable();
            }, 0);
            var active = buttons.find('.ok').addClass('selected active')
                .next().removeClass('selected active');
        }
        function keydown(e) {
            var key = e.key.toUpperCase();
            var map = {
                ARROWUP: 'UP',
                ARROWDOWN: 'DOWN',
                ARROWLEFT: 'LEFT',
                ARROWRIGHT: 'RIGHT'
            };
            if (map[key]) {
                key = map[key];
            }
            var active = buttons.find('.active');
            switch (key) {
                case 'ENTER':
                    if (!cmd.isenabled()) {
                        active.click();
                    }
                    break;
                case 'LEFT':
                    if (!cmd.isenabled()) {
                        if (active.is('.ok')) {
                            cmd.enable();
                            active.removeClass('selected');
                        } else {
                            active.removeClass('active selected').prev()
                                .addClass('active selected');
                        }
                    }
                    break;
                case 'RIGHT':
                    if (!cmd.isenabled()) {
                        if (active.is('.cancel')) {
                            cmd.enable();
                            active.removeClass('selected');
                        } else {
                            active.removeClass('active selected').next()
                                .addClass('active selected');
                        }
                    }
                    break;
                case 'UP':
                    if (!cmd.isenabled()) {
                        if (active.is('.ok')) {
                            cmd.enable();
                            active.removeClass('selected active');
                            buttons.find('.ok').addClass('active');
                        } else {
                            active.removeClass('active selected').prev()
                                .addClass('active selected');
                        }
                    }
                    break;
                case 'DOWN':
                    if (!cmd.isenabled()) {
                        if (active.is('.cancel')) {
                            cmd.enable();
                            active.removeClass('selected active');
                            buttons.find('.ok').addClass('active');
                        } else {
                            active.removeClass('active selected').next()
                                .addClass('active selected');
                        }
                    }
                    break;
            }
        }
        $(document).on('keydown', keydown);
        var bottom = $('<div class="bottom"/>').appendTo(box);
        line(bottom, chars.sw, chars.se, {bottom: true});

        box.appendTo(self);

        $.extend(self, {
            destroy: function() {
                self.removeClass('dialog');
                $(document).off('keydown', keydown);
                cmd.destroy();
                box.remove();
            },
            cmd: function() {
                return cmd;
            },
            refresh: function() {
                char_size = get_char_size();
                update_css_var();
            }
        });
        return self;
    };
})(jQuery);


$('body').dialog(function(input) {
    setTimeout(function() {
        alert(input);
    }, 100);
}, {
    cols: 40,
    rows: 10,
    message: 'Hey you',
    title: 'Foo Bar'
});
            
          
!
999px
Loading ..................

Console