<commit_before>extern crate ncurses;
use ncurses::*;
use Cursorstate;
use std::cmp;

pub fn draw(
    buf: &[u8],
    cursorpos: usize,
    cols: usize,
    command: &String,
    debug: &mut String,
    cstate: Cursorstate,
    screenoffset: usize,
) {
    erase();

//    debug.clear();
//    let screensize = get_screen_size(cols);
//    debug.push_str(&format!("   screensize:{:?}", screensize));
//    debug.push_str(&format!("   screenoffset:{:?}", screenoffset));
//    debug.push_str(&format!("   buf.len():{:?}", buf.len()));

    let screenheight: usize;
    screenheight = getmaxy(stdscr()) as usize;
//    debug.push_str(&format!("   screenheight:{:?}", screenheight));

    let mut tmpbuflen = buf.len();
    if tmpbuflen >= 1 { tmpbuflen -= 1; }
    let rows = tmpbuflen / cols + 1;

//    debug.push_str(&format!("   rows:{:?}", rows));

    for z in 0..rows {
        // 8 hex digits (4GB/cols or 0.25GB@cols=SPALTEN)
        addstr(&format!("{:08X}: ", get_absolute_line(cols, screenoffset, z)));
        // Additional space between line number and hex
        addstr(" ");
        for s in 0..cols {
            let pos: usize = z*cols + s;
            if pos < buf.len() {

                color_left_nibble_cond(true, pos+cols*screenoffset == cursorpos, cstate);
                addstr(&format!("{:01X}", buf[pos] >> 4));
                color_left_nibble_cond(false, pos+cols*screenoffset == cursorpos, cstate);

                color_right_nibble_cond(true, pos+cols*screenoffset == cursorpos, cstate);
                addstr(&format!("{:01X}", buf[pos] & 0x0F));
                color_right_nibble_cond(false, pos+cols*screenoffset == cursorpos, cstate);

                addstr(" ");
            } else if pos == buf.len() {

                color_left_nibble_cond(true, pos+cols*screenoffset == cursorpos, cstate);
                addstr("-");
                color_left_nibble_cond(false, pos+cols*screenoffset == cursorpos, cstate);

                color_right_nibble_cond(true, pos+cols*screenoffset == cursorpos, cstate);
                addstr("-");
                color_right_nibble_cond(false, pos+cols*screenoffset == cursorpos, cstate);

                addstr(" ");
            } else {
                addstr("-- ");
            }
        }
        // Additional space between hex and ascii
        addstr(" ");
        for s in 0..cols {
            let pos: usize = z*cols + s;
            color_ascii_cond(true, pos+cols*screenoffset == cursorpos, cstate);
            if pos < buf.len() {
                if let c @ 32...126 = buf[pos] {
                    if c as char == '%' {
                        // '%' needs to be escaped by a '%' in ncurses
                        addstr("%%");
                    } else {
                        addstr(&format!("{}", c as char));
                    }
                } else {
                    // Mark non-ascii symbols
                    addstr(&format!("."));
                }
            } else if pos == buf.len() {
                // Pad ascii with spaces
                addstr(" ");
            }

            color_ascii_cond(false, pos+cols*screenoffset == cursorpos, cstate);
        }
        addstr("\n");
    }<commit_msg>Remove '%'-escape from old ncurses::printw<commit_after>extern crate ncurses;
use ncurses::*;
use Cursorstate;
use std::cmp;

pub fn draw(
    buf: &[u8],
    cursorpos: usize,
    cols: usize,
    command: &String,
    debug: &mut String,
    cstate: Cursorstate,
    screenoffset: usize,
) {
    erase();

//    debug.clear();
//    let screensize = get_screen_size(cols);
//    debug.push_str(&format!("   screensize:{:?}", screensize));
//    debug.push_str(&format!("   screenoffset:{:?}", screenoffset));
//    debug.push_str(&format!("   buf.len():{:?}", buf.len()));

    let screenheight: usize;
    screenheight = getmaxy(stdscr()) as usize;
//    debug.push_str(&format!("   screenheight:{:?}", screenheight));

    let mut tmpbuflen = buf.len();
    if tmpbuflen >= 1 { tmpbuflen -= 1; }
    let rows = tmpbuflen / cols + 1;

//    debug.push_str(&format!("   rows:{:?}", rows));

    for z in 0..rows {
        // 8 hex digits (4GB/cols or 0.25GB@cols=SPALTEN)
        addstr(&format!("{:08X}: ", get_absolute_line(cols, screenoffset, z)));
        // Additional space between line number and hex
        addstr(" ");
        for s in 0..cols {
            let pos: usize = z*cols + s;
            if pos < buf.len() {

                color_left_nibble_cond(true, pos+cols*screenoffset == cursorpos, cstate);
                addstr(&format!("{:01X}", buf[pos] >> 4));
                color_left_nibble_cond(false, pos+cols*screenoffset == cursorpos, cstate);

                color_right_nibble_cond(true, pos+cols*screenoffset == cursorpos, cstate);
                addstr(&format!("{:01X}", buf[pos] & 0x0F));
                color_right_nibble_cond(false, pos+cols*screenoffset == cursorpos, cstate);

                addstr(" ");
            } else if pos == buf.len() {

                color_left_nibble_cond(true, pos+cols*screenoffset == cursorpos, cstate);
                addstr("-");
                color_left_nibble_cond(false, pos+cols*screenoffset == cursorpos, cstate);

                color_right_nibble_cond(true, pos+cols*screenoffset == cursorpos, cstate);
                addstr("-");
                color_right_nibble_cond(false, pos+cols*screenoffset == cursorpos, cstate);

                addstr(" ");
            } else {
                addstr("-- ");
            }
        }
        // Additional space between hex and ascii
        addstr(" ");
        for s in 0..cols {
            let pos: usize = z*cols + s;
            color_ascii_cond(true, pos+cols*screenoffset == cursorpos, cstate);
            if pos < buf.len() {
                if let c @ 32...126 = buf[pos] {
                    addstr(&format!("{}", c as char));
                } else {
                    // Mark non-ascii symbols
                    addstr(&format!("."));
                }
            } else if pos == buf.len() {
                // Pad ascii with spaces
                addstr(" ");
            }

            color_ascii_cond(false, pos+cols*screenoffset == cursorpos, cstate);
        }
        addstr("\n");
    }
{'fraction_non_alphanumeric': 0.15129797738493392, 'fraction_numerical': 0.008281573498964804, 'mean_word_length': 1.8403437358661239, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '4684829', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1902, 'n_words': 420}