private void setModes(final ControlSequence args, final boolean on) throws IOException
    {
        final int argCount = args.getCount();
        final Mode[] modeTable = args.getModeTable();
        for (int i = 0; i < argCount; i++) {
            final int num = args.getArg(i, -1);
            Mode mode = null;
            if (num >= 0 && num < modeTable.length) {
                mode = modeTable[num];
            }

            if (mode == null) {
                if (logger.isInfoEnabled()) {
                    logger.info("Unknown mode " + num);
                }
            } else if (on) {
                if (logger.isInfoEnabled()) {
                    logger.info("Modes: adding " + mode);
                }
                tw.setMode(mode);

            } else {
                if (logger.isInfoEnabled()) {
                    logger.info("Modes: removing " + mode);
                }
                tw.unsetMode(mode);
            }
        }
    }