# tokens for sepbar are:
#    .username = ping
#    >username = login
#    <username = logout
#    :username = personal message
#    M         = mail received
my @sepbartokens;

# adds a sepbartoken and also updates the appendtosepbar variable
sub sepbartokens_add ($) {
    my ($token) = @_;
    $token =~ s/"//g;  # remove "
    unshift @sepbartokens, $token;
    pop @sepbartokens if (@sepbartokens > 80);
    sepbartokens_set();
}

# trims a sepbartoken from the list and updates the appendtosepbar variable
sub sepbartokens_trim ($) {
    my ($token) = @_;
    @sepbartokens = grep { $_ ne $token } @sepbartokens;
    sepbartokens_set();
}

# redraws the sepbar according to the current token array
sub sepbartokens_set () {
    owl::command("set -q appendtosepbar \"@sepbartokens\"");
}

# reset the sepbartokens to empty and updates the appendtosepbar variable
sub sepbartokens_reset () {
    @sepbartokens = ();
    sepbartokens_set();
}

sub sepbartokens_init () {
    owl::command('alias sepbar_reset perl sepbartokens_reset');
    owl::command('bindkey recv "C-x c" command sepbar_reset');
}

1;
