<commit_before>#include "console.h"
#include "util/bitmap.h"
#include "util/font.h"
#include "util/funcs.h"
#include "util/file-system.h"
#include "input/input-manager.h"
#include "input/input-map.h"
#include "globals.h"
#include <string>
#include <sstream>

using namespace std;

ConsoleEnd Console::endl;
const std::string Console::DEFAULT_FONT = Global::DEFAULT_FONT;

Console::Console(const int maxHeight, const std::string & font):
state(Closed),
maxHeight(maxHeight),
height(0),
font(font),
textHeight(15),
textWidth(15),
offset(0){
    const int delay = 10;
    input.set(Keyboard::Key_TILDE, delay * 2, false, '~');
    input.set(Keyboard::Key_A, delay, false, 'a');
    input.set(Keyboard::Key_BACKSPACE, delay, false, 9);
    input.set(Keyboard::Key_ESC, delay, false, 8);
}

Console::~Console(){
}
    
void Console::act(){
    double speed = 10.0;
    switch (state){
        case Closed : {
            break;
        }
        case Open : {
            break;
        }
        case Closing : {
            int distance = height;
            height -= (int)((double)distance / speed + 1.0);
            if (height <= 0){
                height = 0;
                state = Closed;
            }
            break;
        }
        case Opening : {
            int distance = maxHeight - height;
            height += (int)((double)distance / speed + 1.0);
            if (height >= maxHeight){
                height = maxHeight;
                state = Open;
            }
            break;
        }
    }
    checkStream();
}
    
bool Console::doInput() throw (ReturnException) {
    InputMap<char>::Output inputState = InputManager::getMap(input);
    if (inputState['~']){
        toggle();
        return false;
    }

    if (inputState['a']){
        currentCommand << 'a';
    }

    if (inputState[8]){
        throw ReturnException();
    }

    if (inputState[9]){
        backspace();
    }

    return true;
}

void Console::draw(const Bitmap & work){
    /* if we can show something */
    if (height > 0){
        Bitmap::drawingMode(Bitmap::MODE_TRANS);
	Bitmap::transBlender(0, 0, 0, 160);
        work.rectangleFill(0, 0, work.getWidth(), height, Bitmap::makeColor(200,0,0));
        work.horizontalLine(0, height, work.getWidth(), Bitmap::makeColor(200, 200, 200));
        const Font & font = Font::getFont(Filesystem::find(getFont()), textWidth, textHeight);
        //font.printf(0, height - font.getHeight(), Bitmap::makeColor(255, 255, 255), work, "Console!", 0 );<commit_msg>read entire alphabet in console<commit_after>#include "console.h"
#include "util/bitmap.h"
#include "util/font.h"
#include "util/funcs.h"
#include "util/file-system.h"
#include "input/input-manager.h"
#include "input/input-map.h"
#include "globals.h"
#include <string>
#include <sstream>

using namespace std;

namespace ConsoleInput{
static int Toggle = 254;
static int Backspace = 9;
static int Esc = 8;
}

ConsoleEnd Console::endl;
const std::string Console::DEFAULT_FONT = Global::DEFAULT_FONT;

Console::Console(const int maxHeight, const std::string & font):
state(Closed),
maxHeight(maxHeight),
height(0),
font(font),
textHeight(15),
textWidth(15),
offset(0){
    const int delay = 10;
    input.set(Keyboard::Key_TILDE, delay * 2, false, ConsoleInput::Toggle);
    input.set(Keyboard::Key_BACKSPACE, delay, false, ConsoleInput::Backspace);
    input.set(Keyboard::Key_ESC, delay, false, ConsoleInput::Esc);
    
    /* ugh, do we really have to enumerate every key?? */
    input.set(Keyboard::Key_A, delay, false, 'a');
    input.set(Keyboard::Key_B, delay, false, 'b');
    input.set(Keyboard::Key_C, delay, false, 'c');
    input.set(Keyboard::Key_D, delay, false, 'd');
    input.set(Keyboard::Key_E, delay, false, 'e');
    input.set(Keyboard::Key_F, delay, false, 'f');
    input.set(Keyboard::Key_G, delay, false, 'g');
    input.set(Keyboard::Key_H, delay, false, 'h');
    input.set(Keyboard::Key_I, delay, false, 'i');
    input.set(Keyboard::Key_J, delay, false, 'j');
    input.set(Keyboard::Key_K, delay, false, 'k');
    input.set(Keyboard::Key_L, delay, false, 'l');
    input.set(Keyboard::Key_M, delay, false, 'm');
    input.set(Keyboard::Key_N, delay, false, 'n');
    input.set(Keyboard::Key_O, delay, false, 'o');
    input.set(Keyboard::Key_P, delay, false, 'p');
    input.set(Keyboard::Key_Q, delay, false, 'q');
    input.set(Keyboard::Key_R, delay, false, 'r');
    input.set(Keyboard::Key_S, delay, false, 's');
    input.set(Keyboard::Key_T, delay, false, 't');
    input.set(Keyboard::Key_U, delay, false, 'u');
    input.set(Keyboard::Key_V, delay, false, 'v');
    input.set(Keyboard::Key_W, delay, false, 'w');
    input.set(Keyboard::Key_X, delay, false, 'x');
    input.set(Keyboard::Key_Y, delay, false, 'y');
    input.set(Keyboard::Key_Z, delay, false, 'z');
}

Console::~Console(){
}
    
void Console::act(){
    double speed = 10.0;
    switch (state){
        case Closed : {
            break;
        }
        case Open : {
            break;
        }
        case Closing : {
            int distance = height;
            height -= (int)((double)distance / speed + 1.0);
            if (height <= 0){
                height = 0;
                state = Closed;
            }
            break;
        }
        case Opening : {
            int distance = maxHeight - height;
            height += (int)((double)distance / speed + 1.0);
            if (height >= maxHeight){
                height = maxHeight;
                state = Open;
            }
            break;
        }
    }
    checkStream();
}

static bool isChar(char c){
    return c >= 'a' && c <= 'z';
}

bool Console::doInput() throw (ReturnException) {
    InputMap<char>::Output inputState = InputManager::getMap(input);
    if (inputState[ConsoleInput::Toggle]){
        toggle();
        return false;
    }

    for (InputMap<char>::Output::iterator it = inputState.begin(); it != inputState.end(); it++){
        char c = (*it).first;
        bool pressed = (*it).second;
        if (pressed && isChar(c)){
            currentCommand << c;
        }
    }

    if (inputState[ConsoleInput::Esc]){
        throw ReturnException();
    }

    if (inputState[ConsoleInput::Backspace]){
        backspace();
    }

    return true;
}

void Console::draw(const Bitmap & work){
    /* if we can show something */
    if (height > 0){
        Bitmap::drawingMode(Bitmap::MODE_TRANS);
	Bitmap::transBlender(0, 0, 0, 160);
        work.rectangleFill(0, 0, work.getWidth(), height, Bitmap::makeColor(200,0,0));
        work.horizontalLine(0, height, work.getWidth(), Bitmap::makeColor(200, 200, 200));
        const Font & font = Font::getFont(Filesystem::find(getFont()), textWidth, textHeight);
        //font.printf(0, height - font.getHeight(), Bitmap::makeColor(255, 255, 255), work, "Console!", 0 );
{'fraction_non_alphanumeric': 0.16389132340052587, 'fraction_numerical': 0.01679813029506281, 'mean_word_length': 2.7975596228508044, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '4763238', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2218, 'n_words': 511}