<commit_before>/*
 * Console command prompt.
 *
 * Supports typing proposals and custom welcome messages.
 *
 * Implementation of MVC with passive model.
 * This entity is controller, cmdline is model, and screen is view.
 *
 * Author: <NAME>
 */

#include "console.h"
#include "kernel/uart.h"
#include "kernel/sys.h"
#include "common.h"
#include "string.h"
#include "drivers/terminal.h"

#define EDIT_MODEL(console, update, action, ...) \
		do if((action)((console)->model, ##__VA_ARGS__)) { \
			(update)((console)->view, (console)->model); \
		} while(0)

#define CB_EDIT_MODEL(action, ...) \
		EDIT_MODEL((CONSOLE *) cb->outer, screen_out_update, action, ##__VA_ARGS__)

CONSOLE *cur_console = NULL;

static int on_new_line(SCREEN_CALLBACK *cb, SCREEN *view, int by) {
	CONSOLE *this = (CONSOLE *) cb->outer;
	char buf[CMDLINE_MAX_LENGTH + 1];
	/*FIXME: resolve "(reverse-i-search)`':" statement */
	char *cmd;
#if 0
	= strstr(this->model->string, ":");
	        if (cmd)
	    		*cmd++;
	    	else
#endif
	cmd = this->model->string;

	if (this->callback != NULL && this->callback->exec != NULL && *cmd) {
		screen_out_puts(this->view, NULL);
		strcpy(buf, cmd);
		this->callback->exec(this->callback, this, buf);
	}
	screen_out_show_prompt(this->view, this->prompt);
	CB_EDIT_MODEL(cmdline_history_new_entry);
	return 0;
}

static int on_char(SCREEN_CALLBACK *cb, SCREEN *view, int ch) {
	CB_EDIT_MODEL(cmdline_chars_insert, &ch,1);
	return 0;
}

static int on_cursor_up(SCREEN_CALLBACK *cb, SCREEN *view, int by) {<commit_msg>Fix problem with console after fixing warning<commit_after>/*
 * Console command prompt.
 *
 * Supports typing proposals and custom welcome messages.
 *
 * Implementation of MVC with passive model.
 * This entity is controller, cmdline is model, and screen is view.
 *
 * Author: <NAME>
 */

#include "console.h"
#include "kernel/uart.h"
#include "kernel/sys.h"
#include "common.h"
#include "string.h"
#include "drivers/terminal.h"

#define EDIT_MODEL(console, update, action, ...) \
		do if((action)((console)->model, ##__VA_ARGS__)) { \
			(update)((console)->view, (console)->model); \
		} while(0)

#define CB_EDIT_MODEL(action, ...) \
		EDIT_MODEL((CONSOLE *) cb->outer, screen_out_update, action, ##__VA_ARGS__)

CONSOLE *cur_console = NULL;

static int on_new_line(SCREEN_CALLBACK *cb, SCREEN *view, int by) {
	CONSOLE *this = (CONSOLE *) cb->outer;
	char buf[CMDLINE_MAX_LENGTH + 1];
	/*FIXME: resolve "(reverse-i-search)`':" statement */
	char *cmd;
#if 0
	= strstr(this->model->string, ":");
	        if (cmd)
	    		*cmd++;
	    	else
#endif
	cmd = this->model->string;

	if (this->callback != NULL && this->callback->exec != NULL && *cmd) {
		screen_out_puts(this->view, NULL);
		strcpy(buf, cmd);
		this->callback->exec(this->callback, this, buf);
	}
	screen_out_show_prompt(this->view, this->prompt);
	CB_EDIT_MODEL(cmdline_history_new_entry);
	return 0;
}

static int on_char(SCREEN_CALLBACK *cb, SCREEN *view, int ch) {
	char tmp_ch = (char)ch;
	CB_EDIT_MODEL(cmdline_chars_insert, &tmp_ch,1);
	return 0;
}

static int on_cursor_up(SCREEN_CALLBACK *cb, SCREEN *view, int by) {
{'fraction_non_alphanumeric': 0.1633045148895293, 'fraction_numerical': 0.0038424591738712775, 'mean_word_length': 4.442508710801394, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 41, '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': '6518467', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1152, 'n_words': 271}