<commit_before>#!/usr/bin/env bash

# @includeBy /awql.sh

##
# Read lines from the standard input and split it into fields.
# Manage history in file, completion with tab, navigation with arrow keys and backspace
#
# # pager ?
# http://superuser.com/questions/848516/long-commands-typed-in-bash-overwrite-the-same-line
# echo "set horizontal-scroll-mode off" >> ~/.inputrc
#
# In order to identify witch code for each key, use command: sed -n l
# @param string $1 Name of the variable to retrieve lines
# @param int $2 Use auto rehash for completion
function reader ()
{
    # Variable name use to export the response of prompt
    local READER_VAR_NAME="$1"
    local REPLY
    declare -i WINDOW_WIDTH=$(windowSize "width")

    # History file
    local HISTORY_FILE="${AWQL_HISTORY_FILE}"
    if [[ -n "$HISTORY_FILE" ]]; then
        declare -a HISTORY=()
        if [[ -f "$HISTORY_FILE" ]]; then
            mapfile -t HISTORY < "$HISTORY_FILE"
        fi
        declare -i HISTORY_SIZE=${#HISTORY[@]}
        declare -i HISTORY_INDEX=${HISTORY_SIZE}
    fi

    # Completion
    declare -i AUTO_REHASH="$2"
    local COMPREPLY

    # Introduction messages
    local PROMPT="${AWQL_PROMPT}"
    local PROMPT_NEW_LINE="${AWQL_PROMPT_NEW_LINE}"

    # Launch prompt by sending introducion message
    echo -n "$PROMPT"

    # Read one character at a time
    declare -a READ
    declare -i READ_LENGTH=0
    declare -i READ_INDEX=0
    declare -i CHAR_INDEX=0
    while IFS="" read -rsn1 CHAR; do
        # \x1b is the start of an escape sequence == \033
        if [[ "$CHAR" == $'\x1b' ]]; then
            # Get the rest of the escape sequence (3 characters total)
            while IFS= read -rsn2 REST; do
                CHAR+="$REST"
                break
            done
        fi

        if [[ "$CHAR" == $'\r\n' ]] ; then
            echo "coucou"
        elif [[ "$CHAR" == $'\f' ]]; then
            # Clear the terminal (ctrl + l)
            echo -ne "\r\033c${PROMPT}"
        elif [[ "$CHAR" == $'\x1b[F' || "$CHAR" == $'\x1b[H' || "$CHAR" == $'\x1b[4~' || "$CHAR" == $'\x1b[1~' ]]; then
            # Go to start (home) or end of the line (Fn or ctrl + left and right arrow keys)
            if [[ "$CHAR" == $'\x1b[F' || "$CHAR" == $'\x1b[4~' ]]; then
                # Forward to end
                CHAR_INDEX="$READ_LENGTH"
            else
                # Backward to start
                CHAR_INDEX=0
            fi<commit_msg>Try to fix end and start of line on windows<commit_after>#!/usr/bin/env bash

# @includeBy /awql.sh

##
# Read lines from the standard input and split it into fields.
# Manage history in file, completion with tab, navigation with arrow keys and backspace
#
# # pager ?
# http://superuser.com/questions/848516/long-commands-typed-in-bash-overwrite-the-same-line
# echo "set horizontal-scroll-mode off" >> ~/.inputrc
#
# In order to identify witch code for each key, use command: sed -n l
# @param string $1 Name of the variable to retrieve lines
# @param int $2 Use auto rehash for completion
function reader ()
{
    # Variable name use to export the response of prompt
    local READER_VAR_NAME="$1"
    local REPLY
    declare -i WINDOW_WIDTH=$(windowSize "width")

    # History file
    local HISTORY_FILE="${AWQL_HISTORY_FILE}"
    if [[ -n "$HISTORY_FILE" ]]; then
        declare -a HISTORY=()
        if [[ -f "$HISTORY_FILE" ]]; then
            mapfile -t HISTORY < "$HISTORY_FILE"
        fi
        declare -i HISTORY_SIZE=${#HISTORY[@]}
        declare -i HISTORY_INDEX=${HISTORY_SIZE}
    fi

    # Completion
    declare -i AUTO_REHASH="$2"
    local COMPREPLY

    # Introduction messages
    local PROMPT="${AWQL_PROMPT}"
    local PROMPT_NEW_LINE="${AWQL_PROMPT_NEW_LINE}"

    # Launch prompt by sending introducion message
    echo -n "$PROMPT"

    # Read one character at a time
    declare -a READ
    declare -i READ_LENGTH=0
    declare -i READ_INDEX=0
    declare -i CHAR_INDEX=0
    while IFS="" read -rsn1 CHAR; do
        # \x1b is the start of an escape sequence == \033
        if [[ "$CHAR" == $'\x1b' ]]; then
            # Get the rest of the escape sequence (3 characters total)
            while IFS= read -rsn2 REST; do
                CHAR+="$REST"
                break
            done
        fi

        if [[ "$CHAR" == $'\f' ]]; then
            # Clear the terminal (ctrl + l)
            echo -ne "\r\033c${PROMPT}"
        elif [[ "$CHAR" == $'\x1b[F' || "$CHAR" == $'\x1b[H' || "$CHAR" == $'\001' || "$CHAR" == $'\005' ]]; then
            # Go to start (home) or end of the line (Fn or ctrl + left and right arrow keys)
            if [[ "$CHAR" == $'\x1b[F' || "$CHAR" == $'\005' ]]; then
                # Forward to end
                CHAR_INDEX="$READ_LENGTH"
            else
                # Backward to start
                CHAR_INDEX=0
            fi
{'fraction_non_alphanumeric': 0.12956878850102668, 'fraction_numerical': 0.01457905544147844, 'mean_word_length': 2.1712239583333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2168718', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1539, 'n_words': 506}