#include <stdio.h>
#include <string.h>

#include "shell.h"

static void print_prompt(const struct shell *sh)
{
    fprintf(stdout, "%s> ", sh->name);
    fflush(stdout);
}

int shell_read(struct shell *sh, char *line, size_t size)
{
    (void)size;
    print_prompt(sh);
    if (gets(line) == NULL)
        return -1;
    strcpy(sh->last, line);
    return 0;
}

void shell_reset(struct shell *sh)
{
    memset(sh->history, sizeof sh->history, 0);
    sh->count = 0;
}

void shell_error(const struct shell *sh, const char *msg)
{
    fprintf(stderr, msg);
}
