<commit_before>var blessed = require('blessed');

var logger = require('../logger')
  , config = require('../config')
  , session = require('../app')
  , { safeGet, getPersonaColor } = require('../helpers');

var ui = require('./ui');

var box = {};

// TODO: implement showGames()

module.exports = { 
    box, 
    updateFriend,
    updateGroup,
    clearList: () => box.setContent(""),
    listSelect,
    findFriend,
    createBox: (screen) => {
        box = blessed.box({
            top: 0,
            right: 0,
            width: config.get('userlistwidth') - 1,
            height: "100%-2",
            tags: true,
            style: { scrollbar: { bg: 'blue' } }
        });
        screen.append(box);
    }
};

var list = {
    online:  [],
    ingame:  [],
    busy:    [],
    away:    [],
    snooze:  [],
    offline: [],
    arrOrder: [ 'online', 'ingame', 'busy',
                'away', 'snooze', 'offline' ]
};

function updateFriend() {

    clearArr();

    session.friends.forEach((steamID) => {
        if (steamID in session.users) {
            addUser(session.users[steamID]);
        }
    });

    sortArr();
    updateBox();
}

function updateGroup(chatID) {

    clearArr();

    const clan = safeGet(session.clans, chatID, 'members');
    for (var steamID in clan) {
        if (steamID in session.users) {
            addUser(session.users[steamID]);
        }
    }

    sortArr();
    updateBox();
}

function clearArr() {
    list.arrOrder.forEach(
        (arr) => list[arr].length = 0
    );
}

function sortArr() {
     list.arrOrder.forEach(
        (arr) => list[arr].sort(
            (a, b) => a.localeCompare(b)
        )
    );
}
   
function updateBox() { 

    box.setContent("");

    list.arrOrder.forEach((arrName) => {
        var arr = list[arrName];
        if (arr.length > 0)
            box.insertBottom(arr);
    });
<commit_msg>Slice userlist entries and save userlistwidth<commit_after>var blessed = require('blessed');

var logger = require('../logger')
  , config = require('../config')
  , session = require('../app')
  , { safeGet, getPersonaColor } = require('../helpers');

var ui = require('./ui');

var box = {};

// TODO: implement showGames()

module.exports = { 
    box, 
    updateFriend,
    updateGroup,
    clearList: () => box.setContent(""),
    listSelect,
    findFriend,
    createBox: (screen) => {
        userwidth = config.get('userlistwidth') - 1;
        box = blessed.box({
            top: 0,
            right: 0,
            width: userwidth,
            height: "100%-2",
            tags: true,
            style: { scrollbar: { bg: 'blue' } }
        });
        screen.append(box);
    }
};

var userwidth;
var list = {
    online:  [],
    ingame:  [],
    busy:    [],
    away:    [],
    snooze:  [],
    offline: [],
    arrOrder: [ 'online', 'ingame', 'busy',
                'away', 'snooze', 'offline' ]
};

function updateFriend() {

    clearArr();

    session.friends.forEach((steamID) => {
        if (steamID in session.users) {
            addUser(session.users[steamID]);
        }
    });

    sortArr();
    updateBox();
}

function updateGroup(chatID) {

    clearArr();

    const clan = safeGet(session.clans, chatID, 'members');
    for (var steamID in clan) {
        if (steamID in session.users) {
            addUser(session.users[steamID]);
        }
    }

    sortArr();
    updateBox();
}

function clearArr() {
    list.arrOrder.forEach(
        (arr) => list[arr].length = 0
    );
}

function sortArr() {
     list.arrOrder.forEach(
        (arr) => list[arr].sort(
            (a, b) => a.localeCompare(b)
        )
    );
}
   
function updateBox() { 

    box.setContent("");

    list.arrOrder.forEach((arrName) => {

        var arr = list[arrName].map((str) => {
            if (str.length > userwidth) 
                return str.slice(0, userwidth-1).concat('$');
            else
                return str;
        });

        if (arr.length > 0)
            box.insertBottom(arr);
    });

{'fraction_non_alphanumeric': 0.16997518610421836, 'fraction_numerical': 0.004962779156327543, 'mean_word_length': 1.9210144927536232, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '4287299', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1309, 'n_words': 258}