<commit_before>import events from 'events';
import Mousetrap from 'mousetrap';
import log from './log';

const buildCombokeys = (key) => {
    const keys = ['ctrl', 'alt', 'command'];
    return keys.concat(key).join('+');
};

const commandKeys = [
    { // Cycle Start
        cmd: 'CYCLE_START',
        keys: '!'
    },
    { // Feed Hold
        cmd: 'FEED_HOLD',
        keys: '~'
    },
    { // Homing
        cmd: 'HOMING',
        keys: ['ctrl','alt','command','h'].join('+')
    },
    { // Unlock
        cmd: 'UNLOCK',
        keys: ['ctrl','alt','command','u'].join('+')
    },
    { // Reset
        cmd: 'RESET',
        keys: ['ctrl','alt','command','r'].join('+')
    },
    { // Increment Button
        cmd: 'INCREMENT_BUTTON',
        keys: '^'
    },
    { // Forward Button
        cmd: 'FORWARD_BUTTON',
        keys: '>'
    },
    { // Backward Button
        cmd: 'BACKWARD_BUTTON',
        keys: '<'
    },
    { // X-Axis Button
        cmd: 'X_AXIS_BUTTON',
        keys: ['ctrl','alt','command','x'].join('+')
    },
    { // Y-Axis Button
        cmd: 'Y_AXIS_BUTTON',
        keys: ['ctrl','alt','command','y'].join('+')
    },
    { // Z-Axis Button
        cmd: 'Z_AXIS_BUTTON',
        keys: ['ctrl','alt','command','z'].join('+')
    }
];

class Combokeys extends events.EventEmitter {
    state = {
        didBindEvents: false
    };
    list = [];

    constructor(options = {}) {
        super();

        if (options.autoBind) {
            this.bind();
        }
    }
    bind() {
        if (this.state.didBindEvents) {
            return;
        }
        commandKeys.forEach((o) => {
            const { cmd, keys } = o;
            const callback = () => {
                log.debug('Combokeys:', cmd, keys);
                this.emit(cmd);
            };
            Mousetrap.bind(keys, callback);
            this.list.push({ keys: keys, callback: callback });
        });
        this.state.didBindEvents = true;
    }
    unbind() {
        if (!this.state.didBindEvents) {
            return;
        }
        this.list.forEach((o) => {
            const { keys, callback } = o;
            Mousetrap.unbind(keys, callback);
        });
        this.state.didBindEvents = false;
    }
    reset() {
        Mousetrap.reset();
        this.state.didBindEvents = false;
    }
}

const combokeys = new Combokeys({ autoBind: true });

export default combokeys;
<commit_msg>#20 Shuttle Express jog dial support<commit_after>import events from 'events';
import Mousetrap from 'mousetrap';
import log from './log';

const buildCombokeys = (key) => {
    const keys = ['ctrl', 'alt', 'command'];
    return keys.concat(key).join('+');
};

const commandKeys = [
    { // Cycle Start
        cmd: 'CYCLE_START',
        keys: '!'
    },
    { // Feed Hold
        cmd: 'FEED_HOLD',
        keys: '~'
    },
    { // Homing
        cmd: 'HOMING',
        keys: ['ctrl','alt','command','h'].join('+')
    },
    { // Unlock
        cmd: 'UNLOCK',
        keys: ['ctrl','alt','command','u'].join('+')
    },
    { // Reset
        cmd: 'RESET',
        keys: ['ctrl','alt','command','r'].join('+')
    },
    { // Jog Lever Switch
        cmd: 'JOG_LEVER_SWITCH',
        keys: '^'
    },
    { // Jog Forward
        cmd: 'JOG_FORWARD',
        keys: '>'
    },
    { // Jog Backward
        cmd: 'JOG_BACKWARD',
        keys: '<'
    },
    { // X-Axis
        cmd: 'X_AXIS',
        keys: ['ctrl','alt','command','x'].join('+')
    },
    { // Y-Axis
        cmd: 'Y_AXIS',
        keys: ['ctrl','alt','command','y'].join('+')
    },
    { // Z-Axis
        cmd: 'Z_AXIS',
        keys: ['ctrl','alt','command','z'].join('+')
    }
];

class Combokeys extends events.EventEmitter {
    state = {
        didBindEvents: false
    };
    list = [];

    constructor(options = {}) {
        super();

        if (options.autoBind) {
            this.bind();
        }
    }
    bind() {
        if (this.state.didBindEvents) {
            return;
        }
        commandKeys.forEach((o) => {
            const { cmd, keys } = o;
            const callback = () => {
                log.debug('Combokeys:', cmd, keys);
                this.emit(cmd);
            };
            Mousetrap.bind(keys, callback);
            this.list.push({ keys: keys, callback: callback });
        });
        this.state.didBindEvents = true;
    }
    unbind() {
        if (!this.state.didBindEvents) {
            return;
        }
        this.list.forEach((o) => {
            const { keys, callback } = o;
            Mousetrap.unbind(keys, callback);
        });
        this.state.didBindEvents = false;
    }
    reset() {
        Mousetrap.reset();
        this.state.didBindEvents = false;
    }
}

const combokeys = new Combokeys({ autoBind: true });

export default combokeys;

{'fraction_non_alphanumeric': 0.18413950591654557, 'fraction_numerical': 0.00041519618019514223, 'mean_word_length': 1.6766666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3710173', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1555, 'n_words': 293}