ScalpiEditor

Artifact [311e61882d]
Login

Artifact [311e61882d]

Artifact 311e61882d412ee434cc4e8dce645bed7ad2480f63350a82a5e96d86b2daef5c:


// about
    // ScalpiEditor - ansi-only text editor for terminals.
    // killer features: no. its just editor.
    // licenze:
        // This code and its derivatives can be used under the following conditions:
        // - Do not attack other countries.
        // - Jerk off on public at least 1 time per day.
        // - maintain hygiene.
        // - check my other projects https://chiselapp.com/user/sergey6661313
    // Compile:
        // latest release tested with zig ver 0.15.1 downloaded from https://ziglang.org/download/
        // for generate executable file use:
            // linux:   zig build-exe -lc -O ReleaseSmall -target x86_64-linux-gnu  -mcpu baseline ./main.zig -I "."
                // x86_64-linux-musl not work, becouse zig ^_^
            // windows: zig build-exe -lc -O ReleaseSmall -target x86_64-windows    -mcpu baseline ./main.zig -I "."
    // known bugs in windows:
        // f5 - f12 not work in windows in some terminals. (i use Alacritty)
        // some time brackets not are not written
            // its not editor bug.
            // this happened if you try press ctrl+r in prompt shell with non english keyboard.
            // this action just crack your terminal session.
            // just restart your terminal session and it will be ok.
    // to support me
        // with boosty:
            // https://boosty.to/cutloosedev
        
        // with monero:
            // 87T7 qGbA TrM3 a6Br
            // DyeC jQQf NWtU u3iZ
            // bHVB MC6W mEbN NE13
            // Qrrt KhBb e4vF 58NR
            // 8PTF dYk2 Sozc HexX
            // 4Q69 jbdQ Asrs P7B
    // tested in terminals:
        // linux
            // Alacritty
            // WezTerm
            // sakura
            
        // windows
            // Alacritty-v0.13.2-portable
            // tabby-1.0.207-portable-x64
            // WezTerm-windows-20240520-135708-b8f94c47.
            // contour-0.4.3.6442-win64
            // hyper_4.0.0-canary.5
            // windows_terminal - need some unbind keys to work.
    
            // not tested in terminals:
                // extratermqt-0.77.0-windows-x64 - not run in my system.
// todo
    // find way to remove __AppEditorHistoryNote_alloc__ (zig not compiled without it)
        // all func uses this is dependence on AppEditor. first move AppEditor to C
    // remove from fn c.__OsConsoleOutput_write__ null len variant
    // add ability to read part of file for work with extra big files.
// import
    const std = @import("std");
    const builtin = @import("builtin");
    
    const c = @cImport({
        @cDefine("__COMPILED_FROM_ZIG_FILE__", "1");
        @cDefine("_NO_CRT_STDIO_INLINE", "1"); // https://github.com/ziglang/zig/issues/515
        switch(builtin.os.tag) {
            .windows => @cDefine("_WIN32", "1"),
            .linux   => @cDefine("__linux__", "1"),
            else => {},
        }
        @cInclude("main.c");
    });
// functions
    // # __AppEditorViewsEasyMotionHorizontal_onKey__
        fn __AppEditorViewsEasyMotionHorizontal_onKey__(ctx: ?*anyopaque, cik: c.__ConsoleAnsiInputKey__) callconv(.c) void { __zig_fuck__(ctx);
            
            if ( cik == c.__ConsoleAnsiInputKey_escape__ ) {
                c.__AppEditorViewsEasyMotionHorizontalContext_vtable__.*.setAsView.?(c.__AppEditorViewsEasyMotionHorizontal_context__);
            
            } else if ( cik == c.__ConsoleAnsiInputKey_ctrl_q__ ) {
                __AppEditor_stop__(&c.__app__.editor) catch {};
                
            } else {
                const byte: u8 = @truncate(cik);
                
                if ( byte >= '0' and byte <= '9' ) {
                    const pos: usize = byte - '0' + ('z' - 'a') + 1;
                    c.__AppEditorViewsEasyMotionHorizontal_moveTo__(pos * c.__AppEditorViewsEasyMotionHorizontal_step__);
                
                } else if (byte >= 'a' and byte <= 'z' ) {
                    const pos: usize = byte - 'a';
                    c.__AppEditorViewsEasyMotionHorizontal_moveTo__(pos * c.__AppEditorViewsEasyMotionHorizontal_step__);
                
                }
            
            }
        }
    // # __AppEditorViewsEasyMotionHorizontal_setAsView__
        fn __AppEditorViewsEasyMotionHorizontal_setAsView__(last_context: *anyopaque, last_vtable: *const c.__AppEditorViewsVTable__) callconv(.c) void {
            c.__AppEditorViewsEasyMotionHorizontal_context__       = last_context;
            c.__AppEditorViewsEasyMotionHorizontalContext_vtable__ = last_vtable;
            c.__app__.editor.do_ptr      = null;
            c.__app__.editor.onKey_ptr   = &__AppEditorViewsEasyMotionHorizontal_onKey__;
            c.__app__.editor.current_ctx = null;
            c.__AppEditorViewsEasyMotionHorizontal_draw__();
        }
    // # __AppEditorViewsEasyMotionVertical_draw__
        fn __AppEditorViewsEasyMotionVertical_draw__() !void {
            const terminal = &c.__app__.terminal;
            c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_easy_motion__, c.__AppEditorTheme_easy_motion__.len);
            
            const vox = c.__AppEditorViewsEasyMotionVertical_context_vtable__.*.getOffsetX.?(c.__AppEditorViewsEasyMotionVertical_context__);
            var pos: usize = 0;
            var rune: u8 = 'a';
            while (true) {
                if (pos >= terminal.output.size.y - 1 - c.__AppEditorViewsEasyMotionVertical_step__) break;
                
                c.__Terminal_cursorMove__(terminal, vox, pos);
                c.__Terminal_writeToOutput__(terminal, &rune, 1);
                
                if (rune == '9') {
                    break;
                } else if (rune == 'z') {
                    rune = '0';
                } else {
                    rune += 1;
                }
                
                pos += c.__AppEditorViewsEasyMotionVertical_step__;
            }
        }
    // # __AppEditorViewsEasyMotionVertical_moveTo__
        fn __AppEditorViewsEasyMotionVertical_moveTo__(pos: u8) !void {
            const voy = c.__AppEditorViewsEasyMotionVertical_context_vtable__.*.getOffsetY.?(c.__AppEditorViewsEasyMotionVertical_context__);
            
            if (voy > pos) {
                const gtpl = c.__AppEditorViewsEasyMotionVertical_context_vtable__.*.goToPrevLine.?;
                var i = voy - pos;
                while (i > 0) : (i -= 1) {
                    gtpl(c.__AppEditorViewsEasyMotionVertical_context__);
                }
            
            } else if (voy < pos) {
                const gtnl = c.__AppEditorViewsEasyMotionVertical_context_vtable__.*.goToNextLine.?;
                var i = pos - voy;
                while (i > 0) : (i -= 1) {
                    gtnl(c.__AppEditorViewsEasyMotionVertical_context__);
                }
            }
            
            else { // (voy == pos)
            }
            
            c.__AppEditorViewsEasyMotionVertical_context_vtable__.*.setAsView.?(c.__AppEditorViewsEasyMotionVertical_context__);
        }
    // # __AppEditorViewsEasyMotionVertical_onKey__
        fn __AppEditorViewsEasyMotionVertical_onKey__(ctx: ?*anyopaque, cik: c.__ConsoleAnsiInputKey__) callconv(.c) void { __zig_fuck__(ctx);
            if (cik == c.__ConsoleAnsiInputKey_escape__) {
                c.__AppEditorViewsEasyMotionVertical_context_vtable__.*.setAsView.?(c.__AppEditorViewsEasyMotionVertical_context__);
            } else if (cik == c.__ConsoleAnsiInputKey_ctrl_q__) {
                __AppEditor_stop__(&c.__app__.editor) catch {};
            } else {
                const byte: u8 = @truncate(cik);
                
                if (byte >= '0' and byte <= '9') {
                    const pos: u8 = byte - '0' + ('z' - 'a') + 1;
                    __AppEditorViewsEasyMotionVertical_moveTo__(pos * @as(u8, @intCast(c.__AppEditorViewsEasyMotionVertical_step__))) catch {};
                
                } else if (byte >= 'a' and byte <= 'z') {
                    const pos: u8 = byte - 'a';
                    __AppEditorViewsEasyMotionVertical_moveTo__(pos * @as(u8, @intCast(c.__AppEditorViewsEasyMotionVertical_step__))) catch {};
                
                }
            }
        }
    // # __AppEditorViewsEasyMotionVertical_setAsView__
        fn __AppEditorViewsEasyMotionVertical_setAsView__(last_context: *anyopaque, last_vtable: *const c.__AppEditorViewsVTable__) callconv(.c) void {
            c.__AppEditorViewsEasyMotionVertical_context__        = last_context;
            c.__AppEditorViewsEasyMotionVertical_context_vtable__ = last_vtable;
            c.__app__.editor.do_ptr      = null;
            c.__app__.editor.onKey_ptr   = &__AppEditorViewsEasyMotionVertical_onKey__;
            c.__app__.editor.current_ctx = null;
            __AppEditorViewsEasyMotionVertical_draw__() catch unreachable;
        }
    // # __AppEditorViewsFind_CtrlShiftLeft__
        fn __AppEditorViewsFind_CtrlShiftLeft__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            const line: *c.__AppEditorLine__ = t.line;
            if (line.text_len > 0) {
                const indent = c.__TextAscii_countIndent__(line.text, line.text_len, 1);
                if (t.symbol > indent) {
                    t.goToSymbol(indent);
                } else {
                    t.goToStartOfLine();
                }
            } else {
                t.goToStartOfLine();
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_CtrlShiftRight__
        fn __AppEditorViewsFind_CtrlShiftRight__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            const line: *c.__AppEditorLine__ = t.line;
            if (line.text_len > 0) {
                const indent = c.__TextAscii_countIndent__(line.text, line.text_len, 1);
                if (t.symbol < indent) t.goToSymbol(indent) else t.goToEndOfLine();
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsFind_cancel__
        fn __AppEditorViewsFind_cancel__(t: *c.__AppEditorViewsFind__) !void {
            t.context_vtable.*.setAsView.?(t.context);
        }
    // # __AppEditorViewsFind_clearLine__
        fn __AppEditorViewsFind_clearLine__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            t.line.text_len = 0;
            __AppEditorViewsFind_goToStartOfText__(t);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_correctOffset__
        fn __AppEditorViewsFind_correctOffset__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            const predel = (c.__app__.terminal.output.size.y >> 1) - (c.__app__.terminal.output.size.y >> 4);
            if (t.symbol >= predel) t.offset.x = predel;
        }
    // # __AppEditorViewsFind_ctrlLeft__
        fn __AppEditorViewsFind_ctrlLeft__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            __AppEditorViewsFind_goToPrevSymbol__(t);
            if (t.symbol == 0) return;
            if (t.line.text_len > 0) {
                const line: *c.__AppEditorLine__ = &t.line;
                const full_text = line.text[0..line.text_len];
                const text      = full_text[0 .. t.symbol];
                const spaces    = c.__TextAscii_countIndentReverse__(text.ptr, text.len, 1);
                if (spaces > 0) {
                    __AppEditorViewsFind_goToSymbol__(t, t.symbol - spaces);
                    t.need_redraw = true;
                    return;
                }
                const dest_pos = c.__TextAscii_findBreakOfWordReverse__(text.ptr, text.len) + 1;
                __AppEditorViewsFind_goToSymbol__(t, dest_pos);
            } else {
                __AppEditorViewsFind_goToSymbol__(t, 0);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_ctrlRight__
        fn __AppEditorViewsFind_ctrlRight__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            __AppEditorViewsFind_goToNextSymbol__(t);
            if (t.line.text_len > 0) {
                const full_text = t.line.text[0..t.line.text_len];
                if (t.symbol >= full_text.len) return;
                const text = full_text[t.symbol..];
                const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                if (indent > 0) {
                    __AppEditorViewsFind_goToSymbol__(t, t.symbol + indent);
                    t.need_redraw = true;
                    return;
                }
                __AppEditorViewsFind_goToSymbol__(t, c.__TextAscii_findBreakOfWord__(text.ptr, text.len) + t.symbol);
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsFind_cursorMoveToCurrent__
        fn __AppEditorViewsFind_cursorMoveToCurrent__(t: *c.__AppEditorViewsFind__) !void {
            c.__Terminal_cursorMove__(&c.__app__.terminal, t.offset.x, t.offset.y);
        }
    // # __AppEditorViewsFind_deletePrevSymbol__
        fn __AppEditorViewsFind_deletePrevSymbol__(t: *c.__AppEditorViewsFind__) !void {
            if (t.symbol == 0) {
                return;
            } else if (t.symbol > t.line.text_len) {
                __AppEditorViewsFind_goToPrevSymbol__(t);
            } else {
                if (t.line.text_len == 0) return;
                __AppEditorViewsFind_goToPrevSymbol__(t);
                __AppEditorViewsFind_deleteSymbol__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_deleteSymbol__
        fn __AppEditorViewsFind_deleteSymbol__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            if (t.line.text_len == 0) return;
            
            if (c.__Buffer_pop_check__(t.line.text_len, t.symbol)) {
                _=c.__Buffer_pop__(&t.line.text[0], &t.line.text_len, t.symbol);
            }
            
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_deleteWord__
        fn __AppEditorViewsFind_deleteWord__(t: *c.__AppEditorViewsFind__) !void {
            if (t.symbol > t.line.text_len) {
                return;
            }
            while (true) { // delete current symbol
                if (t.symbol == t.line.text_len) {
                    break;
                }
                const next_symbol = t.line.text[t.symbol];
                if (c.__TextAscii_isLetter__(next_symbol)) {
                    __AppEditorViewsFind_deleteSymbol__(t);
                } else {
                    break;
                }
            }
            while (true) { // delete prev    symbol
                if (t.symbol == 0) {
                    break;
                }
                const prev_symbol = t.line.text[t.symbol - 1];
                if (c.__TextAscii_isLetter__(prev_symbol)) {
                    try __AppEditorViewsFind_deletePrevSymbol__(t);
                } else {
                    break;
                }
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_do__
        fn __AppEditorViewsFind_do__(ctx: *anyopaque) callconv(.c) void {
            const t = __AppEditorViewsFind_getModel__(ctx);
            
            if (t.need_redraw == true) {
                t.need_redraw = false;
                __AppEditorViewsFind_draw__(t) catch unreachable;
                __AppEditorViewsFind_cursorMoveToCurrent__(t) catch unreachable;
            }
        }
    // # __AppEditorViewsFind_drawEditedLine__
        fn __AppEditorViewsFind_drawEditedLine__(t: *c.__AppEditorViewsFind__) !void {
            c.__Terminal_resetColors__(&c.__app__.terminal);
            
            if (t.line.text_len > 0) {
                const text = t.line.text[0 .. t.line.text_len];
                // draw left-to-right from first visible rune
                c.__Terminal_moveCursorToStartOfLine__(&c.__app__.terminal);
                var pos: usize = t.symbol - t.offset.x;
                var offset_x: usize = 0;
                // left arrow
                if (pos > 0) { // draw '<'
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_arrows__, c.__AppEditorTheme_arrows__.len);
                    _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "<");
                    pos += 1;
                    offset_x += 1;
                }
                // left symbols
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_current__, c.__AppEditorTheme_current__.len);
                while (true) {
                    if (offset_x >= t.offset.x) break;
                    if (offset_x >= c.__app__.terminal.output.size.x - 1) break;
                    if (pos >= text.len) break;
                    c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[pos], 1);
                    pos += 1;
                    offset_x += 1;
                }
                // current symbol. maybe inverse cursour?
                if (offset_x < c.__app__.terminal.output.size.x - 2) {
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_current_rune__, c.__AppEditorTheme_current_rune__.len);
                    if (pos < text.len) {
                        c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[pos], 1);
                    }
                    pos += 1;
                    offset_x += 1;
                    // right symbols
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_current__, c.__AppEditorTheme_current__.len);
                    while (true) {
                        if (offset_x >= c.__app__.terminal.output.size.x - 2) break;
                        if (pos >= text.len) break;
                        c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[pos], 1);
                        pos += 1;
                        offset_x += 1;
                    }
                    // right arrow
                    if (pos < text.len) { // draw '>'
                        c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_arrows__, c.__AppEditorTheme_arrows__.len);
                        _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, ">");
                    } else {
                        _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
                    }
                }
            } else {
                c.__Console_clearLine__(&c.__app__.console);
            }
            
        }
    // # __AppEditorViewsFind_draw__
        fn __AppEditorViewsFind_draw__(t: *c.__AppEditorViewsFind__) !void {
            defer __AppEditorViewsFind_cursorMoveToCurrent__(t) catch {};
            
            __AppEditorViewsFind_correctOffset__(t);
            if (t.offset.x >= c.__app__.terminal.output.size.x) t.offset.x = 0;
            if (t.offset.y >= c.__app__.terminal.output.size.y) t.offset.y = 0;
            if (t.symbol < t.offset.x) { // unexpected
                t.offset.x = 0;
                t.symbol = 0;
            }
            
            c.__ConsoleOutput_cursorHide__(&c.__app__.console.output);
            defer c.__Console_showCursor__(&c.__app__.console);
    
            t.offset.y = 1;
            { // draw banner
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, 0);
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_headers__, c.__AppEditorTheme_headers__.len);
                _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "text for find:");
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
            }
            { // draw edit line
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, 1);
                try __AppEditorViewsFind_drawEditedLine__(t);
            }
            var pos_y: usize = 2;
            while (true) { // clear other downer lines
                if (pos_y >= c.__app__.terminal.output.size.y) break;
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                c.__Console_clearLine__(&c.__app__.console);
                pos_y += 1;
            }
        }
    // # __AppEditorViewsFind_find__
        fn __AppEditorViewsFind_find__(t: *c.__AppEditorViewsFind__) !void {
            t.context_vtable.*.setAsView.?(t.context);
        }
    // # __AppEditorViewsFind_getModel__
        fn __AppEditorViewsFind_getModel__(ptr: *anyopaque) callconv(.c) *c.__AppEditorViewsFind__ {
            return @alignCast(@ptrCast(ptr));
        }
    // # __AppEditorViewsFind_get__
        fn __AppEditorViewsFind_get__(t: *c.__AppEditorViewsFind__) ?[]const u8 {
            if (t.*.line.text_len > 0) {
                return t.*.line.text[0..t.*.line.text_len];
            }
            return null;
        }
    // # __AppEditorViewsFind_goToEndOfLine__
        fn goToEndOfLine(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            t.symbol = t.line.text_len;
            if (t.symbol > c.__app__.terminal.output.size.x - 2) {
                t.offset.x = c.__app__.terminal.output.size.x - 2;
            } else {
                t.offset.x = t.symbol;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_goToNextSymbol__
        fn __AppEditorViewsFind_goToNextSymbol__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            const used = t.line.text_len;
            if (t.symbol >= used) {
                if (true) return;
                if (t.line.next) |_| {
                    t.goToNextLine();
                    t.goToStartOfText();
                }
                return;
            }
            if (t.symbol < c.__AppEditorLineLen_max__ - 1) t.symbol += 1;
            if (used - t.symbol >= 10) {
                if (t.offset.x < c.__app__.terminal.output.size.x - 12) t.offset.x += 1;
            } else {
                if (t.offset.x < c.__app__.terminal.output.size.x - 2) t.offset.x += 1;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_goToPrevSymbol__
        fn __AppEditorViewsFind_goToPrevSymbol__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            const used = t.line.text_len;
            if (t.symbol == 0) {
                if (true) return;
                if (t.line.prev) |_| {
                    t.goToPrevLine();
                    t.goToEndOfLine();
                }
                return;
            }
            if (t.symbol > used) {
                t.symbol = used;
                if (used < c.__app__.terminal.output.size.x - 1) t.offset.x = t.line.text_len;
                t.need_redraw = true;
                return;
            }
            if (t.symbol > 0) t.symbol -= 1;
            if (t.symbol >= 10) {
                if (t.offset.x > 10) {
                    t.offset.x -= 1;
                }
            } else {
                if (t.offset.x > 0) t.offset.x -= 1;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_goToStartOfLine__
        fn __AppEditorViewsFind_goToStartOfLine__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            t.symbol = 0;
            t.offset.x = 0;
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_goToStartOfText__
        fn __AppEditorViewsFind_goToStartOfText__(t: *c.__AppEditorViewsFind__) callconv(.c) void {
            if (t.line.text_len > 0) {
                const indent = c.__TextAscii_countIndent__(&t.line.text[0], t.line.text_len, 1);
                __AppEditorViewsFind_goToSymbol__(t, indent);
            } else {
                __AppEditorViewsFind_goToSymbol__(t, 0);
            }
        }
    // # __AppEditorViewsFind_goToSymbol__
        fn __AppEditorViewsFind_goToSymbol__(t: *c.__AppEditorViewsFind__, pos: usize) callconv(.c) void {
            t.symbol = pos;
            if (t.symbol > c.__app__.terminal.output.size.x - 3) {
                t.offset.x = 8;
            } else {
                t.offset.x = t.symbol;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_init__
        fn __AppEditorViewsFind_init__(t: *c.__AppEditorViewsFind__) !void {
            t.offset.x = 0;
            t.offset.y = 3;
            t.need_redraw = true;
            t.symbol = 0;
            c.__AppEditorLine_init__(&t.line);
        }
    // # __AppEditorViewsFind_insertSymbol__
        fn __AppEditorViewsFind_insertSymbol__(t: *c.__AppEditorViewsFind__, rune: u8) !void {
            if (t.symbol > t.line.text_len) __AppEditorViewsFind_goToSymbol__(t, t.line.text_len);
            if (t.line.text_len < c.__AppEditorLineLen_max__) {
                c.__Buffer_push__(&t.line.text[0], &t.line.text_len, t.symbol, rune);
                __AppEditorViewsFind_goToNextSymbol__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFind_onKey__
        fn __AppEditorViewsFind_onKey__(t: *c.__AppEditorViewsFind__, cik: c.__ConsoleAnsiInputKey__) callconv(.c) void {
            __AppEditorViewsFind_onkeyWrap__(t, cik) catch {};
        }
    // # __AppEditorViewsFind_onkeyWrap__
        fn __AppEditorViewsFind_onkeyWrap__(t: *c.__AppEditorViewsFind__, cik: c.__ConsoleAnsiInputKey__) !void {
            switch (cik) {
                c.__ConsoleAnsiInputKey_ctrl_left__    => __AppEditorViewsFind_ctrlLeft__(t),
                c.__ConsoleAnsiInputKey_ctrl_right__   => __AppEditorViewsFind_ctrlRight__(t),
                c.__ConsoleAnsiInputKey_delete__       => __AppEditorViewsFind_deleteSymbol__(t),
                c.__ConsoleAnsiInputKey_shift_delete__ => __AppEditorViewsFind_clearLine__(t),
                c.__ConsoleAnsiInputKey_left__         => __AppEditorViewsFind_goToPrevSymbol__(t),
                c.__ConsoleAnsiInputKey_right__        => __AppEditorViewsFind_goToNextSymbol__(t),
                c.__ConsoleAnsiInputKey_escape__       => try __AppEditorViewsFind_cancel__(t),
                c.__ConsoleAnsiInputKey_ctrl_q__       => try __AppEditorViewsFind_cancel__(t),
                c.__ConsoleAnsiInputKey_back_space__   => try __AppEditorViewsFind_deletePrevSymbol__(t),
                c.__ConsoleAnsiInputKey_ctrl_bs__      => try __AppEditorViewsFind_deletePrevSymbol__(t),
                c.__ConsoleAnsiInputKey_ctrl_j__       => try __AppEditorViewsFind_find__(t),
                c.__ConsoleAnsiInputKey_enter__        => try __AppEditorViewsFind_find__(t),
                c.__ConsoleAnsiInputKey_ctrl_w__       => try __AppEditorViewsFind_deleteWord__(t),
                
                else => {
                    const byte: u8 = @truncate(cik);
                    __AppEditorViewsFind_insertSymbol__(t, byte) catch {};
                },
            }
        }
    // # __AppEditorViewsFind_setAsView__
        fn __AppEditorViewsFind_setAsView__(t: *c.__AppEditorViewsFind__, last_context: *anyopaque, last_vtable: *const c.__AppEditorViewsVTable__) callconv(.c) void {
            t.context        = last_context;
            t.context_vtable = last_vtable;
            
            c.__app__.editor.do_ptr      = @ptrCast(&__AppEditorViewsFind_do__);
            c.__app__.editor.onKey_ptr   = @ptrCast(&__AppEditorViewsFind_onKey__);
            c.__app__.editor.current_ctx = t;
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlatVtable_countLineNum__
        fn __AppEditorViewsFlatVtable_countLineNum__(ctx: *anyopaque) callconv(.c) usize {
            const view: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
            return __AppEditorViewsFlat_countLineNum__(view, view.line);
        }
    // # __AppEditorViewsFlatVtable_getOffsetX__
        fn __AppEditorViewsFlatVtable_getOffsetX__(ctx: *anyopaque) callconv(.c) usize {
            const view: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
            return view.offset.x;
        }
    // # __AppEditorViewsFlatVtable_getOffsetY__
        fn __AppEditorViewsFlatVtable_getOffsetY__(ctx: *anyopaque) callconv(.c) usize {
            const view: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
            return view.offset.y;
        }
    // # __AppEditorViewsFlatVtable_getSymbolPosX__ 
        fn __AppEditorViewsFlatVtable_getSymbolPosX__(ctx: *anyopaque) callconv(.c) usize {
            const view: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
            return view.symbol;
        }
    // # __AppEditorViewsFlatVtable_goToLineFromNumber__
        fn __AppEditorViewsFlatVtable_goToLineFromNumber__(ctx: *anyopaque, _num: usize) callconv(.c) void {
            const view: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
            return __AppEditorViewsFlat_goToLineFromNumber__(view, _num);
        }
    // # __AppEditorViewsFlatVtable_goToNextLine__
        fn __AppEditorViewsFlatVtable_goToNextLine__(ctx: *anyopaque) callconv(.c) void {
            const view: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
            _=__AppEditorViewsFlat_goToNextLine__(view);
        }
    // # __AppEditorViewsFlatVtable_goToPrevLine__
        fn __AppEditorViewsFlatVtable_goToPrevLine__(ctx: *anyopaque) callconv(.c) void {
            const view: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
            _=__AppEditorViewsFlat_goToPrevLine__(view);
        }
    // # __AppEditorViewsFlatVtable_goToSymbolPosX__
        fn __AppEditorViewsFlatVtable_goToSymbolPosX__(ctx: *anyopaque, pos: usize) callconv(.c) void {
            const view: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
            __AppEditorViewsFlat_goToSymbol__(view, pos);
        }
    // # __AppEditorViewsFlatVtable_init__
        fn __AppEditorViewsFlatVtable_init__(t: *c.__AppEditorViewsVTable__) void {
            t.setAsView          = @ptrCast(&__AppEditorViewsFlatVtable_setAsView__);
            t.goToPrevLine       = @ptrCast(&__AppEditorViewsFlatVtable_goToPrevLine__);
            t.goToNextLine       = @ptrCast(&__AppEditorViewsFlatVtable_goToNextLine__);
            t.getOffsetX         = @ptrCast(&__AppEditorViewsFlatVtable_getOffsetX__);
            t.getOffsetY         = @ptrCast(&__AppEditorViewsFlatVtable_getOffsetY__);
            t.goToSymbolPosX     = @ptrCast(&__AppEditorViewsFlatVtable_goToSymbolPosX__);
            t.getSymbolPosX      = @ptrCast(&__AppEditorViewsFlatVtable_getSymbolPosX__);
            t.countLineNum       = @ptrCast(&__AppEditorViewsFlatVtable_countLineNum__);
            t.goToLineFromNumber = @ptrCast(&__AppEditorViewsFlatVtable_goToLineFromNumber__);
        }
    // # __AppEditorViewsFlatVtable_setAsView__
        fn __AppEditorViewsFlatVtable_setAsView__(ctx: *anyopaque) callconv(.c) void {
            const view: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
            __AppEditorViewsFlat_setAsView__(view) catch unreachable;
            c.__app__.editor.current_vtable = &c.__AppEditorViewsVtable_flat__;
        }
    // # __AppEditorViewsFlat_addIndent__
        fn __AppEditorViewsFlat_addIndent__(t: *c.__AppEditorViewsFlat__) !void {
            var text: []u8 = "";
            if (t.line.text_len > 0) text = t.line.text[0 .. t.line.text_len];
            const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
            if (c.__AppEditorLine_setIndent__(t.line, indent + 4) == false) return error.Unexpected;
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_addNextLine__
        fn __AppEditorViewsFlat_addNextLine__(t: *c.__AppEditorViewsFlat__) !void {
            var ok: bool = true;
            var new_line: *c.__AppEditorLine__ = undefined;
            if ( c.__AppEditorLine_alloc__( @ptrCast(&new_line) ) ) {
                c.__AppEditorLine_init__(new_line);
                c.__MemList_pushAfter__(&t.lines, &t.line.*.link, &new_line.link);
                _=__AppEditorViewsFlat_goToNextLine__(t);
                __AppEditorViewsFlat_goToStartOfText__(t);
                t.need_redraw = true;
                
                if (!ok) c.__AppEditorLine_free__(new_line);
            } else {
                ok = false;
            }
            if (!ok) return error.Unexpected;
        }
    // # __AppEditorViewsFlat_addPrevLine__
        fn __AppEditorViewsFlat_addPrevLine__(t: *c.__AppEditorViewsFlat__) !void {
            var ok: bool = true;
            var new_line: *c.__AppEditorLine__ = undefined;
            if ( c.__AppEditorLine_alloc__( @ptrCast(&new_line) ) ) {
                c.__AppEditorLine_init__(new_line);
                c.__MemList_pushBefore__(&t.lines, &t.line.*.link, &new_line.link);
                _=__AppEditorViewsFlat_goToPrevLine__(t);
                __AppEditorViewsFlat_goToStartOfText__(t);
                t.need_redraw = true;
                
                if (!ok) c.__AppEditorLine_free__(new_line);
            } else {
                ok = false;
            }
            
            if (!ok) return error.Unexpected;
        }
    // # __AppEditorViewsFlat_bakupTextOnCurrentLine__
        fn __AppEditorViewsFlat_bakupTextOnCurrentLine__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            if (t.line.*.text_len > 0) {
                t.bakup_line.text_len = t.line.*.text_len;
                c.__Mem_copy__(&t.bakup_line.text[0], &t.line.*.text[0], t.line.*.text_len);
            }
        }
    // # __AppEditorViewsFlat_changeOffsetX__
        fn __AppEditorViewsFlat_changeOffsetX__(t: *c.__AppEditorViewsFlat__, pos: usize) callconv(.c) void {
            t.offset.x = pos;
            __AppEditorViewsFlat_correctOffsetX__(t);
        }
    // # __AppEditorViewsFlat_clearLine__
        fn __AppEditorViewsFlat_clearLine__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            t.line.*.text_len = 0;
            __AppEditorViewsFlat_goToStartOfText__(t);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_copyDownIntervals__
        fn __AppEditorViewsFlat_copyDownIntervals__(t: *c.__AppEditorViewsFlat__) !void {
            const next_line_link: *c.__MemListLink__ = t.line.*.link.next orelse return;
            const next_line: *c.__AppEditorLine__ = @fieldParentPtr("link", next_line_link);
            
            try t.copyIntervalsAfterDC(next_line);
            try t.copyIntervalsBeforeEQ(next_line);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_copyUpIntervals__
        fn __AppEditorViewsFlat_copyUpIntervals__(t: *c.__AppEditorViewsFlat__) !void {
            const prev_line_link: *c.__MemListLink__ = t.line.*.link.prev orelse return;
            const prev_line: *c.__AppEditorLine__ = @fieldParentPtr("link", prev_line_link);
            
            try t.copyIntervalsAfterDC(prev_line);
            try t.copyIntervalsBeforeEQ(prev_line);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_copyWordToFind__
        fn __AppEditorViewsFlat_copyWordToFind__(t: *c.__AppEditorViewsFlat__) !void {
            const line = t.line;
            if (line.*.text_len > 0) {
                const text = t.line.*.text[0 .. t.line.*.text_len];
                if (t.symbol < line.*.text_len) {
                    const sow: usize = blk: { // start_of_word
                        var pos: usize = t.symbol;
                        while (true) {
                            if (pos == 0) break;
                            const prev_symbol = text[pos - 1];
                            if (c.__TextAscii_isLetter__(prev_symbol) == false) break;
                            pos -= 1;
                        }
                        break :blk pos;
                    };
                    const eow: usize = blk: { // end_of_word
                        var pos: usize = t.symbol;
                        while (true) {
                            if (pos >= t.line.*.text_len - 1) {
                                break;
                            }
                            const next_symbol = text[pos + 1];
                            if (c.__TextAscii_isLetter__(next_symbol) == false) break;
                            pos += 1;
                        }
                        break :blk pos;
                    };
                    const word = text[sow .. eow + 1];
                    { // copy to find_line
                        // current word cannot be bigger than __AppEditorLineLen_max__, but when lines size be dynamic allocated then need recheck
                        const find_line: *c.__AppEditorLine__ = &c.__app__.editor.views.find.line;
                        find_line.text_len = word.len;
                        c.__Mem_copy__(&find_line.text[0], word.ptr, word.len);
                    }
                    __AppEditor_changeStatus__("word copied");
                } else {
                    __AppEditor_changeStatus__("cursor not an word");
                }
            }
        }
    // # __AppEditorViewsFlat_correctOffsetX__
        fn __AppEditorViewsFlat_correctOffsetX__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            const tsx = c.__app__.terminal.output.size.x;
            if (t.offset.x >= tsx) t.offset.x = 0;
            
            const predel = (tsx >> 1) - (tsx >> 4);
            if (t.symbol >= predel) t.offset.x = predel;
        }
    // # __AppEditorViewsFlat_correctOffsetY__
        fn __AppEditorViewsFlat_correctOffsetY__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            // { correct offset_y:
            const tsy = c.__app__.terminal.output.size.y;
            if (t.offset.y >= tsy) t.offset.y = 0;
            if (tsy <= 5) return;
            
            // count downest_lines
            var count_to_downest_line: usize = 0;
            var line: *c.__MemListLink__ = &t.line.*.link;
            while (count_to_downest_line < 5) {
                if (line.next) |down_next| {
                    count_to_downest_line += 1;
                    line = down_next;
                } else {
                    break;
                }
            }
            
            if (tsy - t.offset.y < count_to_downest_line) {
                t.offset.y = tsy - count_to_downest_line;
            }
            //}
        }
    // # __AppEditorViewsFlat_countLineNum__
        fn __AppEditorViewsFlat_countLineNum__(t: *c.__AppEditorViewsFlat__, line: *c.__AppEditorLine__) callconv(.c) usize {
            _ = t;
            var pos: usize = 1;
            var link: [*c]c.__MemListLink__ = &line.link;
            while (c.__MemListLink_isFirst__(link) == false) { // todo just use while prev
                pos += 1;
                link = link.*.prev;
            }
            return pos;
        }
    // # __AppEditorViewsFlat_ctrlDown__
        fn __AppEditorViewsFlat_ctrlDown__ (t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            var last_text: []const u8 = "";
            if (t.line.*.text_len > 0) last_text = t.line.*.text[0 .. t.line.*.text_len];
            const last_indent = c.__TextAscii_countIndent__(last_text.ptr, last_text.len, 1);
            while(__AppEditorViewsFlat_goToNextLine__(t)) {
                var new_text: []u8 = "";
                if (t.line.*.text_len > 0) new_text = t.line.*.text[0 .. t.line.*.text_len];
                const new_indent = c.__TextAscii_countIndent__(new_text.ptr, new_text.len, 1);
                if (true // line not empty and indent <= last_indent
                    // line not empty
                        and new_text.len > new_indent 
                        and c.__TextAscii_isVisible__(new_text[new_indent])
                    and new_indent <= last_indent
                ) {
                    break;
                }
            }
        }
    // # __AppEditorViewsFlat_ctrlLeft__
        fn __AppEditorViewsFlat_ctrlLeft__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            __AppEditorViewsFlat_goToPrevSymbol__(t);
            if (t.symbol > 0) {
                const line: *c.__AppEditorLine__  = t.line;
                if (line.text_len > 0) {
                    const text:   []u8  = line.text[0 .. t.symbol];
                    const spaces: usize = c.__TextAscii_countIndentReverse__(text.ptr, text.len, 1);
                    var dest_pos: usize = 0;
                    if (spaces > 0) {
                        dest_pos = t.symbol - spaces;
                    } else {
                        dest_pos = c.__TextAscii_findBreakOfWordReverse__(text.ptr, text.len);
                        if (dest_pos > 0) dest_pos += 1;
                    }
                    __AppEditorViewsFlat_goToSymbol__(t, dest_pos);
                } else {
                    __AppEditorViewsFlat_goToSymbol__(t, 0);
                }
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_ctrlRight__
        fn __AppEditorViewsFlat_ctrlRight__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            __AppEditorViewsFlat_goToNextSymbol__(t);
            if (t.line.*.text_len > 0) {
                const full_text = t.line.*.text[0 .. t.line.*.text_len];
                if (t.symbol >= full_text.len) return;
                const text = full_text[t.symbol..];
                const spaces = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                if (spaces > 0) {
                    __AppEditorViewsFlat_goToSymbol__(t, t.symbol + spaces);
                    t.need_redraw = true;
                    return;
                }
                const dest_pos = c.__TextAscii_findBreakOfWord__(text.ptr, text.len) + t.symbol;
                __AppEditorViewsFlat_goToSymbol__(t, dest_pos);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_ctrlShiftLeft__
        fn __AppEditorViewsFlat_ctrlShiftLeft__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            var text: []u8 = "";
            if (t.line.*.text_len > 0) {
                text = t.line.*.text[0 .. t.line.*.text_len];
                const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                if (t.symbol > indent) {
                    __AppEditorViewsFlat_goToSymbol__(t, indent);
                } else {
                    __AppEditorViewsFlat_goToStartOfLine__(t);
                }
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_ctrlShiftRight__
        fn __AppEditorViewsFlat_ctrlShiftRight__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            var text: []u8  = "";
            if (t.line.*.text_len > 0) {text = t.line.*.text[0 .. t.line.*.text_len];}
            const indent: usize = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
            if (t.symbol < indent) __AppEditorViewsFlat_goToSymbol__(t, indent) else __AppEditorViewsFlat_goToEndOfLine__(t);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_ctrlUp__
        fn __AppEditorViewsFlat_ctrlUp__ (t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            var last_text: []u8 = "";
            if (t.line.*.text_len > 0) last_text = t.line.*.text[0 .. t.line.*.text_len];
            const last_indent = c.__TextAscii_countIndent__(last_text.ptr, last_text.len, 1);
            while(__AppEditorViewsFlat_goToPrevLine__(t)) {
                var new_text: []u8 = "";
                if (t.line.*.text_len > 0) new_text = t.line.*.text[0 .. t.line.*.text_len];
                const new_indent = c.__TextAscii_countIndent__(new_text.ptr, new_text.len, 1);
                if (true // line not empty and indent <= last_indent
                    // line not empty
                        and new_text.len > new_indent 
                        and c.__TextAscii_isVisible__(new_text[new_indent])
                    // 
                        and new_indent <= last_indent
                ) {
                    break;
                }
            }
        }
    // # __AppEditorViewsFlat_ctrl_t__
        fn __AppEditorViewsFlat_ctrl_t__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            const text = "__scalpi__.__print__(__TRACE__(), )";
            for (text) |symbol| {
                __AppEditorViewsFlat_insertSymbol__(t, symbol) catch {};
            }
            __AppEditorViewsFlat_goToPrevSymbol__(t);
        }
    // # __AppEditorViewsFlat_cursorMoveToCurrent__
        fn __AppEditorViewsFlat_cursorMoveToCurrent__(t: *c.__AppEditorViewsFlat__) !void {
            c.__Terminal_cursorMove__(&c.__app__.terminal, t.offset.x, t.offset.y);
        }
    // # __AppEditorViewsFlat_cutLine__
        fn __AppEditorViewsFlat_cutLine__(t: *c.__AppEditorViewsFlat__) !void {
            var ok: bool = true;
            const current_link = &t.line.*.link;
            var next_link: *c.__MemListLink__ = undefined;
            if (current_link.next) |_next_link| {
                next_link = _next_link;
            } else if (current_link.prev) |prev_link| {
                next_link = prev_link;
            } else {
                // create prev line
                var new_empty_line: *c.__AppEditorLine__ = undefined;
                if ( c.__AppEditorLine_alloc__( @ptrCast(&new_empty_line) ) ) {
                    c.__AppEditorLine_init__(new_empty_line);
                    c.__MemList_pushFirst__(&t.lines, &new_empty_line.link); {
                        next_link = &new_empty_line.link;
                        if (!ok) c.__MemList_pop__(&t.lines, &new_empty_line.link);
                    }
                    
                    if (!ok) c.__AppEditorLine_free__(new_empty_line);
                } else {
                    ok = false;
                }
            }
            
            if (ok) {
                // move to cut
                c.__MemList_pop__(&t.lines, current_link);
                c.__MemList_pushLast__(&t.cutted, current_link);
                
                // update screen
                const line: *c.__AppEditorLine__ = @fieldParentPtr("link", next_link);
                t.line = line;
                t.need_redraw = true;
                __AppEditorViewsFlat_bakupTextOnCurrentLine__(t);
            }
            
            if (!ok) return error.Unexpected;
        }
    // # __AppEditorViewsFlat_deleteCutted__
        fn __AppEditorViewsFlat_deleteCutted__(t: *c.__AppEditorViewsFlat__) !void {
            while (t.cutted.count > 0) {
                const link: *c.__MemListLink__ = t.cutted.first orelse unreachable;
                c.__MemList_pop__(&t.cutted, link);
                const line: *c.__AppEditorLine__ = @fieldParentPtr("link", link);
                c.__AppEditorLine_free__(line);
            }
            __AppEditor_changeStatus__("cutted lines is gone :)");
            __AppEditorViewsFlat_cursorMoveToCurrent__(t) catch {};
        }
    // # __AppEditorViewsFlat_deleteIndent__
        fn __AppEditorViewsFlat_deleteIndent__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            _=c.__AppEditorLine_setIndent__(t.line, 0);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_deletePrevSymbol__
        fn __AppEditorViewsFlat_deletePrevSymbol__(t: *c.__AppEditorViewsFlat__) !void {
            __AppEditorViewsFlat_goToPrevSymbol__(t);
            if (t.line.*.text_len > t.symbol) {
                __AppEditorViewsFlat_deleteSymbol__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_deleteSymbol__
        fn __AppEditorViewsFlat_deleteSymbol__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            if (t.line.*.text_len == 0) return;
            
            if (c.__Buffer_pop_check__(t.line.*.text_len, t.symbol)) {
                _=c.__Buffer_pop__(&t.line.*.text[0], &t.line.*.text_len, t.symbol);
            }
            
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_deleteWord__
        fn __AppEditorViewsFlat_deleteWord__(t: *c.__AppEditorViewsFlat__) !void {
            if (t.symbol > t.line.*.text_len) {
                return;
            }
            while (true) { // delete current symbol
                if (t.symbol == t.line.*.text_len) {
                    break;
                }
                const next_symbol = t.line.*.text[t.symbol];
                if (c.__TextAscii_isLetter__(next_symbol)) {
                    __AppEditorViewsFlat_deleteSymbol__(t);
                } else {
                    break;
                }
            }
            while (true) { // delete prev    symbol
                if (t.symbol == 0) {
                    break;
                }
                const prev_symbol = t.line.*.text[t.symbol - 1];
                if (c.__TextAscii_isLetter__(prev_symbol)) {
                    try __AppEditorViewsFlat_deletePrevSymbol__(t);
                } else {
                    break;
                }
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_divideLine__
        fn __AppEditorViewsFlat_divideLine__(t: *c.__AppEditorViewsFlat__) !void {
            if (t.line.*.text_len > 0) {
                const current_text: []u8 = t.line.*.text[0 .. t.line.*.text_len];
                const indent = c.__TextAscii_countIndent__(current_text.ptr, current_text.len, 1);
                if (t.symbol <= indent) { // just add prev line
                    const last_symbol = t.symbol;
                    const last_offset = t.offset.x;
                    try __AppEditorViewsFlat_addPrevLine__(t);
                    
                    // copy indent
                        for (t.line.*.text[0..indent], current_text[0..indent])  
                            |*rune, indent_symbol|
                            rune.* = indent_symbol
                        ;
                        t.line.*.text_len = indent;
                    
                    t.symbol = last_symbol;
                    t.offset.x = last_offset;
                } else if (t.symbol >= t.line.*.text_len) {
                    try __AppEditorViewsFlat_addNextLine__(t);
                    
                    // copy indent
                        if (t.__AppEditorViewsFlat_autoSpace__) {
                            for (t.line.*.text[0..indent], current_text[0..indent]) |*rune, indent_symbol| rune.* = indent_symbol;
                            t.line.*.text_len = indent;
                        }
                
                } else { // separate text to 2 line
                    const parent    = t.line;
                    const pos       = t.symbol;
                    const copy_text = current_text[pos..];
                    try __AppEditorViewsFlat_addNextLine__(t);
                    t.line.*.text_len = indent + current_text.len;
                    
                    // copy indent
                        if (t.__AppEditorViewsFlat_autoSpace__) {
                            for (t.line.*.text[0..indent], current_text[0..indent]) |*rune, indent_symbol| rune.* = indent_symbol;
                            t.line.*.text_len = indent;
                            std.mem.copyForwards(u8, t.line.*.text[indent..], copy_text);
                            parent.*.text_len = pos;
                            t.line.*.text_len = indent + copy_text.len;
                        } else {
                            std.mem.copyForwards(u8, t.line.*.text[0..], copy_text);
                            parent.*.text_len = pos;
                            t.line.*.text_len = copy_text.len;
                        }
                }
            } else {
                try __AppEditorViewsFlat_addNextLine__(t);
            }
            __AppEditorViewsFlat_goToStartOfText__(t);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_do__ 
        fn __AppEditorViewsFlat_do__(ctx: *anyopaque) callconv(.c) void {
            var ok: bool = true;
                const t: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
                
                if (t.need_redraw) {
                    t.need_redraw = false;
                    if (__AppEditorViewsFlat_draw__(t)) {
                        if (__AppEditorViewsFlat_cursorMoveToCurrent__(t)) {
                        } else  |_| {
                            ok = false;
                        }
                    } else |_| {
                        ok = false;
                    }
                }
                
                if (t.need_draw_line_num) {
                    t.need_draw_line_num = false;
                    if (__AppEditorViewsFlat_drawCountLineNum__(t)) {
                        if (__AppEditorViewsFlat_cursorMoveToCurrent__(t)) {
                        } else |_| {
                            ok = false;
                        }
                    } else |_| {
                        ok = false;
                    }
                }
            if (!ok) unreachable;
            //return ok;
        }
    // # __AppEditorViewsFlat_drawCountLineNum__
        fn __AppEditorViewsFlat_drawCountLineNum__(t: *c.__AppEditorViewsFlat__) !void {
            const pos: usize = __AppEditorViewsFlat_countLineNum__(t, t.line);
            
            c.__Terminal_cursorMove__(&c.__app__.terminal, 0, c.__app__.terminal.output.size.y - 1);
            c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_notification__, c.__AppEditorTheme_notification__.len);
            
            //print("line number = {pos}");
                _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, " line number = ");
                _=c.__Text_formatU64__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, pos, 1);
            
            c.__Terminal_resetColors__(&c.__app__.terminal);
            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
            try __AppEditorViewsFlat_cursorMoveToCurrent__(t);
            t.need_redraw = false;
        }
    // # __AppEditorViewsFlat_drawDownerLines__
        fn __AppEditorViewsFlat_drawDownerLines__(t: *c.__AppEditorViewsFlat__) !void {
            // change color
            c.__Terminal_resetColors__(&c.__app__.terminal);
            
            var pos_y: usize = t.offset.y + 1;
            c.__app__.editor.lines_drawing = pos_y;
            if (pos_y >= c.__app__.terminal.output.size.y) return;
            var link = &t.line.*.link;
            while (true) { // draw
                link = link.next orelse break;
                const line: *c.__AppEditorLine__ = @fieldParentPtr("link", link);
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                try __AppEditorViewsFlat_drawLine__(t, line);
                if (pos_y >= c.__app__.terminal.output.size.y - 1) {
                    c.__app__.editor.lines_drawing = c.__app__.terminal.output.size.y;
                    return;
                }
                pos_y += 1;
            }
            c.__app__.editor.lines_drawing = pos_y;
            c.__Terminal_resetColors__(&c.__app__.terminal);
            while (true) { // clear other downer lines
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                c.__Console_clearLine__(&c.__app__.console);
                if (pos_y >= c.__app__.terminal.output.size.y - 1) return;
                pos_y += 1;
            }
        }
    // # __AppEditorViewsFlat_drawEditedLine__
        fn __AppEditorViewsFlat_drawEditedLine__(t: *c.__AppEditorViewsFlat__) !void {
            c.__Terminal_cursorMove__(&c.__app__.terminal, 0, t.offset.y);
            
            if (t.line.*.text_len > 0) {
                const text = t.line.*.text[0 .. t.line.*.text_len];
                try __AppEditorViewsFlat_drawLine__(t, t.line);
                
                const screen_start: usize = t.symbol - t.offset.x; // first visible rune
                const screen_end: usize = screen_start + c.__app__.terminal.output.size.x;
                
                // draw left arrow '<'
                    if (screen_start > 0) {
                        c.__Terminal_cursorMove__(&c.__app__.terminal, 0, t.offset.y);
                        c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_arrows__, c.__AppEditorTheme_arrows__.len);
                        _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "<");
                    }
                    
                // draw right arrow '>'
                    if (screen_end < text.len) {
                        c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_arrows__, c.__AppEditorTheme_arrows__.len);
                        c.__Terminal_cursorMove__(&c.__app__.terminal, c.__app__.terminal.output.size.x - 1, t.offset.y);
                        _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, ">");
                    }
                    
                // redraw current symbol
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_current_rune__, c.__AppEditorTheme_current_rune__.len);
                    c.__Terminal_cursorMove__(&c.__app__.terminal, t.offset.x, t.offset.y);
                    if (t.symbol < text.len) {
                        c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[t.symbol], 1);
                    } else {
                        c.__Terminal_writeToOutput__(&c.__app__.terminal, "#", 1);
                    }
            } else {
                c.__Terminal_resetColors__(&c.__app__.terminal);
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_line__, 0);
            }
        }
    // # __AppEditorViewsFlat_drawLine__
        fn __AppEditorViewsFlat_drawLine__(t: *c.__AppEditorViewsFlat__, line: *c.__AppEditorLine__) !void {
            c.__Terminal_moveCursorToStartOfLine__(&c.__app__.terminal);
            if (line.text_len > 0) {
                const text = line.text[0 .. line.text_len];
                // draw left-to-right from first visible rune
                const screen_start: usize = t.symbol - t.offset.x; // first visible rune
                const screen_end:   usize = screen_start + c.__app__.terminal.output.size.x;
                if (text.len > screen_start) {
                    c.__Terminal_resetColors__(&c.__app__.terminal);
                    var visible_text_ptr: [*c]const u8 = undefined; _=&visible_text_ptr;
                    var visible_text_len: usize = undefined; _=&visible_text_len;
                    if (c.__TextAscii_getNonIndent__(&visible_text_ptr, &visible_text_len, text.ptr, text.len)) {
                        const visible_text: []const u8 = visible_text_ptr[0..visible_text_len];
                        var is_comment: u8 = 0; // 0 - false, 1 - commentary, 2 - disabled commentary
                            if (false // comment with space
                                or std.mem.startsWith(u8, visible_text, "# ")
                                or std.mem.startsWith(u8, visible_text, "// ")
                                or std.mem.startsWith(u8, visible_text, "; ")
                                or std.mem.startsWith(u8, visible_text, "-- ")
                            ) { // is commentary
                                is_comment = 1;
                            } else if (false // commant without space
                                or std.mem.startsWith(u8, visible_text, "#")
                                or std.mem.startsWith(u8, visible_text, "//")
                                or std.mem.startsWith(u8, visible_text, ";")
                                or std.mem.startsWith(u8, visible_text, "--")
                            ) { // is disabled commentary
                                is_comment = 2;
                            }
                        // draw
                            var text_end: usize = text.len;
                            if (text.len > screen_end) text_end = screen_end;
                            const draw_len = text_end - screen_start;
                            
                            if (is_comment == 2) {
                                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_disabled__, c.__AppEditorTheme_disabled__.len);
                                const draw_ptr = &text[screen_start];
                                c.__Terminal_writeToOutput__(&c.__app__.terminal, draw_ptr, draw_len);
                            } else if (is_comment == 1) {
                                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_commentary__, c.__AppEditorTheme_commentary__.len);
                                const draw_ptr = &text[screen_start];
                                c.__Terminal_writeToOutput__(&c.__app__.terminal, draw_ptr, draw_len);
                            } else { // coloring ^_^
                                var color: [5]u8 = "\x1B[90m".*;
                                var last_pos:  usize = 0;
                                var pos:       usize = 0;
                                var hash_summ: u8    = 0;
                                var last_symbol_is_word: bool = false;
                                while (pos < draw_len) {
                                    const symbol: u8 = text[screen_start + pos];
                                    if (c.__TextAsciiSymbol_isWordSymbol__(symbol)) {
                                        if (last_symbol_is_word == false) {
                                            last_symbol_is_word = true;
                                            
                                            color[3] = '0' + ((hash_summ & 0b111));
                                            c.__Terminal_setFontStyle__(&c.__app__.terminal, &color[0], color.len);
                                            c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[screen_start + last_pos], pos - last_pos);
                                            last_pos  = pos;
                                            hash_summ = 0;
                                        }
                                        
                                        hash_summ +%= symbol;
                                        pos += 1;
                                    } else {
                                        color[3] = '0' + ((hash_summ & 0b111));
                                        c.__Terminal_setFontStyle__(&c.__app__.terminal, &color[0], color.len);
                                        c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[screen_start + last_pos], pos - last_pos);
                                        last_pos  = pos;
                                        
                                        hash_summ = symbol;
                                        pos += 1;
                                        
                                        if (false) { // spaces
                                            if (symbol == ' ') {
                                                while(pos < draw_len-1) {
                                                    if (text[screen_start + pos+1] != ' ') {
                                                        break;
                                                    }
                                                    pos += 1;
                                                }
                                            }
                                            c.__Terminal_setFontStyle__(&c.__app__.terminal, &color[0], color.len);
                                            c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[screen_start + last_pos], pos - last_pos);
                                            last_pos = pos;
                                        }
                                        last_symbol_is_word = false;
                                    }
                                }
                                if (last_pos < draw_len) {
                                    color[3] = '0' + (hash_summ & 0b111);
                                    c.__Terminal_setFontStyle__(&c.__app__.terminal, &color[0], color.len);
                                    c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[screen_start + last_pos], draw_len - last_pos);
                                }
                            }
                    }
                }
            }
            
            // clear other line space
            c.__Terminal_resetColors__(&c.__app__.terminal);
            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
        }
    // # __AppEditorViewsFlat_drawUpperLines__
        fn __AppEditorViewsFlat_drawUpperLines__(t: *c.__AppEditorViewsFlat__) !void {
            // change color
            c.__Terminal_resetColors__(&c.__app__.terminal);
            
            if (t.offset.y == 0) return;
            var pos_y: usize = t.offset.y - 1;
            var link = &t.line.*.link;
            while (true) { // draw
                link = link.prev orelse break;
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                const line: *c.__AppEditorLine__ = @fieldParentPtr("link", link);
                try __AppEditorViewsFlat_drawLine__(t, line);
                if (pos_y == 0) return;
                pos_y -= 1;
            }
            
            c.__Terminal_resetColors__(&c.__app__.terminal);
            while (true) { // clear other upp lines
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                c.__Console_clearLine__(&c.__app__.console);
                if (pos_y == 0) return;
                pos_y -= 1;
            }
        }
    // # __AppEditorViewsFlat_draw__
        fn __AppEditorViewsFlat_draw__(t: *c.__AppEditorViewsFlat__) !void {
            defer __AppEditorViewsFlat_cursorMoveToCurrent__(t) catch {};
            
            __AppEditorViewsFlat_correctOffsetX__(t);
            __AppEditorViewsFlat_correctOffsetY__(t);
            c.__ConsoleOutput_cursorHide__(&c.__app__.console.output);
            defer c.__Console_showCursor__(&c.__app__.console);
            
            // draw edit line
            try __AppEditorViewsFlat_drawEditedLine__(t);
            
            // draw other lines
            if (c.__app__.terminal.output.size.y <= 1) return;
            try __AppEditorViewsFlat_drawUpperLines__(t);
            try __AppEditorViewsFlat_drawDownerLines__(t);
        }
    // # __AppEditorViewsFlat_duplicateLineAndCut__
        fn __AppEditorViewsFlat_duplicateLineAndCut__(t: *c.__AppEditorViewsFlat__) !void {
            try __AppEditorViewsFlat_duplicateLine__(t);
            try __AppEditorViewsFlat_cutLine__(t);
            __AppEditor_changeStatus__("copied.");
            __AppEditorViewsFlat_cursorMoveToCurrent__(t) catch {};
        }
    // # __AppEditorViewsFlat_duplicateLine__
        fn __AppEditorViewsFlat_duplicateLine__(t: *c.__AppEditorViewsFlat__) !void {
            var ok: bool = true;
            var copy: *c.__AppEditorLine__ = undefined;
            if ( c.__AppEditorLine_alloc__( @ptrCast(&copy) ) ) {
                c.__AppEditorLine_init__(copy);
                copy.text_len = t.line.*.text_len;
                if (t.line.*.text_len > 0) c.__Mem_copy__(&copy.text[0], &t.line.*.text[0], t.line.*.text_len);
                c.__MemList_pushAfter__(&t.lines, &t.line.*.link, &copy.link);
                t.line = copy;
                t.need_redraw = true;
                
                if (!ok) c.__AppEditorLine_free__(copy);
            } else {
                ok = false;
            }
            if (!ok) return error.Unexpected;
        }
    // # __AppEditorViewsFlat_easyMotionH__
        fn __AppEditorViewsFlat_easyMotionH__(t: *c.__AppEditorViewsFlat__) !void {
            __AppEditorViewsEasyMotionHorizontal_setAsView__(t, &c.__AppEditorViewsVtable_flat__);
        }
    // # __AppEditorViewsFlat_easyMotionV__
        fn __AppEditorViewsFlat_easyMotionV__(t: *c.__AppEditorViewsFlat__) !void {
            __AppEditorViewsEasyMotionVertical_setAsView__(t, &c.__AppEditorViewsVtable_flat__);
        }
    // # __AppEditorViewsFlat_enterToBlock__   
        fn __AppEditorViewsFlat_enterToBlock__ (t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            var last_text: []u8 = "";
            if (t.line.*.text_len > 0) last_text = t.line.*.text[0 .. t.line.*.text_len];
            const last_indent = c.__TextAscii_countIndent__(last_text.ptr, last_text.len, 1);
            while(__AppEditorViewsFlat_goToNextLine__(t)) {
                var new_text: []u8 = "";
                if (t.line.*.text_len > 0) new_text = t.line.*.text[0 .. t.line.*.text_len];
                const new_indent = c.__TextAscii_countIndent__(new_text.ptr, new_text.len, 1);
                if ( true
                    // line not empty
                        and new_text.len > new_indent 
                        and c.__TextAscii_isVisible__(new_text[new_indent])
                    and new_indent != last_indent
                ) {
                    break;
                }
            }
            __AppEditorViewsFlat_moveCursorToStartOfLine__(t);
        }
    // # __AppEditorViewsFlat_externalCopy__
        fn __AppEditorViewsFlat_externalCopy__(t: *c.__AppEditorViewsFlat__) !bool {
            const path        = &c.__app__.editor.__AppEditor_pathToClipboard__[0];
            const path_len    = c.__app__.editor.__AppEditor_pathToClipboard_len__;
            
            var ok: bool = true;
                if (t.cutted.count == 0) {
                    try __AppEditorViewsFlat_duplicateLine__(t);
                    try __AppEditorViewsFlat_cutLine__(t);
                }
                __AppEditor_changeStatus__("saving ...");
                if (c.__AppEditorListOfLine_writeToFile__( &t.cutted, path, path_len ) ) {
                    // print "saved to {clipboard}"
                        var buffer: [1024]u8 = undefined;
                        var writed: usize    = 0;
                        writed += __zig_writeToBuffer__(&buffer[writed], "clipboard saved to ");
                        c.__Mem_copy__(&buffer[writed], path, path_len);
                            writed += path_len;
                        __AppEditor_changeStatus__(buffer[0..writed]);
                } else {
                    ok = false;
                    // print "NOT saved to {clipboard}"
                        var buffer: [1024]u8 = undefined;
                        var writed: usize    = 0;
                        writed += __zig_writeToBuffer__(&buffer[writed], "clipboard NOT saved to ");
                        c.__Mem_copy__(&buffer[writed], path, path_len);
                            writed += path_len;
                        __AppEditor_changeStatus__(buffer[0..writed]);
                }
                
                t.need_redraw = false;
            return ok;
        }
    // # __AppEditorViewsFlat_externalPaste__
        fn __AppEditorViewsFlat_externalPaste__(t: *c.__AppEditorViewsFlat__) !void {
            t.__AppEditorViewsFlat_autoSpace__ = false;
            var ok: bool = true;
                // read file
                const path     = c.__app__.editor.__AppEditor_pathToClipboard__;
                const path_len = c.__app__.editor.__AppEditor_pathToClipboard_len__;
                var file: c.__OsFileHandle__ = undefined;
                if (c.__OsFile_open__(&file, &path[0], path_len)) {
                    const file_size: usize = c.__OsFile_getSize__(file);
                    var file_data: [*]u8 = undefined;
                    if (c.__OsMem_allocAny__(&file_data, file_size)) {
                        if (c.__OsFile_readToBuffer__(file, file_data, file_size, 0)) {
                            // paste
                            const line = t.line;
                            try __AppEditorViewsFlat_addPrevLine__(t);
                            for (file_data[0..file_size]) |rune| { // parse lines
                                switch (rune) {
                                    13 => {},
                                    10 => { 
                                        try __AppEditorViewsFlat_addNextLine__(t);
                                    },
                                    else => {
                                        try __AppEditorViewsFlat_insertSymbol__(t, rune);
                                    },
                                }
                                if (!ok) break;
                            }
                            if (ok) {
                                t.line = line;
                                t.need_redraw = true;
                            }
                        } else {
                            ok = false;
                        }
                        
                        c.__OsMem_freeAny__(file_data);
                    } else {
                        ok = false;
                    }
                } else {
                    ok = false;
                }
            if (!ok) { // print error
                c.__Terminal_resetColors__(&c.__app__.terminal);
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_notification__, c.__AppEditorTheme_notification__.len);
                
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, 0);
                _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "file ~/clipboard.tmp not reedable.");
                
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, 1);
                _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, path[0..path_len]);
                
                c.__Terminal_resetColors__(&c.__app__.terminal);
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
            }
            t.__AppEditorViewsFlat_autoSpace__ = true;
            if (!ok) return error.Unexpected;
        }
    // # __AppEditorViewsFlat_findNextAndDraw__
        fn __AppEditorViewsFlat_findNextAndDraw__(t: *c.__AppEditorViewsFlat__) !void {
            try __AppEditorViewsFlat_findNext__(t);
            t.need_redraw = true;
            t.need_draw_line_num = true;
        }
    // # __AppEditorViewsFlat_findNext__
        fn __AppEditorViewsFlat_findNext__(
            t: *c.__AppEditorViewsFlat__
        ) !void {
            const finding_text: []const u8 = __AppEditorViewsFind_get__(&c.__app__.editor.views.find) orelse return;
            if (finding_text.len > 0){
                var finded: bool = false;
                if (t.line.*.text_len > 0) { // try find on current line
                    const text = t.line.*.text[0 .. t.line.*.text_len];
                    if (t.symbol < text.len) {
                        const start_find_pos: usize        = t.symbol + 1;
                        const find_data:      [*]const u8  = text.ptr[start_find_pos..];
                        const find_data_len:  usize        = text.len - (start_find_pos);
                        var   pos:            usize        = 0;
                        if (find_data_len >= finding_text.len and c.__Mem_findFast__(&pos, find_data, find_data_len, finding_text.ptr, finding_text.len)){
                            t.symbol += pos + 1;
                            finded = true;
                        }
                    }
                }
                if (finded == false) { // find on next lines
                    var current: *c.__MemListLink__ = &t.line.*.link;
                    while (true) {
                        if (current == t.lines.last) break;
                        
                        if (current.next) |nl| {
                            current = nl;
                        }
                        const line: *c.__AppEditorLine__ = @fieldParentPtr("link", current);
                        if (line.text_len > 0) {
                            var pos: usize = 0;
                            if (line.text_len >= finding_text.len and c.__Mem_findFast__(&pos, line.text[0..].ptr, line.text_len, finding_text.ptr, finding_text.len)) {
                                t.line     = line;
                                t.offset.y = (c.__app__.terminal.output.size.y >> 1) + (c.__app__.terminal.output.size.y >> 3);
                                t.symbol   = pos;
                                __AppEditorViewsFlat_changeOffsetX__(t, pos);
                                __AppEditorViewsFlat_bakupTextOnCurrentLine__(t);
                                break;
                            }
                        } 
                    }
                    
                }
            }
        }
    // # __AppEditorViewsFlat_findPrevAndDraw__
        fn __AppEditorViewsFlat_findPrevAndDraw__(t: *c.__AppEditorViewsFlat__) !void {
            try __AppEditorViewsFlat_findPrev__(t);
            t.need_redraw = true;
            t.need_draw_line_num = true;
        }
    // # __AppEditorViewsFlat_findPrev__
        fn __AppEditorViewsFlat_findPrev__(t: *c.__AppEditorViewsFlat__) !void {
            const finding_text: []const u8 = __AppEditorViewsFind_get__(&c.__app__.editor.views.find) orelse return;
            
            find_on_current_line: {
                var current_text: []u8 = "";
                if (t.line.*.text_len > 0) {
                    current_text = t.line.*.text[0 .. t.line.*.text_len];
                } else {
                    break :find_on_current_line;
                }
                if (t.symbol > current_text.len) __AppEditorViewsFlat_goToSymbol__(t, current_text.len);
                var pos: usize = 0;
                if (t.symbol >= finding_text.len and c.__mem_findFastReverse__(&pos, current_text.ptr, t.symbol, finding_text.ptr, finding_text.len)) {
                    t.symbol = pos;
                    __AppEditorViewsFlat_changeOffsetX__(t, pos);
                    __AppEditorViewsFlat_bakupTextOnCurrentLine__(t);
                    t.need_redraw = true;
                    t.need_draw_line_num = true;
                    return;
                } else {
                    break :find_on_current_line;
                }
            }
            
            var current = &t.line.*.link;
            while (true) {
                const prev_link = current.prev orelse break;
                current = prev_link;
                
                var line: *c.__AppEditorLine__ = @fieldParentPtr("link", current);
                var line_text: []u8 = "";
                if (line.text_len > 0) {
                    line_text = line.text[0 .. line.text_len];
                } else {
                    continue;
                }
                var pos: usize = 0;
                if (line_text.len >= finding_text.len and c.__mem_findFastReverse__(&pos, line_text.ptr, line_text.len, finding_text.ptr, finding_text.len)) {
                    t.line = line;
                    t.offset.y = (c.__app__.terminal.output.size.y >> 1) - (c.__app__.terminal.output.size.y >> 3);
                    __AppEditorViewsFlat_goToStartOfText__(t);
                    t.symbol = pos;
                    __AppEditorViewsFlat_changeOffsetX__(t, pos);
                    break;
                } else {
                    continue;
                }
            }
            __AppEditorViewsFlat_bakupTextOnCurrentLine__(t);
        }
    // # __AppEditorViewsFlat_fold__
        fn __AppEditorViewsFlat_fold__(t: *c.__AppEditorViewsFlat__) !void {
            const vf = &c.__app__.editor.views.folded;
            
            { // fold (set links in tree)
                var blanked_lines: c.__MemList__  = undefined;
                c.__MemList_init__(&blanked_lines);
                
                const tree_root = &vf.lines;
                var current: *c.__MemTree__ = tree_root;
                while (t.lines.count > 0) {
                    const next_line_link: *c.__MemListLink__ = t.lines.first.?; // flat link. not null. garanty by count > 0
                    c.__MemList_pop__(&t.lines, next_line_link);
                    const next_line:      *c.__AppEditorLine__       = @fieldParentPtr("link", next_line_link);
                    const next_line_tree: *c.__MemTree__     = &next_line.tree;
                    var   next_text:      []u8                     = "";
                    if (next_line.text_len > 0) next_text = next_line.text[0 .. next_line.text_len];
                    const next_indent:      usize  = c.__TextAscii_countIndent__(next_text.ptr, next_text.len, 1);
                    const next_non_indent:  usize  = c.__TextAscii_countNonIndent__(next_text.ptr, next_text.len);
                    
                    if (next_non_indent == 0) {
                        c.__MemList_pushLast__(&blanked_lines, next_line_link);
                    } else {
                        while (current != tree_root) { // findLineWithLessIndent
                            const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", current);
                            
                            var line_text: []u8  = "";
                            if (line.text_len > 0) line_text = line.text[0 .. line.text_len];
                            const non_indent = c.__TextAscii_countNonIndent__(line_text.ptr, line_text.len);
                            const indent     = c.__TextAscii_countIndent__(line_text.ptr, line_text.len, 1);
                            if (non_indent != 0 and indent < next_indent) break;
                            
                            c.__MemTree_getParent__(@ptrCast(&current), current); // current not null - garanty by loop. current is child of tree_root
                        }
                        c.__MemTree_pushChild__(current, next_line_tree);
                        current = next_line_tree;
                        
                        while (blanked_lines.count > 0) {
                            const blank_link: *c.__MemListLink__ = blanked_lines.first.?;
                            c.__MemList_pop__(&blanked_lines, blank_link);
                            const blank_line: *c.__AppEditorLine__       = @fieldParentPtr("link", blank_link);
                            c.__MemTree_pushPrev__(current, &blank_line.tree);
                        }
                    }
                }
                
                while (blanked_lines.count > 0) {
                    const blank_link: *c.__MemListLink__ = blanked_lines.first.?; // non nil - garanty by count > 0
                    c.__MemList_pop__(&blanked_lines, blank_link);
                    const blank_line: *c.__AppEditorLine__       = @fieldParentPtr("link", blank_link);
                    c.__MemTree_pushChild__(tree_root, &blank_line.tree);
                }
            }
            
            { // changeView
                vf.line        = t.line;
                vf.offset      = t.offset;
                vf.symbol      = t.symbol;
                vf.marked_line = t.marked_line;
                vf.need_redraw = true;
                try __AppEditorViewsFolded_setAsView__(vf);
            }
        }
    // # __AppEditorViewsFlat_goToEndOfLine__
        fn __AppEditorViewsFlat_goToEndOfLine__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            t.symbol = t.line.*.text_len;
            __AppEditorViewsFlat_changeOffsetX__(t, t.symbol);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_goToFirstLine__
        fn __AppEditorViewsFlat_goToFirstLine__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            const link = t.lines.first orelse unreachable;
            t.line = @fieldParentPtr("link", link);
            t.goToStartOfText();
            t.offset.y = (c.__app__.terminal.output.size.y >> 1) - (c.__app__.terminal.output.size.y >> 2);
            t.need_redraw = true;
            t.bakup();
        }
    // # __AppEditorViewsFlat_goToLastLine__
        fn __AppEditorViewsFlat_goToLastLine__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            const link = t.lines.last orelse unreachable;
            
            t.line = @fieldParentPtr("link", link);
            t.goToStartOfText();
            t.offset.y = (c.__app__.terminal.output.size.y >> 1) + (c.__app__.terminal.output.size.y >> 2);
            t.need_redraw = true;
            t.bakup();
        }
    // # __AppEditorViewsFlat_goToLineFromNumber__
        fn __AppEditorViewsFlat_goToLineFromNumber__(t: *c.__AppEditorViewsFlat__, _num: usize) callconv(.c) void {
            if (_num == 0) return;
            __AppEditorViewsFlat_goToRoot__(t);
            var pos: usize = 1;
            while (pos < _num and __AppEditorViewsFlat_goToNextLine__(t)) {
                pos += 1;
            }
            var indent: usize = 0;
                const text_len = t.line.*.text_len;
                if (text_len > 0) {
                    const text = &t.line.*.text[0];
                    indent = c.__TextAscii_countIndent__(text, text_len, 1);
                }
            __AppEditorViewsFlat_goToSymbol__(t, indent);
            t.offset.y = c.__app__.terminal.output.size.y >> 1;
            __AppEditorViewsFlat_bakupTextOnCurrentLine__(t);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_goToMarked__
        fn __AppEditorViewsFlat_goToMarked__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            if (t.marked_line) |mark| {
                t.line = mark;
                t.need_redraw = true;
                __AppEditorViewsFlat_bakupTextOnCurrentLine__(t);
            }
        }
    // # __AppEditorViewsFlat_goToNextLine__
        fn __AppEditorViewsFlat_goToNextLine__(t: *c.__AppEditorViewsFlat__) callconv(.c) bool {
            var ok: bool = true;
                const last_line: *c.__AppEditorLine__ = t.line;
                if (@intFromPtr(t.line.*.link.next) != @intFromPtr(c.NULL)) {
                    const next_link: *c.__MemListLink__ = @ptrCast(t.line.*.link.next);
                    
                    // set current line to prev line
                        const next_line: *c.__AppEditorLine__ = @fieldParentPtr("link", next_link);
                        t.line = next_line;
                        __AppEditorViewsFlat_bakupTextOnCurrentLine__(t);
                        t.need_redraw = true;
                        if (t.offset.y < c.__app__.terminal.output.size.y - 1) t.offset.y += 1;
                    
                    // if cursor on start of text - move cursor to new start of text
                        var last_text: []u8 = "";
                        if (last_line.text_len > 0) {
                            last_text = last_line.text[0 .. last_line.text_len];
                        }
                        if (t.symbol == c.__TextAscii_countIndent__(last_text.ptr, last_text.len, 1)) {
                            var next_text: []u8 = "";
                            if (next_line.text_len > 0) next_text = next_line.text[0 .. next_line.text_len];
                            __AppEditorViewsFlat_goToSymbol__(t, c.__TextAscii_countIndent__(next_text.ptr, next_text.len, 1));
                        }
                    
                } else {
                    ok = false;
                }
                
            return ok;
        }
    // # __AppEditorViewsFlat_goToNextSymbol__
        fn __AppEditorViewsFlat_goToNextSymbol__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            if (t.symbol < t.line.*.text_len) {
                // inc symbol
                if (t.symbol >= c.__AppEditorLineLen_max__ - 1) return; // todo rewrite lines to use allocator for lines. and remove this check.
                t.symbol += 1;
                t.need_redraw = true;
                
                __AppEditorViewsFlat_changeOffsetX__(t, t.symbol);
            }
        }
    // # __AppEditorViewsFlat_goToPrevLine__
        fn __AppEditorViewsFlat_goToPrevLine__(t: *c.__AppEditorViewsFlat__) callconv(.c) bool {
            var ok: bool = true;
                const last_line = t.line;
                if (@intFromPtr(t.line.*.link.prev) != @intFromPtr(c.NULL))  {
                    const prev_link: *c.__MemListLink__ = @ptrCast(t.line.*.link.prev);
                    
                    // set current line to prev line
                        const prev_line: *c.__AppEditorLine__ = @fieldParentPtr("link", prev_link);
                        t.need_redraw = true;
                        t.line = prev_line;
                        if (t.offset.y > 5) {
                            t.offset.y -= 1;
                        }
                        __AppEditorViewsFlat_bakupTextOnCurrentLine__(t);
                    
                    // if cursor on start of text - move cursor to new start of text
                        var last_indent: usize = 0;
                        if (last_line.*.text_len > 0) {
                            last_indent = c.__TextAscii_countIndent__(&last_line.*.text[0], last_line.*.text_len, 1);
                        }
                        if (t.symbol == last_indent) {
                            __AppEditorViewsFlat_moveCursorToStartOfLine__(t);
                        }
                } else {
                    ok = false;
                }
            return ok;
        }
    // # __AppEditorViewsFlat_goToPrevSymbol__
        fn __AppEditorViewsFlat_goToPrevSymbol__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            const used = t.line.*.text_len;
            
            if (t.symbol > used) {
                t.symbol = used;
            } else if (t.symbol > 0) {
                t.symbol -= 1;
            }
            
            __AppEditorViewsFlat_changeOffsetX__(t, t.symbol);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_goToRoot__
        fn __AppEditorViewsFlat_goToRoot__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            const first_line_link: *c.__MemListLink__ = t.lines.first orelse unreachable;
            const line: *c.__AppEditorLine__ = @fieldParentPtr("link", first_line_link);
            t.line = line;
            t.offset.y = 5;
            __AppEditorViewsFlat_goToStartOfText__(t);
            t.need_redraw = true;
            __AppEditorViewsFlat_bakupTextOnCurrentLine__(t);
        }
    // # __AppEditorViewsFlat_goToStartOfLine__
        fn __AppEditorViewsFlat_goToStartOfLine__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            t.symbol = 0;
            t.offset.x = 0;
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_goToStartOfText__
        fn __AppEditorViewsFlat_goToStartOfText__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            var text: []u8  = "";
            if (t.line.*.text_len > 0) text = t.line.*.text[0 .. t.line.*.text_len];
            const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
            __AppEditorViewsFlat_goToSymbol__(t, indent);
        }
    // # __AppEditorViewsFlat_goToSymbol__
        fn __AppEditorViewsFlat_goToSymbol__(t: *c.__AppEditorViewsFlat__, pos: usize) callconv(.c) void {
            t.symbol = pos;
            __AppEditorViewsFlat_changeOffsetX__(t, t.symbol);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_init__
        fn __AppEditorViewsFlat_init__(t: *c.__AppEditorViewsFlat__) !void {
            c.__MemList_init__(&t.lines);
            c.__MemList_init__(&t.cutted);
            c.__AppEditorLine_init__(&t.bakup_line);
            t.need_redraw         = true;
            t.need_draw_line_num  = true;
            t.marked_line         = null;
            t.offset              = .{ .x = 0, .y = 3 };
            t.symbol              = 0;
            t.__AppEditorViewsFlat_autoSpace__ = true;
            // t.line - is setted by outside
        }
    // # __AppEditorViewsFlat_insertFindedText__
        fn __AppEditorViewsFlat_insertFindedText__(t: *c.__AppEditorViewsFlat__) !void {
            const text: []const u8 = __AppEditorViewsFind_get__(&c.__app__.editor.views.find) orelse return;
            for (text) |rune| {
                __AppEditorViewsFlat_insertSymbol__(t, rune) catch {};
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_insertSymbol__
        fn __AppEditorViewsFlat_insertSymbol__(t: *c.__AppEditorViewsFlat__, rune: u8) !void {
            if (t.symbol > t.line.*.text_len) __AppEditorViewsFlat_goToSymbol__(t, t.line.*.text_len);
            if (t.line.*.text_len < c.__AppEditorLineLen_max__) {
                c.__Buffer_push__(&t.line.*.text[0], &t.line.*.text_len, t.symbol, rune);
                __AppEditorViewsFlat_goToNextSymbol__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_joinLines__
        fn __AppEditorViewsFlat_joinLines__(t: *c.__AppEditorViewsFlat__) !void {
            //var ok: bool = true
            
            if (@intFromPtr(t.line.*.link.prev) != @intFromPtr(c.NULL)) {
                const prev_link: *c.__MemListLink__    = t.line.*.link.prev;
                const prev_line: *c.__AppEditorLine__  = @fieldParentPtr("link", prev_link);
                
                if (t.line.*.text_len > 0) {
                    if (prev_line.text_len > 0) {
                        // count non indent text len
                        const prev_indent:     usize  = c.__Text_countIndent__(&prev_line.text[0], prev_line.text_len, 1);
                        const prev_non_indent: usize  = prev_line.text_len - prev_indent;
                        
                        if (prev_non_indent > 0) {
                            const line_indent:     usize  = c.__Text_countIndent__(&t.line.*.text[0], t.line.*.text_len, 1);
                            const line_non_indent: usize  = t.line.*.text_len - line_indent;
                            
                            if (line_non_indent > 0) {
                                // copy text
                                const space_len: usize = @as(usize, c.__AppEditorLineLen_max__) - prev_line.text_len; // TODO use allocator for realocating. Maybe create virtual lines for too big text?
                                if (space_len > line_non_indent) { // size checked
                                    const prev_len: usize = prev_line.text_len;
                                    c.__Mem_copy__(&prev_line.text[prev_line.text_len], &t.line.*.text[line_indent], line_non_indent);
                                    prev_line.text_len += line_non_indent;
                                    
                                    // delete line
                                        c.__MemList_pop__(&t.lines, &t.line.*.link);
                                        c.__AppEditorLine_free__(t.line);
                                    
                                    // replace to prev line
                                        t.line = prev_line;
                                        __AppEditorViewsFlat_goToSymbol__(t, prev_len);
                                } else {
                                    __AppEditor_changeStatus__("line is too big");
                                }
                            } else { // current line text is nil (only spaces)
                                // remove current line
                                    c.__MemList_pop__(&t.lines, &t.line.*.link);
                                    c.__AppEditorLine_free__(t.line);
                                
                                // replace to prev line
                                    t.line = prev_line;
                                    __AppEditorViewsFlat_goToSymbol__(t, prev_line.text_len);
                            }
                        } else { // prev_text is nil
                            c.__MemList_pop__(&t.lines, prev_link);
                           c.__AppEditorLine_free__(prev_line);
                        }
                    } else {
                        c.__MemList_pop__(&t.lines, prev_link);
                        c.__AppEditorLine_free__(prev_line);
                    }
                } else {
                    //  delete current line
                        c.__MemList_pop__(&t.lines, &t.line.*.link);
                        c.__AppEditorLine_free__(t.line);
                    
                    // replace to prev line
                        t.line = prev_line;
                        __AppEditorViewsFlat_goToSymbol__(t, prev_line.text_len);
                }
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_jumpToOutOfBlock__
        fn __AppEditorViewsFlat_jumpToOutOfBlock__ (t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            var last_text: []u8 = "";
            if (t.line.*.text_len > 0) last_text = t.line.*.text[0 .. t.line.*.text_len];
            const last_indent = c.__TextAscii_countIndent__(last_text.ptr, last_text.len, 1);
            while(__AppEditorViewsFlat_goToPrevLine__(t)) {
                var new_text: []u8 = "";
                if (t.line.*.text_len > 0) new_text = t.line.*.text[0 .. t.line.*.text_len];
                const new_indent = c.__TextAscii_countIndent__(new_text.ptr, new_text.len, 1);
                if ( true
                    // line not empty
                        and new_text.len > new_indent 
                        and c.__TextAscii_isVisible__(new_text[new_indent])
                    and new_indent < last_indent
                ) {
                    break;
                }
            }
            __AppEditorViewsFlat_moveCursorToStartOfLine__(t);
        }
    // # __AppEditorViewsFlat_manyIndent__
        fn __AppEditorViewsFlat_manyIndent__(t: *c.__AppEditorViewsFlat__) !void { // todo rename to __AppEditorFlat_lessIndent__
            var text: []u8 = "";
            if (t.line.text_len > 0) text = t.line.text[0 .. t.line.text_len];
            const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
            if (indent < 4) return;
            if (c.__AppEditorLine_setIndent__(t.line, indent - 4) == false) return error.Unexpected;
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_markThisLine__
        fn __AppEditorViewsFlat_markThisLine__(t: *c.__AppEditorViewsFlat__) !void {
            t.marked_line = t.line;
            __AppEditor_changeStatus__("marked.");
        }
    // # __AppEditorViewsFlat_moveBlockToMarkedOut__
        fn __AppEditorViewsFlat_moveBlockToMarkedOut__(t: *c.__AppEditorViewsFlat__) !void {
            var ok: bool = true;
                const marked = t.marked_line orelse return;
                if (marked == t.line) return;
                
                // move
                var next_link: *c.__MemListLink__  = undefined; { // select next_link
                    const current_link = &t.line.*.link;
                    if (current_link.next) |_next_link| {
                        next_link = _next_link;
                    } else if (current_link.prev) |prev_link| {
                        next_link = prev_link;
                    } else {
                        ok = false;
                    }
                }
                if (ok) {
                    const line_link = &t.line.*.link;
                    c.__MemList_pop__(&t.lines, line_link);
                    c.__MemList_pushBefore__(&t.lines, &marked.*.link, line_link);
                    const line: *c.__AppEditorLine__ = @fieldParentPtr("link", next_link);
                    t.line = line;
                    t.need_redraw = true;
                    __AppEditor_changeStatus__("moved to marked.");
                    
                }
            if (!ok) return error.Unexpected;
        }
    // # __AppEditorViewsFlat_moveCursorToStartOfLine__
        fn __AppEditorViewsFlat_moveCursorToStartOfLine__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            var indent: usize = 0;
            if (t.line.*.text.len > 0) {indent = c.__TextAscii_countIndent__(&t.line.*.text[0], t.line.*.text_len, 1);}
            __AppEditorViewsFlat_goToSymbol__(t, indent);
        }
    // # __AppEditorViewsFlat_moveFoldedBlockToMarkedIn__
        fn __AppEditorViewsFlat_moveFoldedBlockToMarkedIn__(t: *c.__AppEditorViewsFlat__) !void {
           const vf = &c.__app__.editor.views.folded;
           try __AppEditorViewsFlat_fold__(t);
           try __AppEditorViewsFolded_moveBlockToMarkedInWithAddIndent__(vf);
           try __AppEditorViewsFolded_unFold__(vf);
        }
    // # __AppEditorViewsFlat_onKey__
        fn __AppEditorViewsFlat_onKey__(ctx: *c.__AppEditorViewsFlat__, cik: c.__ConsoleAnsiInputKey__) callconv(.c) void {
            __AppEditorViewsFlat_onkeyWrap__(ctx, cik) catch {};
        }
    // # __AppEditorViewsFlat_onkeyWrap__
        fn __AppEditorViewsFlat_onkeyWrap__(ctx: ?*anyopaque, cik: c.__ConsoleAnsiInputKey__) !void {
            const t: *c.__AppEditorViewsFlat__ = @alignCast(@ptrCast(ctx));
            
            switch (cik) {
                c.__ConsoleAnsiInputKey_ctrl_q__           => {try __AppEditor_stop__(&c.__app__.editor);},
                c.__ConsoleAnsiInputKey_ctrl_s__           => {__AppEditorViewsFlat_save__(t) catch {};},
                // change view
                    c.__ConsoleAnsiInputKey_alt_e__            => {try __AppEditorViewsFlat_easyMotionV__(t);},
                    c.__ConsoleAnsiInputKey_alt_q__            => {try __AppEditorViewsFlat_easyMotionH__(t);},
                    c.__ConsoleAnsiInputKey_ctrl_e__           => {try __AppEditorViewsFlat_fold__(t);},
                    c.__ConsoleAnsiInputKey_ctrl_f__           => {__AppEditorViewsFlat_toFind__(t);},
                    c.__ConsoleAnsiInputKey_ctrl_g__           => {__AppEditorViewsFlat_toGoTo__(t);},
                    c.__ConsoleAnsiInputKey_alt_5__            => {__AppEditorViewsFlat_toReplace__(t);},
                // navigation
                    // blocks
                        c.__ConsoleAnsiInputKey_escape__           => {__AppEditorViewsFlat_jumpToOutOfBlock__(t);},
                        c.__ConsoleAnsiInputKey_tab__              => {__AppEditorViewsFlat_enterToBlock__(t);},
                        c.__ConsoleAnsiInputKey_alt_0__            => {try __AppEditorViewsFlat_moveBlockToMarkedOut__(t);},
                        c.__ConsoleAnsiInputKey_alt_9__            => {__AppEditorViewsFlat_moveFoldedBlockToMarkedIn__(t) catch {};},
                    // lines
                        c.__ConsoleAnsiInputKey_up__               => {_=__AppEditorViewsFlat_goToPrevLine__(t);},
                        c.__ConsoleAnsiInputKey_down__             => {_=__AppEditorViewsFlat_goToNextLine__(t);},
                        c.__ConsoleAnsiInputKey_page_up__          => {__AppEditorViewsFlat_pageUp__(t);},
                        c.__ConsoleAnsiInputKey_page_down__        => {__AppEditorViewsFlat_pageDown__(t);},
                        c.__ConsoleAnsiInputKey_alt_g__            => {__AppEditorViewsFlat_goToMarked__(t);},
                        c.__ConsoleAnsiInputKey_alt_m__            => {try __AppEditorViewsFlat_markThisLine__(t);},
                    // text
                        c.__ConsoleAnsiInputKey_left__             => {__AppEditorViewsFlat_goToPrevSymbol__(t);},
                        c.__ConsoleAnsiInputKey_right__            => {__AppEditorViewsFlat_goToNextSymbol__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_up__          => {__AppEditorViewsFlat_ctrlUp__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_down__        => {__AppEditorViewsFlat_ctrlDown__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_shift_left__  => {__AppEditorViewsFlat_ctrlShiftLeft__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_shift_right__ => {__AppEditorViewsFlat_ctrlShiftRight__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_left__        => {__AppEditorViewsFlat_ctrlLeft__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_right__       => {__AppEditorViewsFlat_ctrlRight__(t);},
                        c.__ConsoleAnsiInputKey_end__              => {__AppEditorViewsFlat_goToEndOfLine__(t);},
                        c.__ConsoleAnsiInputKey_home__             => {__AppEditorViewsFlat_goToStartOfLine__(t);},
                // edit
                    // blocks
                    // lines
                        c.__ConsoleAnsiInputKey_alt_up__           => {try __AppEditorViewsFlat_swapWithUpper__(t);},
                        c.__ConsoleAnsiInputKey_alt_down__         => {try __AppEditorViewsFlat_swapWithBottom__(t);},
                        c.__ConsoleAnsiInputKey_shift_delete__     => {__AppEditorViewsFlat_clearLine__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_d__           => {try __AppEditorViewsFlat_duplicateLine__(t);},
                        c.__ConsoleAnsiInputKey_enter__            => {__AppEditorViewsFlat_divideLine__(t) catch {};},
                        c.__ConsoleAnsiInputKey_ctrl_j__           => {try __AppEditorViewsFlat_joinLines__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_enter__       => {try __AppEditorViewsFlat_joinLines__(t);},
                    // text
                        c.__ConsoleAnsiInputKey_alt_6__            => {__AppEditorViewsFlat_replace__(t) catch {};},
                        c.__ConsoleAnsiInputKey_alt_1__            => {try __AppEditorViewsFlat_copyWordToFind__(t);},
                        c.__ConsoleAnsiInputKey_alt_2__            => {try __AppEditorViewsFlat_findPrevAndDraw__(t);},
                        c.__ConsoleAnsiInputKey_alt_3__            => {try __AppEditorViewsFlat_findNextAndDraw__(t);},
                        c.__ConsoleAnsiInputKey_alt_4__            => {try __AppEditorViewsFlat_insertFindedText__(t);},
                        c.__ConsoleAnsiInputKey_delete__           => {__AppEditorViewsFlat_deleteSymbol__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_z__           => {try __AppEditorViewsFlat_restoreTextOnCurrentLine__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_w__           => {try __AppEditorViewsFlat_deleteWord__(t);},
                        //c.__ConsoleAnsiInputKey_ctrl_t__           => {__AppEditorViewsFlat_insertSymbol__(t, '\t') catch {};},
                        c.__ConsoleAnsiInputKey_back_space__       => {try __AppEditorViewsFlat_deletePrevSymbol__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_bs__          => {try __AppEditorViewsFlat_deletePrevSymbol__(t);},
                    // copy paste
                        c.__ConsoleAnsiInputKey_ctrl_x__           => {try __AppEditorViewsFlat_cutLine__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_c__           => {try __AppEditorViewsFlat_duplicateLineAndCut__(t);},
                        c.__ConsoleAnsiInputKey_ctrl_v__           => {__AppEditorViewsFlat_pasteLine__(t) catch {};},
                        c.__ConsoleAnsiInputKey_alt_z__            => {try __AppEditorViewsFlat_deleteCutted__(t);},
                        c.__ConsoleAnsiInputKey_alt_b__            => {
                            t.__AppEditorViewsFlat_autoSpace__ = !t.__AppEditorViewsFlat_autoSpace__;
                            if (t.__AppEditorViewsFlat_autoSpace__) {
                                __AppEditor_changeStatus__("auto space enabled");
                            } else {
                                __AppEditor_changeStatus__("auto space disabled");
                            }
                        },
                    // external
                        c.__ConsoleAnsiInputKey_alt_c__            => {_=__AppEditorViewsFlat_externalCopy__(t) catch {};},
                        c.__ConsoleAnsiInputKey_alt_v__            => {__AppEditorViewsFlat_externalPaste__(t)  catch {};},
                c.__ConsoleAnsiInputKey_ctrl_t__ => __AppEditorViewsFlat_ctrl_t__(t),
                else => {
                    if (cik > 255) return;
                    const byte: u8 = @truncate(cik);
                    __AppEditorViewsFlat_insertSymbol__(t, byte) catch {};
                    t.need_redraw = true;
                },
            }
        }
    // # __AppEditorViewsFlat_pageDown__
        fn __AppEditorViewsFlat_pageDown__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            var pos: usize = 0;
            while (pos < 10) : (pos += 1) {
                if (!__AppEditorViewsFlat_goToNextLine__(t)) break;
            }
        }
    // # __AppEditorViewsFlat_pageUp__
        fn __AppEditorViewsFlat_pageUp__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            var pos: usize = 0;
            while (pos < 10) : (pos += 1) {
                if (!__AppEditorViewsFlat_goToPrevLine__(t)) break;
            }
        }
    // # __AppEditorViewsFlat_pasteLine__
        fn __AppEditorViewsFlat_pasteLine__(t: *c.__AppEditorViewsFlat__) !void {
            if (t.cutted.count == 0) return;
            
            const indent = count_indent: {
                var text: []u8 = "";
                if (t.line.*.text_len > 0) text = t.line.*.text[0 .. t.line.*.text_len];
                const current_indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                
                const prev_line_link: *c.__MemListLink__ = t.line.*.link.prev orelse break :count_indent current_indent;
                const prev_line: *c.__AppEditorLine__ = @fieldParentPtr("link", prev_line_link);
                var prev_text: []u8 = "";
                if (prev_line.text_len > 0) prev_text = prev_line.text[0 .. prev_line.text_len];
                const prev_indent = c.__TextAscii_countIndent__(prev_text.ptr, prev_text.len, 1);
                
                break :count_indent @max(current_indent, prev_indent);
            };
            const link: *c.__MemListLink__ = t.cutted.last orelse unreachable;
            c.__MemList_pop__(&t.cutted, link); 
            c.__MemList_pushBefore__(&t.lines, &t.line.*.link, link);
            t.offset.y += 1;
            _=__AppEditorViewsFlat_goToPrevLine__(t);
            if (c.__AppEditorLine_setIndent__(t.line, indent) == false) return error.Unexpected;
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_replace__
        fn __AppEditorViewsFlat_replace__(t: *c.__AppEditorViewsFlat__) !void {
            const find_line    = &c.__app__.editor.views.find.line;
            const replace_line = &c.__app__.editor.views.replace.line;
            const current_line = t.line;
            const check_len    = find_line.text_len;
            if (true
                and current_line.*.text_len - t.symbol >= check_len
                and c.__Mem_isEql__(&current_line.*.text[t.symbol], &find_line.text[0], find_line.text_len)
            ) {
                // delete old text
                var pos: usize = 0;
                while (pos < check_len):(pos += 1) {
                    __AppEditorViewsFlat_deleteSymbol__(t);
                }
                // insert new_text
                pos = 0;
                while (pos < replace_line.text_len):(pos += 1) {
                    const rune = replace_line.text[pos];
                    __AppEditorViewsFlat_insertSymbol__(t, rune) catch {};
                }
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsFlat_restoreTextOnCurrentLine__
        fn __AppEditorViewsFlat_restoreTextOnCurrentLine__(t: *c.__AppEditorViewsFlat__) !void {
            var text: []u8 = "";
            if (t.bakup_line.text_len > 0) text = t.bakup_line.text[0 .. t.bakup_line.text_len];
            c.__AppEditorLine_setText__(t.line, text.ptr, text.len);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_save__
        fn __AppEditorViewsFlat_save__(t: *c.__AppEditorViewsFlat__) !void {
            var ok: bool = true;
                __AppEditor_changeStatus__("saving ...");
                ok = c.__AppEditorListOfLine_writeToFile__(
                    &t.lines, 
                    &c.__app__.editor.__AppEditor_fileName__[0],
                    c.__app__.editor.__AppEditor_fileName_len__
                );
                if (ok) {
                    __AppEditor_changeStatus__("saved ...");
                } else {
                    __AppEditor_changeStatus__("NOT saved ...");
                    ok = false;
                }
                t.need_redraw = false;
            
            if (!ok) return error.Unexpected;
            // return ok;
        }
    // # __AppEditorViewsFlat_setAsView__
        fn __AppEditorViewsFlat_setAsView__(t: *c.__AppEditorViewsFlat__) !void {
            c.__app__.editor.do_ptr      = @ptrCast(&__AppEditorViewsFlat_do__);
            c.__app__.editor.onKey_ptr   = @ptrCast(&__AppEditorViewsFlat_onKey__);
            c.__app__.editor.current_ctx = t;
            c.__app__.editor.current_vtable = &c.__AppEditorViewsVtable_flat__;
            __AppEditorViewsFlat_bakupTextOnCurrentLine__(t);
            t.need_redraw = true;
            __AppEditor_changeStatus__("Flat mode.");
            __AppEditorViewsFlat_cursorMoveToCurrent__(t) catch {};
        }
    // # __AppEditorViewsFlat_swapWithBottom__
        fn __AppEditorViewsFlat_swapWithBottom__(t: *c.__AppEditorViewsFlat__) !void {
            try __AppEditorViewsFlat_cutLine__(t);
            var text: []u8 = "";
            if (t.line.*.text_len > 0) text = t.line.*.text[0 .. t.line.*.text_len];
            const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
            
            const link: *c.__MemListLink__ = t.cutted.last orelse unreachable;
            c.__MemList_pop__(&t.cutted, link);
            c.__MemList_pushAfter__(&t.lines, &t.line.*.link, link);
            _=__AppEditorViewsFlat_goToNextLine__(t);
            if (c.__AppEditorLine_setIndent__(t.line, indent) == false) return error.Unexpected;
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_swapWithUpper__
        fn __AppEditorViewsFlat_swapWithUpper__(t: *c.__AppEditorViewsFlat__) !void {
            if (t.line.*.link.next == null) {
                try __AppEditorViewsFlat_cutLine__(t);
                try __AppEditorViewsFlat_pasteLine__(t);
            } else {
                try __AppEditorViewsFlat_cutLine__(t);
                _=__AppEditorViewsFlat_goToPrevLine__(t);
                try __AppEditorViewsFlat_pasteLine__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFlat_toFind__
        fn __AppEditorViewsFlat_toFind__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            __AppEditorViewsFind_setAsView__(&c.__app__.editor.views.find, t, &c.__AppEditorViewsVtable_flat__);
        }
    // # __AppEditorViewsFlat_toGoTo__
        fn __AppEditorViewsFlat_toGoTo__(t: *c.__AppEditorViewsFlat__) callconv(.c) void { __zig_fuck__(t);
            __AppEditorViewsGoToLine_setAsView__(&c.__app__.editor.views.go_to_line, t, &c.__AppEditorViewsVtable_flat__);
        }
    // # __AppEditorViewsFlat_toReplace__
        fn __AppEditorViewsFlat_toReplace__(t: *c.__AppEditorViewsFlat__) callconv(.c) void {
            __AppEditorViewsReplace_setAsView__(&c.__app__.editor.views.replace, t, &c.__AppEditorViewsVtable_flat__);
        }
    // # __AppEditorViewsFoldedVtable_countLineNum__
        fn __AppEditorViewsFoldedVtable_countLineNum__(model: *c.__AppEditorViewsFolded__) callconv(.c) usize {
            const view = __AppEditorViewsFoldedVtable_getModel__(model);
            return __AppEditorViewsFolded_countLineNum__(view);
        }
    // # __AppEditorViewsFoldedVtable_getModel__
        fn __AppEditorViewsFoldedVtable_getModel__(ptr: *anyopaque) callconv(.c) *c.__AppEditorViewsFolded__ {
            const ret_ptr: *c.__AppEditorViewsFolded__ = @ptrFromInt(@intFromPtr(ptr));
            return ret_ptr;
        }
    // # __AppEditorViewsFoldedVtable_getOffsetX__
        fn __AppEditorViewsFoldedVtable_getOffsetX__(model: *anyopaque) callconv(.c) usize {
            const view = __AppEditorViewsFoldedVtable_getModel__(model);
            return view.offset.x;
        }
    // # __AppEditorViewsFoldedVtable_getOffsetY__
        fn __AppEditorViewsFoldedVtable_getOffsetY__(model: *anyopaque) callconv(.c) usize {
            const view = __AppEditorViewsFoldedVtable_getModel__(model);
            return view.offset.y;
        }
    // # __AppEditorViewsFoldedVtable_getSymbolPosX__
        fn __AppEditorViewsFoldedVtable_getSymbolPosX__(model: *c.__AppEditorViewsFolded__) callconv(.c) usize {
            const view = __AppEditorViewsFoldedVtable_getModel__(model);
            return view.symbol;
        }
    // # __AppEditorViewsFoldedVtable_goToLineFromNumber__
        fn __AppEditorViewsFoldedVtable_goToLineFromNumber__(ctx: *c.__AppEditorViewsFolded__, _num: usize) callconv(.c) void {
            const view = __AppEditorViewsFoldedVtable_getModel__(ctx);
            return __AppEditorViewsFolded_goToLineFromNumber__(view, _num);
        }
    // # __AppEditorViewsFoldedVtable_goToNextLine__
        fn __AppEditorViewsFoldedVtable_goToNextLine__(model: *anyopaque) callconv(.c) void {
            const view = __AppEditorViewsFoldedVtable_getModel__(model);
            __AppEditorViewsFolded_goToNextLine__(view);
        }
    // # __AppEditorViewsFoldedVtable_goToPrevLine__
        fn __AppEditorViewsFoldedVtable_goToPrevLine__(model: *anyopaque) callconv(.c) void {
            const view = __AppEditorViewsFoldedVtable_getModel__(model);
            __AppEditorViewsFolded_goToPrevLine__(view);
        }
    // # __AppEditorViewsFoldedVtable_goToSymbolPosX__
        fn __AppEditorViewsFoldedVtable_goToSymbolPosX__(model: *anyopaque, pos: usize) callconv(.c) void {
            const view = __AppEditorViewsFoldedVtable_getModel__(model);
            __AppEditorViewsFolded_goToSymbol__(view, pos);
        }
    // # __AppEditorViewsFoldedVtable_init__
        fn __AppEditorViewsFoldedVtable_init__(t: *c.__AppEditorViewsVTable__) void {
            t.setAsView          = @ptrCast(&__AppEditorViewsFoldedVtable_setAsView__);
            t.goToPrevLine       = @ptrCast(&__AppEditorViewsFoldedVtable_goToPrevLine__);
            t.goToNextLine       = @ptrCast(&__AppEditorViewsFoldedVtable_goToNextLine__);
            t.getOffsetX         = @ptrCast(&__AppEditorViewsFoldedVtable_getOffsetX__);
            t.getOffsetY         = @ptrCast(&__AppEditorViewsFoldedVtable_getOffsetY__);
            t.goToSymbolPosX     = @ptrCast(&__AppEditorViewsFoldedVtable_goToSymbolPosX__);
            t.getSymbolPosX      = @ptrCast(&__AppEditorViewsFoldedVtable_getSymbolPosX__);
            t.countLineNum       = @ptrCast(&__AppEditorViewsFoldedVtable_countLineNum__);
            t.goToLineFromNumber = @ptrCast(&__AppEditorViewsFoldedVtable_goToLineFromNumber__);
        }
    // # __AppEditorViewsFoldedVtable_setAsView__
        fn __AppEditorViewsFoldedVtable_setAsView__(model: *anyopaque) callconv(.c) void {
            const view = __AppEditorViewsFoldedVtable_getModel__(model);
            __AppEditorViewsFolded_setAsView__(view) catch unreachable;
            c.__app__.editor.current_vtable = &c.__AppEditorViewsVtable_folded__;
        }
    // # __AppEditorViewsFolded_CtrlShiftLeft__
        fn __AppEditorViewsFolded_CtrlShiftLeft__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const line   = t.line;
            if (line.*.text_len > 0) {
                const indent = c.__TextAscii_countIndent__(&line.*.text[0], line.*.text_len, 1);
                if (t.symbol > indent) {
                    __AppEditorViewsFolded_goToSymbol__(t, indent);
                } else { 
                    __AppEditorViewsFolded_goToStartOfLine__(t);
                }
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsFolded_CtrlShiftRight__
        fn __AppEditorViewsFolded_CtrlShiftRight__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const line = t.line;
            if (line.*.text_len > 0) {
                const indent = c.__TextAscii_countIndent__(&line.*.text[0], line.*.text_len, 1);
                if (t.symbol < indent) {
                    __AppEditorViewsFolded_goToSymbol__(t, indent);
                } else {
                    __AppEditorViewsFolded_goToEndOfLine__(t);
                }
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsFolded_Line_GetLastByte__
        fn __AppEditorViewsFolded_Line_GetLastByte__(t: *c.__AppEditorViewsFolded__, line: *c.__AppEditorLine__) callconv(.c) ?u8 { __zig_fuck__(t);
            if (line.text_len < 1) return null;
            return line.text[line.text_len - 1];
        }
    // # __AppEditorViewsFolded_Line_getFirstChildLine__
        fn __AppEditorViewsFolded_Line_getFirstChildLine__(t: *c.__AppEditorViewsFolded__, line: *c.__AppEditorLine__) callconv(.c) ?*c.__AppEditorLine__ { __zig_fuck__(t);
            const link: *c.__MemListLink__ = line.tree.childs orelse return null;
            const tree: *c.__MemTree__ = @fieldParentPtr("link", link);
            return @fieldParentPtr("tree", tree);
        }
    // # __AppEditorViewsFolded_Line_getFirstSibling__
        fn __AppEditorViewsFolded_Line_getFirstSibling__(t: *c.__AppEditorViewsFolded__, line: *c.__AppEditorLine__) callconv(.c) ?*c.__AppEditorLine__ { __zig_fuck__(t);
            // maybe return self
            const parent = __AppEditorViewsFolded_Line_getFirstChildLine__(t, line) orelse return null;
            return __AppEditorViewsFolded_Line_getFirstChildLine__(t, parent) orelse return null;
        }
    // # __AppEditorViewsFolded_Line_getNearestUncleLine__
        fn __AppEditorViewsFolded_Line_getNearestUncleLine__(t: *c.__AppEditorViewsFolded__, line: *c.__AppEditorLine__) callconv(.c) ?*c.__AppEditorLine__ {
            var current = line;
            while(true) {
                const parent = __AppEditorViewsFolded_Line_getParentLine__(t, current) orelse return null;
                const uncle = __AppEditorViewsFolded_Line_getNextLine__(t, parent) orelse {
                    current = parent;
                    continue;
                };
                return uncle;
            }
        }
    // # __AppEditorViewsFolded_Line_getNextLine__
        fn __AppEditorViewsFolded_Line_getNextLine__(t: *c.__AppEditorViewsFolded__, line: *c.__AppEditorLine__) callconv(.c) ?*c.__AppEditorLine__ { __zig_fuck__(t);
            const link: *c.__MemListLink__ = line.tree.link.next orelse return null;
            const tree: *c.__MemTree__ = @fieldParentPtr("link", link);
            return @fieldParentPtr("tree", tree);
        }
    // # __AppEditorViewsFolded_Line_getParentLine__
        fn __AppEditorViewsFolded_Line_getParentLine__(t: *c.__AppEditorViewsFolded__, line: *c.__AppEditorLine__) callconv(.c) ?*c.__AppEditorLine__ {
            if (c.__MemTree_isChild__(@ptrCast(&line.tree))) {
                var tree: *c.__MemTree__ = undefined;
                c.__MemTree_getParent__(@ptrCast(&tree), &line.tree);
                if (tree == &t.lines) return null;
                return @fieldParentPtr("tree", tree);
            }
            return null;
        }
    // # __AppEditorViewsFolded_Line_getPrevLine__
        fn __AppEditorViewsFolded_Line_getPrevLine__(t: *c.__AppEditorViewsFolded__, line: *c.__AppEditorLine__) callconv(.c) ?*c.__AppEditorLine__ {
            const link: *c.__MemListLink__ = line.tree.link.prev orelse return null;
            const tree: *c.__MemTree__ = @fieldParentPtr("link", link);
            if (tree == &t.lines) return null;
            return @fieldParentPtr("tree", tree);
        }
    // # __AppEditorViewsFolded_addIndent__
        fn __AppEditorViewsFolded_addIndent__(t: *c.__AppEditorViewsFolded__) !void {
            var ok: bool = true;
                var indent: usize = 0;
                if (t.line.*.text_len > 0) {
                    indent = c.__TextAscii_countIndent__(&t.line.*.text[0], t.line.*.text_len, 1);
                }
                if (c.__AppEditorLine_setIndent__(t.line, indent + 4)) {
                } else {
                    ok = false;
                }
                t.need_redraw = true;
            if (!ok) return error.Unexpected;
        }
    // # __AppEditorViewsFolded_addNextLine__
        fn __AppEditorViewsFolded_addNextLine__(t: *c.__AppEditorViewsFolded__) !void {
            var status = false;
            
            var new_line: *c.__AppEditorLine__ = undefined;
            if ( c.__AppEditorLine_alloc__( @ptrCast(&new_line) ) ) {
                c.__AppEditorLine_init__(new_line);
                c.__MemTree_pushNext__(&t.line.*.tree, &new_line.tree);
                __AppEditorViewsFolded_goToNextLine__(t);
                __AppEditorViewsFolded_goToStartOfText__(t);
                t.need_redraw = true;
                
                status = true;
                if (status == false) c.__AppEditorLine_free__(new_line);
            } else {
                // TODO debug
            }
            
            if (status == false) return error.Unexpected;
        }
    // # __AppEditorViewsFolded_addPrevLine__
        fn __AppEditorViewsFolded_addPrevLine__(t: *c.__AppEditorViewsFolded__) !void {
            var ok: bool = true;
            
            var new_line: *c.__AppEditorLine__ = undefined;
            if ( c.__AppEditorLine_alloc__( @ptrCast(&new_line) ) ) {
                c.__AppEditorLine_init__(new_line);
                c.__MemTree_pushPrev__(&t.line.*.tree, &new_line.tree);
                __AppEditorViewsFolded_goToPrevLine__(t);
                __AppEditorViewsFolded_goToStartOfText__(t);
                t.need_redraw = true;
                if (!ok) c.__AppEditorLine_free__(new_line);
            } else {
                ok = true;
            }
            if (!ok) return error.Unexpected;
        }
    // # __AppEditorViewsFolded_alt2__
        fn __AppEditorViewsFolded_alt2__(t: *c.__AppEditorViewsFolded__) !void {
            try __AppEditorViewsFolded_unFold__(t);
            const flat = &c.__app__.editor.views.flat;
            try __AppEditorViewsFlat_findPrev__(flat);
            try __AppEditorViewsFlat_fold__(flat);
        }
    // # __AppEditorViewsFolded_alt3__
        fn __AppEditorViewsFolded_alt3__(t: *c.__AppEditorViewsFolded__) !void {
            try __AppEditorViewsFolded_unFold__(t);
            const flat = &c.__app__.editor.views.flat;
            try __AppEditorViewsFlat_findNext__(flat);
            try __AppEditorViewsFlat_fold__(flat);
        }
    // # __AppEditorViewsFolded_bakup__
        fn __AppEditorViewsFolded_bakup__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            t.bakup_line.text_len = t.line.*.text_len;
            c.__Mem_copy__(&t.bakup_line.text[0], &t.line.*.text[0], t.line.*.text_len);
        }
    // # __AppEditorViewsFolded_clearLine__
        fn __AppEditorViewsFolded_clearLine__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            t.line.*.text_len = 0;
            __AppEditorViewsFolded_goToStartOfText__(t);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_copyWordToFind__
        fn __AppEditorViewsFolded_copyWordToFind__(t: *c.__AppEditorViewsFolded__) !void {
            if (t.line.*.text_len > 0) {
                const text = t.line.*.text[0..t.line.*.text_len];
                if (t.symbol < text.len) {
                    const sow: usize = blk: { // start_of_word
                        const buffer = t.line.*.text[0..];
                        var pos: usize = t.symbol;
                        while (true) {
                            if (pos == 0) break;
                            const prev_symbol = buffer[pos - 1];
                            if (c.__TextAscii_isLetter__(prev_symbol) == false) break;
                            pos -= 1;
                        }
                        break :blk pos;
                    };
                    const eow: usize = blk: { // end_of_word
                        const buffer = t.line.*.text[0..];
                        var pos: usize = t.symbol;
                        while (true) {
                            if (pos >= t.line.*.text_len - 1) {
                                break;
                            }
                            const next_symbol = buffer[pos + 1];
                            if (c.__TextAscii_isLetter__(next_symbol) == false) break;
                            pos += 1;
                        }
                        break :blk pos;
                    };
                    const word = t.line.*.text[sow .. eow + 1];
                    
                    c.__AppEditorLine_setText__(&c.__app__.editor.views.find.line, word.ptr, word.len);
                    
                    __AppEditor_changeStatus__(word);
                } else {
                    __AppEditor_changeStatus__("cursor not an word");
                }
                __AppEditorViewsFolded_cursorMoveToCurrent__(t) catch {};
            }
        }
    // # __AppEditorViewsFolded_correctOffsetX__
        fn __AppEditorViewsFolded_correctOffsetX__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const tsx = c.__app__.terminal.output.size.x;
            if (t.offset.x >= tsx) t.offset.x = 0;
            const predel = (tsx >> 1) - (tsx >> 4);
            if (t.symbol >= predel) t.offset.x = predel;
        }
    // # __AppEditorViewsFolded_correctOffsetY__
        fn __AppEditorViewsFolded_correctOffsetY__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const tsy = c.__app__.terminal.output.size.y;
            if (t.offset.y >= tsy) t.offset.y = 0;
            if (tsy <= 5) return;
            
            // count downest_lines
            var count_to_downest_line: usize = 0;
            var current_tree_link: *c.__MemListLink__ = &t.line.*.tree.link;
            while (count_to_downest_line < 5) {
                count_to_downest_line += 1;
                current_tree_link = current_tree_link.next orelse break;
            }
            
            if (tsy - t.offset.y < count_to_downest_line) {
                t.offset.y = tsy - count_to_downest_line;
            }
        }
    // # __AppEditorViewsFolded_countLineNum__
        fn __AppEditorViewsFolded_countLineNum__(t: *c.__AppEditorViewsFolded__) callconv(.c) usize {
            var pos: usize = 0;
            var current: *c.__MemTree__ = &t.line.*.tree;
            while (true) {
                if (c.__MemTree_isFirst__(current) == false) {
                    const prev_tree: *c.__MemTree__ = c.__MemTree_getPrev__(current);
                    pos += prev_tree.count;
                    current = prev_tree;
                    pos += 1;
                } else if (c.__MemTree_isChild__(current)) {
                    c.__MemTree_getParent__(@ptrCast(&current), current);
                    pos += 1;
                } else {
                    break;
                }
            }
            return pos;
        }
    // # __AppEditorViewsFolded_ctrlLeft__
        fn __AppEditorViewsFolded_ctrlLeft__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            __AppEditorViewsFolded_goToPrevSymbol__(t);
            if (t.symbol > 0) {
                var dest_pos: usize = 0;
                    if (t.line.*.text_len > 0) {
                        const full_text = t.line.*.text[0..t.line.*.text_len];
                        const text = full_text[0 .. t.symbol];
                        const spaces = c.__TextAscii_countIndentReverse__(text.ptr, text.len, 1);
                        if (spaces > 0) {
                            dest_pos = t.symbol - spaces;
                        } else {
                            dest_pos = c.__TextAscii_findBreakOfWordReverse__(text.ptr, text.len) + 1;
                        }
                    }
                __AppEditorViewsFolded_goToSymbol__(t, dest_pos);
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsFolded_ctrlRight__
        fn __AppEditorViewsFolded_ctrlRight__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            __AppEditorViewsFolded_goToNextSymbol__(t);
            if (t.line.*.text_len > 0) {
                const full_text = t.line.*.text[0..t.line.*.text_len];
                if (t.symbol < full_text.len) {
                    const text = full_text[t.symbol..];
                    const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                    if (indent > 0) {
                        __AppEditorViewsFolded_goToSymbol__(t, t.symbol + indent);
                        t.need_redraw = true;
                        return;
                    }
                    __AppEditorViewsFolded_goToSymbol__(t, c.__TextAscii_findBreakOfWord__(text.ptr, text.len) + t.symbol);
                    t.need_redraw = true;
                }
            }
        }
    // # __AppEditorViewsFolded_cursorMoveToCurrent__
        fn __AppEditorViewsFolded_cursorMoveToCurrent__(t: *c.__AppEditorViewsFolded__) !void {
            c.__Terminal_cursorMove__(&c.__app__.terminal, t.offset.x, t.offset.y);
        }
    // # __AppEditorViewsFolded_cut__
        fn __AppEditorViewsFolded_cut__(t: *c.__AppEditorViewsFolded__) !void {
            var ok: bool = true;
                const current_tree: *c.__MemTree__ = &t.line.*.tree;
                var next_tree: *c.__MemTree__ = select: {
                    if (@intFromPtr(current_tree.link.next) != @intFromPtr(c.NULL)) {
                        const next_link: *c.__MemListLink__ = current_tree.link.next;
                        break :select @fieldParentPtr("link", next_link);
                    } else if (@intFromPtr(current_tree.link.prev) != @intFromPtr(c.NULL)) {
                        const prev_link: *c.__MemListLink__ = current_tree.link.prev;
                        break :select @fieldParentPtr("link", prev_link);
                    } else {
                        var parent: *c.__MemTree__ = undefined;
                        c.__MemTree_getParent__(@ptrCast(&parent), current_tree);
                        break :select @ptrCast(parent);
                    }
                };
                
                if (next_tree == &t.lines) {
                    // create prev line
                    var new_empty_line: *c.__AppEditorLine__ = undefined;
                    if ( c.__AppEditorLine_alloc__( @ptrCast(&new_empty_line) ) ) {
                        c.__AppEditorLine_init__(new_empty_line);
                        c.__MemTree_pushPrev__(&t.line.*.tree, &new_empty_line.tree);
                        
                        // copy indent
                        var indent: usize = 0;
                        if (t.line.*.text_len > 0) {
                            indent = c.__TextAscii_countIndent__(&t.line.*.text[0], t.line.*.text_len, 1);
                        }
                        if (c.__AppEditorLine_setIndent__(new_empty_line, indent)) {
                            // cut current
                            c.__MemTree_pop__(&t.line.*.tree);
                            c.__MemTree_pushChild__(&t.cutted, &t.line.*.tree);
                            
                            // set as next
                            next_tree = &new_empty_line.tree;
                            
                        } else {
                            ok = false;
                        }
                    } else {
                        // TODO debug
                        ok = false;
                    }
                    
                    if (!ok) c.__AppEditorLine_free__(new_empty_line);
                }
                
                if (ok) {
                    // move to cut
                    c.__MemTree_pop__(current_tree);
                    c.__MemTree_pushChild__(&t.cutted, current_tree);
                    
                    //  update screen
                    const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", next_tree);
                    t.line = line;
                    t.need_redraw = true;
                    __AppEditorViewsFolded_bakup__(t);
                }
            if (!ok) return error.Unexpected;
        }
    // # __AppEditorViewsFolded_deleteCutted__
        fn __AppEditorViewsFolded_deleteCutted__(t: *c.__AppEditorViewsFolded__) !void {
            var tree_a: *allowzero c.__MemTree__ = c.__MemTree_traverse__(&t.cutted);
            while(@intFromPtr(tree_a) != @intFromPtr(c.NULL)) {
                if (@intFromPtr(tree_a) == @intFromPtr(&t.cutted)) unreachable;
                const tree: *c.__MemTree__ = @ptrCast(tree_a);
                const next: *allowzero c.__MemTree__ = c.__MemTree_traverse__(tree);
                
                if (tree.childs.count > 0) {
                    c.__MemTree_growChilds__(tree); // root skipped by first traverse
                }
                
                
                c.__MemTree_pop__(tree);
                
                const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", tree);
                c.__AppEditorLine_free__(line);
                
                tree_a = next;
            }
            
            // clear t.cutted
            t.cutted.childs.count = 0;
            t.cutted.childs.first = 0;
            t.cutted.childs.last  = 0;
            t.cutted.count = 0;
            
            __AppEditor_changeStatus__("cutted lines is gone :)");
        }
    // # __AppEditorViewsFolded_deleteIndent__
        fn __AppEditorViewsFolded_deleteIndent__(t: *c.__AppEditorViewsFolded__) !void {
            t.need_redraw = true;
            if(c.__AppEditorLine_setIndent__(t.line, 0) == false) return error.Unexpected;
            
            // traversal
            const start_tree = &t.line.*.tree;
            const end_tree_link = start_tree.link.next orelse return;
            const end_tree: *c.__MemTree__ = @fieldParentPtr("link", end_tree_link);
            var wlkr = start_tree.walker();
            while (wlkr.next()) |tree| {
                if (tree == end_tree) break;
                const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", tree);
                if(c.__AppEditorLine_setIndent__(line, 0) == false) return error.Unexpected;
            }
        }
    // # __AppEditorViewsFolded_deletePrevSymbol__
        fn __AppEditorViewsFolded_deletePrevSymbol__(t: *c.__AppEditorViewsFolded__, ) !void {
            if (t.symbol == 0) {
                if (t.line.*.tree.childs.count > 0) return;
                if (&t.line.*.tree.link == t.lines.childs.first) return;
                const prev_link: *c.__MemListLink__    = t.line.*.tree.link.prev orelse return;
                const prev_tree: *c.__MemTree__        = @fieldParentPtr("link", prev_link);
                const prev_line: *c.__AppEditorLine__  = @fieldParentPtr("tree", prev_tree);
                
                // maybe just delete current line?
                const current_line_non_indent: usize = blk: {
                    var indent: usize = 0;
                    if (t.line.*.text_len > 0){
                        indent = c.__TextAscii_countNonIndent__(&t.line.*.text[0], t.line.*.text_len);
                    }
                    break :blk indent;
                };
                if (current_line_non_indent == 0) { // delete t line
                    const line_to_delete: *c.__AppEditorLine__ = t.line;
                    const tree_to_delete: *c.__MemTree__       = &line_to_delete.tree;
                    c.__MemTree_pop__(tree_to_delete);
                    c.__AppEditorLine_free__(line_to_delete);
                    t.line = prev_line;
                    t.need_redraw = true;
                    __AppEditorViewsFolded_goToEndOfLine__(t);
                    return;
                }
                
                // or just delete prev line
                const prev_non_indent: usize = blk: {
                    var indent: usize = 0;
                    if (prev_line.text_len > 0) {
                        indent = c.__TextAscii_countNonIndent__(&prev_line.text[0], prev_line.text_len);
                    }
                    break :blk indent;
                };
                if (prev_non_indent == 0) {
                    c.__MemTree_pop__(&prev_line.tree);
                    c.__AppEditorLine_free__(prev_line);
                    t.need_redraw = true;
                    return;
                }
            } else if (t.symbol > t.line.*.text_len) {
                __AppEditorViewsFolded_goToPrevSymbol__(t);
            } else {
                if (t.line.*.text_len == 0) return;
                __AppEditorViewsFolded_goToPrevSymbol__(t);
                __AppEditorViewsFolded_deleteSymbol__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_deleteSymbol__
        fn __AppEditorViewsFolded_deleteSymbol__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            if (t.line.*.text_len == 0) return;
            
            if (c.__Buffer_pop_check__(t.line.*.text_len, t.symbol)) {
                _=c.__Buffer_pop__(&t.line.*.text[0], &t.line.*.text_len, t.symbol);
            }
            
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_deleteWord__
        fn __AppEditorViewsFolded_deleteWord__(t: *c.__AppEditorViewsFolded__) !void {
            if (t.symbol > t.line.*.text_len) {
                return;
            }
            while (true) { // delete current symbol
                if (t.symbol == t.line.*.text_len) {
                    break;
                }
                const next_symbol = t.line.*.text[t.symbol];
                if (c.__TextAscii_isLetter__(next_symbol)) {
                    __AppEditorViewsFolded_deleteSymbol__(t);
                } else {
                    break;
                }
            }
            while (true) { // delete prev    symbol
                if (t.symbol == 0) {
                    break;
                }
                const prev_symbol = t.line.*.text[t.symbol - 1];
                if (c.__TextAscii_isLetter__(prev_symbol)) {
                    try __AppEditorViewsFolded_deletePrevSymbol__(t);
                } else {
                    break;
                }
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_divide__
        fn __AppEditorViewsFolded_divide__(t: *c.__AppEditorViewsFolded__) !void {
            try __AppEditorViewsFolded_unFold__(t);
            const flat = &c.__app__.editor.views.flat;
            try __AppEditorViewsFlat_divideLine__(flat);
        }
    // # __AppEditorViewsFolded_doWrap__
        fn __AppEditorViewsFolded_doWrap__(ctx: *anyopaque) !void {
            const t = __AppEditorViewsFoldedVtable_getModel__(ctx);
            
            if (t.need_redraw == true) {
                t.need_redraw = false;
                __AppEditorViewsFolded_draw__(t) catch unreachable;
                __AppEditorViewsFolded_cursorMoveToCurrent__(t) catch unreachable;
            }
            
            if (t.need_draw_line_num) {
                t.need_draw_line_num = false;
                try __AppEditorViewsFolded_drawCountLineNum__(t);
                __AppEditorViewsFolded_cursorMoveToCurrent__(t) catch unreachable;
            }
        }
    // # __AppEditorViewsFolded_do__
        fn __AppEditorViewsFolded_do__(ctx: *anyopaque) callconv(.c) void {
            __AppEditorViewsFolded_doWrap__(ctx) catch unreachable;
        }
    // # __AppEditorViewsFolded_drawCountLineNum__
        fn __AppEditorViewsFolded_drawCountLineNum__(t: *c.__AppEditorViewsFolded__) !void {
            const pos = __AppEditorViewsFolded_countLineNum__(t);
            c.__Terminal_cursorMove__(&c.__app__.terminal, 0, c.__app__.terminal.output.size.y - 1);
            c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_notification__, c.__AppEditorTheme_notification__.len);
            // print("line number = {pos}");
                const tt: []const u8 = "line_number = ";
                c.__Terminal_writeToOutput__(&c.__app__.terminal, tt.ptr, tt.len);
                
                _=c.__Text_formatU64__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, pos, 1);
            c.__Terminal_resetColors__(&c.__app__.terminal);
            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
            try __AppEditorViewsFolded_cursorMoveToCurrent__(t);
            t.need_redraw = false;
        }
    // # __AppEditorViewsFolded_drawDownerLines__
        fn __AppEditorViewsFolded_drawDownerLines__(t: *c.__AppEditorViewsFolded__) !void {
            var pos_y: usize = t.offset.y + 1;
            c.__app__.editor.lines_drawing = pos_y;
            if (pos_y >= c.__app__.terminal.output.size.y) return;
            var current_tree = &t.line.*.tree;
            while (true) { // draw lines
                c.__Terminal_resetColors__(&c.__app__.terminal);
                const next_tree_link: *c.__MemListLink__ = current_tree.link.next orelse break;
                const next_tree: *c.__MemTree__ = @fieldParentPtr("link", next_tree_link);
                const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", next_tree);
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                try __AppEditorViewsFolded_drawLine__(t, line);
                if (pos_y >= c.__app__.terminal.output.size.y - 1) {
                    c.__app__.editor.lines_drawing = c.__app__.terminal.output.size.y;
                    return;
                }
                pos_y += 1;
                current_tree = next_tree;
            }
            c.__app__.editor.lines_drawing = pos_y;
            c.__Terminal_resetColors__(&c.__app__.terminal);
            while (true) { // clear other downer lines
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                c.__Console_clearLine__(&c.__app__.console);
                if (pos_y >= c.__app__.terminal.output.size.y - 1) return;
                pos_y += 1;
            }
        }
    // # __AppEditorViewsFolded_drawEditedLine__
        fn __AppEditorViewsFolded_drawEditedLine__(t: *c.__AppEditorViewsFolded__) !void {
            const line = t.line;
            c.__Terminal_cursorMove__(&c.__app__.terminal, 0, t.offset.y);
            // reset color and bold
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_reset__, c.__AppEditorTheme_reset__.len);
                c.__Terminal_resetColors__(&c.__app__.terminal);
            
            if (line.*.text_len > 0) {
                const text = line.*.text[0 .. line.*.text_len];
                try __AppEditorViewsFolded_drawLine__(t, line);
                const screen_start: usize = t.symbol - t.offset.x; // first visible rune
                const screen_end:   usize = screen_start + c.__app__.terminal.output.size.x;
                // draw fold indicator
                    if (t.line.*.tree.childs.count > 0) {
                        c.__Terminal_cursorMove__(&c.__app__.terminal, 0, t.offset.y);
                        var symbol: u8 = ' ';
                        if (screen_start < text.len) {
                            symbol = text[screen_start];
                        }
                        c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_folded__, c.__AppEditorTheme_folded__.len);
                        c.__Terminal_writeToOutput__(&c.__app__.terminal, &symbol, 1);
                    }
                // draw left arrow '<'
                    if (screen_start != 0) { // this means cursor_pos.x > 0
                        c.__Terminal_cursorMove__(&c.__app__.terminal, 0, t.offset.y);
                        if (t.line.*.tree.childs.count > 0) {
                            c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_folded_arrows__, c.__AppEditorTheme_folded_arrows__.len);
                        } else {
                            c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_arrows__, c.__AppEditorTheme_arrows__.len);
                        }
                        c.__Terminal_writeToOutput__(&c.__app__.terminal, "<", 1);
                    }
                // draw right arrow '>'
                    if (screen_end < text.len) {
                        c.__Terminal_cursorMove__(&c.__app__.terminal, c.__app__.terminal.output.size.x - 1, t.offset.y);
                        c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_arrows__, c.__AppEditorTheme_arrows__.len);
                        c.__Terminal_writeToOutput__(&c.__app__.terminal, ">", 1);
                    }
                // current symbol
                    c.__Terminal_cursorMove__(&c.__app__.terminal, t.offset.x, t.offset.y);
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_current_rune__, c.__AppEditorTheme_current_rune__.len);
                    if (t.symbol < text.len) {
                        c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[t.symbol], 1);
                    } else {
                        c.__Terminal_writeToOutput__(&c.__app__.terminal, " ", 1);
                    }
            } else {
                c.__Terminal_resetColors__(&c.__app__.terminal);
                c.__Console_clearLine__(&c.__app__.console);
            }
        }
    // # __AppEditorViewsFolded_drawLine__
        fn __AppEditorViewsFolded_drawLine__(t: *c.__AppEditorViewsFolded__, line: *c.__AppEditorLine__) !void {
            const screen_start: usize = t.symbol - t.offset.x; // first visible rune
            const screen_end:   usize = screen_start + c.__app__.terminal.output.size.x;
            // draw left-to-right from first visible rune
            c.__Terminal_moveCursorToStartOfLine__(&c.__app__.terminal);
            // reset color and bold
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_reset__, c.__AppEditorTheme_reset__.len);
                c.__Terminal_resetColors__(&c.__app__.terminal);
            if (line.text_len > screen_start) {
                const text = line.text[0 .. line.text_len];
                var visible_text_ptr: [*c]const u8 = undefined; _=&visible_text_ptr;
                var visible_text_len: usize = undefined; _=&visible_text_len;
                if (c.__TextAscii_getNonIndent__(&visible_text_ptr, &visible_text_len, text.ptr, text.len)) {
                    const visible_text: []const u8 = visible_text_ptr[0..visible_text_len];
                    if (text.len > screen_start) {
                        const text_end = if (text.len > screen_end) screen_end else text.len;
                        const draw_len = text_end - screen_start; 
                        // bold if childs
                            if (line.tree.childs.count > 0) {
                                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_folded__, c.__AppEditorTheme_folded__.len);
                            } 
                        var is_comment: usize = 0;
                            if (false
                                or std.mem.startsWith(u8, visible_text, "# ")
                                or std.mem.startsWith(u8, visible_text, "// ")
                                or std.mem.startsWith(u8, visible_text, "; ")
                                or std.mem.startsWith(u8, visible_text, "-- ")
                            ) { // if is commentary
                                is_comment = 1;
                            } else if (false 
                                or std.mem.startsWith(u8, visible_text, "#")
                                or std.mem.startsWith(u8, visible_text, "//")
                                or std.mem.startsWith(u8, visible_text, ";")
                                or std.mem.startsWith(u8, visible_text, "--")
                            ) { // if is disabled commentary
                                is_comment = 2;
                            }
                        // draw text
                            // const to_draw = text[screen_start..text_end];
                            // c.__Terminal_writeToOutput__(&c.__app__.terminal, to_draw.ptr, to_draw.len);
                            
                            if (is_comment == 2) {
                                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_disabled__, c.__AppEditorTheme_disabled__.len);
                                const draw_ptr = &text[screen_start];
                                c.__Terminal_writeToOutput__(&c.__app__.terminal, draw_ptr, draw_len);
                            } else if (is_comment == 1) {
                                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_commentary__, c.__AppEditorTheme_commentary__.len);
                                const draw_ptr = &text[screen_start];
                                c.__Terminal_writeToOutput__(&c.__app__.terminal, draw_ptr, draw_len);
                            } else { // coloring ^_^
                                var color: [5]u8 = "\x1B[90m".*;
                                var last_pos:  usize = 0;
                                var pos:       usize = 0;
                                var hash_summ: u8    = 0;
                                var last_symbol_is_word: bool = false;
                                while (pos < draw_len) {
                                    const symbol: u8 = text[screen_start + pos];
                                    if (c.__TextAsciiSymbol_isWordSymbol__(symbol)) {
                                        if (last_symbol_is_word == false) {
                                            last_symbol_is_word = true;
                                            
                                            color[3] = '0' + ((hash_summ & 0b111));
                                            c.__Terminal_setFontStyle__(&c.__app__.terminal, &color[0], color.len);
                                            c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[screen_start + last_pos], pos - last_pos);
                                            last_pos  = pos;
                                            hash_summ = 0;
                                        }
                                        
                                        hash_summ +%= symbol;
                                        pos += 1;
                                    } else {
                                        color[3] = '0' + ((hash_summ & 0b111));
                                        c.__Terminal_setFontStyle__(&c.__app__.terminal, &color[0], color.len);
                                        c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[screen_start + last_pos], pos - last_pos);
                                        last_pos  = pos;
                                        
                                        hash_summ = symbol;
                                        pos += 1;
                                        
                                        if (false) { // spaces
                                            if (symbol == ' ') {
                                                while(pos < draw_len-1) {
                                                    if (text[screen_start + pos+1] != ' ') {
                                                        break;
                                                    }
                                                    pos += 1;
                                                }
                                            }
                                            c.__Terminal_setFontStyle__(&c.__app__.terminal, &color[0], color.len);
                                            c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[screen_start + last_pos], pos - last_pos);
                                            last_pos = pos;
                                        }
                                        last_symbol_is_word = false;
                                    }
                                }
                                if (last_pos < draw_len) {
                                    color[3] = '0' + (hash_summ & 0b111);
                                    c.__Terminal_setFontStyle__(&c.__app__.terminal, &color[0], color.len);
                                    c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[screen_start + last_pos], draw_len - last_pos);
                                }
                            }
                    } else {
                        // draw "#" if childs
                        if (line.tree.childs.count > 0) {
                            c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_folded__, c.__AppEditorTheme_folded__.len);
                            c.__Terminal_writeToOutput__(&c.__app__.terminal, "#", 1);
                        } 
                    }
                }
                // clear other
                    c.__Terminal_resetColors__(&c.__app__.terminal);
                    _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
                // draw folded indicator
                    if (line.tree.childs.count > 0) {
                        c.__Terminal_moveCursorToStartOfLine__(&c.__app__.terminal);
                        c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_folded__, c.__AppEditorTheme_folded__.len);
                        var symbol: u8 = '>';
                        if (text.len > screen_start) symbol = text[screen_start];
                        c.__Terminal_writeToOutput__(&c.__app__.terminal, &symbol, 1);
                    }
                // reset color and bold
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_reset__, c.__AppEditorTheme_reset__.len);
                    c.__Terminal_resetColors__(&c.__app__.terminal);
            } else {
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
            }
        }
    // # __AppEditorViewsFolded_drawParentLine__
        fn __AppEditorViewsFolded_drawParentLine__(t: *c.__AppEditorViewsFolded__, parent: *c.__AppEditorLine__) !void {
            c.__Terminal_moveCursorToStartOfLine__(&c.__app__.terminal);
            if (parent.text_len > 0) {
                const text = parent.text[0.. parent.text_len];
                const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                var symbol: usize = indent;
                if (indent >= t.symbol - t.offset.x) {
                    symbol = t.symbol - t.offset.x;
                }
                var offset_x: usize = 0;
                while (true) {
                    if (symbol >= text.len) {
                        _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
                        break;
                    }
                    if (offset_x >= c.__app__.terminal.output.size.x - 2) break;
                    c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[symbol], 1);
                    
                    symbol += 1;
                    offset_x += 1;
                }
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
            } else {
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
            }
        }
    // # __AppEditorViewsFolded_drawUpperLines__
        fn __AppEditorViewsFolded_drawUpperLines__(t: *c.__AppEditorViewsFolded__) !void {
            const nested = t.line.*.tree.nested;
            
            if (t.offset.y == 0) return;
            var pos_y: usize = t.offset.y - 1;
            var current_tree = &t.line.*.tree;
            c.__Terminal_resetColors__(&c.__app__.terminal);
            while (true) { // draw lines
                // draw upper arrow
                const term_1_3 = (c.__app__.terminal.output.size.y >> 3) * 3;
                const upperest_line = if (nested > term_1_3) term_1_3 else nested;
                if (t.offset.y > upperest_line and pos_y < upperest_line) {
                    c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y + 1);
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_commentary__, c.__AppEditorTheme_commentary__.len);
                    c.__Terminal_writeToOutput__(&c.__app__.terminal, "^", 1);
                    break;
                }
                
                //
                const prev_tree_link: *c.__MemListLink__ = current_tree.link.prev orelse break;
                const prev_tree:      *c.__MemTree__       = @fieldParentPtr("link", prev_tree_link);
                const line:           *c.__AppEditorLine__       = @fieldParentPtr("tree", prev_tree);
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                try __AppEditorViewsFolded_drawLine__(t, line);
                if (pos_y == 0) return;
                pos_y -= 1;
                current_tree = prev_tree;
            }
            
            // draw headers (parents)
            c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_headers__, c.__AppEditorTheme_headers__.len);
            while (c.__MemTree_isChild__(current_tree)) {
                var parent_tree: *c.__MemTree__ = undefined;
                c.__MemTree_getParent__(@ptrCast(&parent_tree), current_tree);
                if (parent_tree == &t.lines) break;
                const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", parent_tree);
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                try __AppEditorViewsFolded_drawParentLine__(t, line);
                if (pos_y == 0) return;
                pos_y -= 1;
                current_tree = parent_tree;
            }
            
            // clear other up lines
            c.__Terminal_resetColors__(&c.__app__.terminal);
            while (true) {
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                c.__Console_clearLine__(&c.__app__.console);
                if (pos_y == 0) return;
                pos_y -= 1;
            }
        }
    // # __AppEditorViewsFolded_draw__
        fn __AppEditorViewsFolded_draw__(t: *c.__AppEditorViewsFolded__) !void {
            defer __AppEditorViewsFolded_cursorMoveToCurrent__(t) catch {};
            
            __AppEditorViewsFolded_correctOffsetX__(t);
            __AppEditorViewsFolded_correctOffsetY__(t);
            if (t.symbol < t.offset.x) { // unexpected
                unreachable;
                //t.offset.x = 0;
                //t.symbol = 0;
            }
            c.__ConsoleOutput_cursorHide__(&c.__app__.console.output);
            defer c.__Console_showCursor__(&c.__app__.console);
            
            // draw edit line
            try __AppEditorViewsFolded_drawEditedLine__(t);
            
            // draw other lines
            if (c.__app__.terminal.output.size.y <= 1) return;
            try __AppEditorViewsFolded_drawUpperLines__(t);
            try __AppEditorViewsFolded_drawDownerLines__(t);
        }
    // # __AppEditorViewsFolded_duplicateAndCut__
        fn __AppEditorViewsFolded_duplicateAndCut__(t: *c.__AppEditorViewsFolded__) !void {
            try __AppEditorViewsFolded_duplicate__(t);
            try __AppEditorViewsFolded_cut__(t);
            __AppEditor_changeStatus__("copied.");
        }
    // # __AppEditorViewsFolded_duplicate__
        fn __AppEditorViewsFolded_duplicate__(t: *c.__AppEditorViewsFolded__) !void {
            // copy roots
            const copy_line = try __AppEditorViewsFolded_duplicate_line__(t.line);
            const copy_root = &copy_line.tree;
            c.__MemTree_pushNext__(&t.line.*.tree, copy_root);
            
            // copy trees
            var current_tree: *c.__MemTree__ = &t.line.*.tree;
            var copy_tree: *c.__MemTree__ = copy_root;
            while (true) {
                if (@intFromPtr(current_tree.childs.first) != @intFromPtr(c.NULL)) {
                    const child_link: *c.__MemListLink__ = current_tree.childs.first;
                    
                    // duplicate
                    const child_tree: *c.__MemTree__ = @fieldParentPtr("link", child_link);
                    const child_line: *c.__AppEditorLine__ = @fieldParentPtr("tree", child_tree);
                    const copy_child_line = try __AppEditorViewsFolded_duplicate_line__(child_line);
                    
                    // place
                    const copy_child_tree = &copy_child_line.tree;
                    c.__MemTree_pushChild__(copy_tree, copy_child_tree);
                    
                    // update currents
                    current_tree = child_tree;
                    copy_tree = copy_child_tree;
                } else if (@intFromPtr(current_tree.link.next) != @intFromPtr(c.NULL)) {
                    const next_link: *c.__MemListLink__ = current_tree.link.next;
                    const next_tree: *c.__MemTree__ = @fieldParentPtr("link", next_link);
                    if (next_tree == copy_root) break;
                    
                    // duplicate
                    const next_line: *c.__AppEditorLine__ = @fieldParentPtr("tree", next_tree);
                    const copy_next_line = try __AppEditorViewsFolded_duplicate_line__(next_line);
                    
                    // place
                    const copy_next_tree = &copy_next_line.tree;
                    c.__MemTree_pushNext__(copy_tree, copy_next_tree);
                    
                    // update currents
                    current_tree = next_tree;
                    copy_tree = copy_next_tree;
                } else { // find parent with next
                    
                    // find parent with next
                    var next_tree: *c.__MemTree__ = copy_root;
                    while (true) {
                        if (@intFromPtr(current_tree.link.next) != @intFromPtr(c.NULL)) {
                            const next_link: *c.__MemListLink__ = current_tree.link.next;
                            next_tree = @fieldParentPtr("link", next_link);
                            break;
                        }
                        
                        if (c.__MemTree_isChild__(current_tree)) {
                            c.__MemTree_getParent__(@ptrCast(&current_tree), current_tree);
                            c.__MemTree_getParent__(@ptrCast(&copy_tree),    copy_tree);
                        } else {
                            break;
                        }
                    }
                    if (next_tree == copy_root) break;
                    
                    // duplicate
                    const next_line: *c.__AppEditorLine__ = @fieldParentPtr("tree", next_tree);
                    const copy_next_line = try __AppEditorViewsFolded_duplicate_line__(next_line);
                    
                    // place
                    const copy_next_tree = &copy_next_line.tree;
                    c.__MemTree_pushNext__(copy_tree, copy_next_tree);
                    
                    // update currents
                    current_tree = next_tree;
                    copy_tree = copy_next_tree;
                }
            }
            
            // update current working line and screen
            t.line = copy_line;
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_duplicate_line__
        fn __AppEditorViewsFolded_duplicate_line__(line: *c.__AppEditorLine__) !*c.__AppEditorLine__ {
            var new_line: *c.__AppEditorLine__ = undefined;
            if (c.__AppEditorLine_alloc__( @ptrCast(&new_line) ) ) {
                c.__AppEditorLine_init__(new_line);
                if (line.text_len > 0) {
                    const old_text = line.text[0 .. line.text_len];
                    c.__AppEditorLine_setText__(new_line, old_text.ptr, old_text.len);
                }
                return new_line;
                // if (status == false) c.__AppEditorLine_free__(new_line);
            } else {
                return error.LineNotAllocated;
            }
        }
    // # __AppEditorViewsFolded_easyMotionH__
        fn __AppEditorViewsFolded_easyMotionH__(t: *c.__AppEditorViewsFolded__) !void {
            __AppEditorViewsEasyMotionHorizontal_setAsView__(t, &c.__AppEditorViewsVtable_folded__);
        }
    // # __AppEditorViewsFolded_easyMotionV__
        fn __AppEditorViewsFolded_easyMotionV__(t: *c.__AppEditorViewsFolded__) !void {
            __AppEditorViewsEasyMotionVertical_setAsView__(t, &c.__AppEditorViewsVtable_folded__);
        }
    // # __AppEditorViewsFolded_externalCopy__
        fn __AppEditorViewsFolded_externalCopy__(t: *c.__AppEditorViewsFolded__) !void {
            const path_len    = c.__app__.editor.__AppEditor_pathToClipboard_len__;
            const path_buffer = c.__app__.editor.__AppEditor_pathToClipboard__;
            const path_slice  = path_buffer[0..path_len];
            const path        = &c.__app__.editor.__AppEditor_pathToClipboard__[0];
             
            const tree     = &t.cutted;
            if (t.cutted.childs.count > 0) {
                try __AppEditorViewsFolded_saveTreeToFile__(tree, path_slice, .skip_root);
                t.need_redraw = false;
                // print "saved to {clipboard}"
                    var buffer: [1024]u8 = undefined;
                    var writed: usize    = 0;
                    writed += __zig_writeToBuffer__(&buffer[writed], "clipboard saved to ");
                    c.__Mem_copy__(&buffer[writed], path, path_len);
                        writed += path_len;
                    __AppEditor_changeStatus__(buffer[0..writed]);
            } else {
                try __AppEditorViewsFolded_saveTreeToFile__(tree, path_slice, .not_skip_root);
                // print "saved to {clipboard}"
                    var buffer: [1024]u8 = undefined;
                    var writed: usize    = 0;
                    writed += __zig_writeToBuffer__(&buffer[writed], "clipboard saved to ");
                    c.__Mem_copy__(&buffer[writed], path, path_len);
                        writed += path_len;
                    __AppEditor_changeStatus__(buffer[0..writed]);
            }
            t.need_redraw = false;
        }
    // # __AppEditorViewsFolded_externalPaste__
        fn __AppEditorViewsFolded_externalPaste__(t: *c.__AppEditorViewsFolded__) !void {
            var ok: bool = true;
            
            // read file
            const path     = &c.__app__.editor.__AppEditor_pathToClipboard__[0];
            const path_len = c.__app__.editor.__AppEditor_pathToClipboard_len__;
            var file: c.__OsFileHandle__ = undefined;
            if (c.__OsFile_open__(&file, path, path_len)) {
                // read file
                    const file_size: usize  = c.__OsFile_getSize__(file);
                    var   file_data: [*c]u8 = undefined;
                    if (c.__OsMem_allocAny__(&file_data, file_size)) {
                        if (c.__OsFile_readToBuffer__(file, file_data, file_size, 0)) {
                            // paste
                            const line = t.line;
                            try __AppEditorViewsFolded_addPrevLine__(t);
                            for (file_data[0..file_size]) |rune| { // parse lines
                                switch (rune) {
                                    13     => {},
                                    10     => {try __AppEditorViewsFolded_addNextLine__(t); },
                                    else   => {try __AppEditorViewsFolded_insertSymbol__(t, rune); },
                                }
                            }
                            t.line = line;
                            t.need_redraw = true;
                        } else {
                            ok = false;
                        }
                        
                        c.__OsMem_freeAny__(file_data);
                    } else {
                        ok = false;
                    }
                    
                c.__OsFile_close__(file);
            } else {
                ok = false;
            }
            
            if (!ok) {
                t.need_redraw = false;
                
                // print error
                    { // moving cursor
                        c.__Terminal_cursorMove__(&c.__app__.terminal, 0, 0);
                        { // set text color
                            c.__Terminal_resetColors__(&c.__app__.terminal);
                            c.__Terminal_setFontStyle__(
                                &c.__app__.terminal, 
                                c.__AppEditorTheme_notification__,
                                c.__AppEditorTheme_notification__.len
                            );
                            
                            { // write text
                                const tt: []const u8 = " file ~/clipboard.tmp not reedable.";
                                c.__Terminal_writeToOutput__(&c.__app__.terminal, tt.ptr, tt.len);
                            }
                            
                            c.__Terminal_resetColors__(&c.__app__.terminal);
                        }
                    }
                    _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
            }
            
            if (!ok) return error.Unexpected;
        }
    // # __AppEditorViewsFolded_findNext__
        fn __AppEditorViewsFolded_findNext__(t: *c.__AppEditorViewsFolded__) !void {
            const finding_text: []const u8 = c.__app__.editor.views.find.get() orelse return;
            if (finding_text.len == 0) {
                var finded = true;
                if (t.line.text_len > 0) { // try find on current line
                    const text = t.line.text[0 .. t.line.text_len];
                    if (t.symbol + 1 <= text.len) {
                        const data:     [*]const u8 = &text[t.symbol + 1];
                        const data_len: usize       = text.len - (t.symbol + 1);
                        const pos:      usize       = 0;
                        if (data_len >= finding_text.len and c.__Mem_findFast__(&pos, data, data_len, finding_text.ptr, finding_text.len)) {
                            finded = true;
                            __AppEditorViewsFolded_goToSymbol__(t, t.symbol + pos + 1);
                        }
                    }
                }
                
                if (finded == false) { // find on next lines
                    var maybe_current: *allowzero c.__MemTree__ = c.__MemTree_traverse__(&t.line.*.tree);
                    while (@intFromPtr(maybe_current) != 0) {
                        {
                            const current:   *c.__MemTree__        = maybe_current.?;
                            const line:      *c.__AppEditorLine__  = @fieldParentPtr("tree", current);
                            if (line.text_len > 0) {
                                const line_text: []const u8   = line.text[0 .. line.text_len];
                                const pos:       usize        = 0;
                                if (line_text.len >= finding_text.len and c.__Mem_findFast__(&pos, line_text.ptr, line_text.len, finding_text.ptr, finding_text.len)) {
                                    t.line = line;
                                    t.need_redraw = true;
                                    t.offset.y = (c.__app__.terminal.output.size.y >> 1) + (c.__app__.terminal.output.size.y >> 3);
                                    __AppEditorViewsFolded_goToSymbol__(t, pos);
                                    finded = true;
                                    break;
                                }
                            }
                        }
                        
                        maybe_current = c.__MemTree_traverse__(maybe_current);
                    }
                }
                if (finded) {
                    t.need_redraw = true;
                    t.bakup();
                    try __AppEditorViewsFolded_draw__(t);
                    try __AppEditorViewsFolded_drawCountLineNum__(t);
                }
            }
        }
    // # __AppEditorViewsFolded_findPrev__
        fn __AppEditorViewsFolded_findPrev__(t: *c.__AppEditorViewsFolded__) !void {
            const find_line = &c.__app__.editor.views.find.text;
            if (find_line.text_len > 0) {
                const finding_text: []const u8 = find_line.text[0 .. find_line.text_len];
                { // find_on_current_line
                    if (t.line.text_len > 0) {
                        const current_text: []const u8 = t.line.text[0 .. t.line.text_len];
                        if (t.symbol > current_text.len) t.goToSymbol(finding_text.len);
                        var pos: usize = 0;
                        if (t.symbol >= finding_text.len and c.__mem_findFastReverse__(&pos, current_text.ptr, t.symbol, finding_text.ptr, finding_text.len)) {
                            __AppEditorViewsFolded_goToSymbol__(t, pos);
                            __AppEditorViewsFolded_bakup__(t);
                            t.need_redraw = true;
                            t.need_draw_line_num = true;
                            return;
                        }
                    }
                }
                
                var current = &t.line.*.tree;
                while (true) {
                    const prev_link = current.link.prev orelse return;
                    const prev_tree: *c.__MemTree__ = @fieldParentPtr("link", prev_link);
                    current = prev_tree;
                    
                    const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", current);
                    if (line.text_len > 0) {
                        const line_text = line.text[0..line.text_len];
                        var pos: usize = 0;
                        if (line_text.len >= finding_text and c.__mem_findFastReverse__(&pos, line_text.ptr, line_text.len, finding_text.ptr, finding_text.len)) {
                            t.line = line;
                            t.need_redraw = true;
                            t.goToSymbol(pos);
                            break;
                        }
                    }
                }
                t.bakup();
                try t.draw();
                try t.drawCountLineNum();
            }
        }
    // # __AppEditorViewsFolded_fixIndent__
        fn __AppEditorViewsFolded_fixIndent__(t: *c.__AppEditorViewsFolded__, first_line: *c.__AppEditorLine__, indent_delta: isize) !void {
            if (indent_delta == 0) return;
            t.need_redraw = true;
            
            const end_tree: ?*c.__MemTree__ = blk: {
                if (__AppEditorViewsFolded_Line_getNextLine__(t, first_line)) |next_line| { 
                    break: blk &next_line.tree;
                } else if (__AppEditorViewsFolded_Line_getNearestUncleLine__(t, first_line)) |uncle_line| { 
                    break: blk &uncle_line.tree;
                }
                break: blk null;
            };
            
            var maybe_tree: ?*c.__MemTree__ = &first_line.tree;
            while (maybe_tree) |tree| {
                if (tree == end_tree) break;
                const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", tree);
                
                // count indents
                var current_indent: usize = 0;
                if (line.text_len > 0) {
                    const line_text = line.text[0..line.text_len];
                    current_indent = c.__TextAscii_countIndent__(line_text.ptr, line_text.len, 1);
                }
                const new_indent: usize = blk: {
                    if (indent_delta > 0) {
                        break: blk current_indent + @as(usize, @intCast(indent_delta));
                    } else { // indent_delta < 0
                        const abs_delta: usize = @intCast(indent_delta * -1);
                        if (abs_delta > current_indent) {
                            break: blk 0;
                        } else { // abs_delta <= current_indent
                            break: blk current_indent - abs_delta;
                        }
                    }
                };
                
                if (c.__AppEditorLine_setIndent__(line, new_indent) == false) return error.Unexpected;
                maybe_tree = c.__MemTree_traverse__(tree);
            }
        }
    // # __AppEditorViewsFolded_goToEndOfLine__
        fn __AppEditorViewsFolded_goToEndOfLine__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            t.symbol = t.line.*.text_len;
            if (t.symbol > c.__app__.terminal.output.size.x - 2) {
                t.offset.x = c.__app__.terminal.output.size.x - 2;
            } else {
                t.offset.x = t.symbol;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_goToFirstLine__
        fn __AppEditorViewsFolded_goToFirstLine__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const current = &t.line.*.tree;
            if (c.__MemTree_isChild__(current)) {
                var   parent: *c.__MemTree__       = undefined;
                    c.__MemTree_getParent__(@ptrCast(&parent), current);
                const list:   *c.__MemList__       = &parent.childs;
                const link:   *c.__MemListLink__   = list.first orelse unreachable;
                const tree:   *c.__MemTree__       = @fieldParentPtr("link", link);
                const line:   *c.__AppEditorLine__ = @fieldParentPtr("tree", tree);
                
                t.line = line;
                __AppEditorViewsFolded_goToStartOfText__(t);
                t.offset.y = (c.__app__.terminal.output.size.y >> 1) - (c.__app__.terminal.output.size.y >> 2);
                t.need_redraw = true;
                __AppEditorViewsFolded_bakup__(t);
            }
        }
    // # __AppEditorViewsFolded_goToIn__
        fn __AppEditorViewsFolded_goToIn__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const child_tree_link: *c.__MemListLink__ = t.line.*.tree.childs.first orelse return;
            const child_tree: *c.__MemTree__ = @fieldParentPtr("link", child_tree_link);
            const child: *c.__AppEditorLine__ = @fieldParentPtr("tree", child_tree);
            
            t.line = child;
            
            var child_indent: usize = 0;
            if (child.text_len > 0) {
                const text = child.text[0..child.text_len];
                child_indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
            }
            __AppEditorViewsFolded_goToSymbol__(t, child_indent);
            
            t.offset.y = (c.__app__.terminal.output.size.y >> 1) - (c.__app__.terminal.output.size.y >> 3);
            __AppEditorViewsFolded_bakup__(t);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_goToLastLine__
        fn __AppEditorViewsFolded_goToLastLine__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const current = &t.line.*.tree;
            if (c.__MemTree_isChild__(current)) {
                var   parent: *c.__MemTree__       = undefined;
                    c.__MemTree_getParent__(@ptrCast(&parent), current);
                const list:   *c.__MemList__       = &parent.childs;
                const link:   *c.__MemListLink__   = list.last orelse unreachable;
                const tree:   *c.__MemTree__       = @fieldParentPtr("link", link);
                const line:   *c.__AppEditorLine__ = @fieldParentPtr("tree", tree);
                
                t.line = line;
                __AppEditorViewsFolded_goToStartOfText__(t);
                t.offset.y = (c.__app__.terminal.output.size.y >> 1) + (c.__app__.terminal.output.size.y >> 2);
                t.need_redraw = true;
                __AppEditorViewsFolded_bakup__(t);
            }
        }
    // # __AppEditorViewsFolded_goToLineFromNumber__
        fn __AppEditorViewsFolded_goToLineFromNumber__(t: *c.__AppEditorViewsFolded__, _num: usize) callconv(.c) void {
            switch (_num) {
                0 => {
                    return;
                },
                
                1 => {
                    const first_link: *c.__MemListLink__ = t.lines.childs.first.?;
                    const tree_link: *c.__MemTree__ = @fieldParentPtr("link", first_link);
                    const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", tree_link);
                    t.line = line;
                    if (t.line.*.text_len > 0) {
                        const text = t.line.*.text[0..t.line.*.text_len];
                        __AppEditorViewsFolded_goToSymbol__(t, c.__TextAscii_countIndent__(text.ptr, text.len, 1));
                    } else {
                        __AppEditorViewsFolded_goToSymbol__(t, 0);
                    }
                },
                
                else => {
                    var pos: usize = 1;
                    const first_link: *c.__MemListLink__ = t.lines.childs.first.?;
                    var current: *c.__MemTree__ = @fieldParentPtr("link", first_link);
                    while (true) {
                        if (_num == pos + current.count) {
                            const next_link: *c.__MemListLink__ = current.childs.last orelse break;
                            current = @fieldParentPtr("link", next_link);
                            break;
                        }
                        
                        if (_num > pos + current.count) {
                            pos += current.count + 1;
                            const next_link: *c.__MemListLink__ = current.link.next orelse break;
                            current = @fieldParentPtr("link", next_link);
                            if (pos >= _num) break;
                            continue;
                        }
                        
                        const link: *c.__MemListLink__ = current.childs.first.?;
                        current = @fieldParentPtr("link", link);
                        pos += 1;
                        if (pos >= _num) break;
                    }
                    const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", current);
                    t.line = line;
                    if (t.line.*.text_len > 0) {
                        const text = t.line.*.text[0..t.line.*.text_len];
                        __AppEditorViewsFolded_goToSymbol__(t, c.__TextAscii_countIndent__(text.ptr, text.len, 1));
                    } else {
                        __AppEditorViewsFolded_goToSymbol__(t, 0);
                    }
                },
            }
            
            t.need_redraw = true;
            t.need_draw_line_num = true;
        }
    // # __AppEditorViewsFolded_goToMarked__
        fn __AppEditorViewsFolded_goToMarked__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            if (t.marked_line) |mark| {
                t.line = mark;
                t.need_redraw = true;
                __AppEditorViewsFolded_bakup__(t);
            }
        }
    // # __AppEditorViewsFolded_goToNextComment__
        fn __AppEditorViewsFolded_goToNextComment__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            var last_line = t.line;
            while (true) {
                __AppEditorViewsFolded_goToNextLine__(t);
                if (last_line == t.line) break;
                last_line = t.line;
                
                if (t.line.*.text_len > 0) {
                    const text = t.line.*.text[0..t.line.*.text_len];
                    var visible_text_ptr: [*c]const u8 = undefined; _=&visible_text_ptr;
                    var visible_text_len: usize = undefined; _=&visible_text_len;
                    if (c.__TextAscii_getNonIndent__(&visible_text_ptr, &visible_text_len, text.ptr, text.len)) {
                        const visible_text: []const u8 = visible_text_ptr[0..visible_text_len];
                        if (std.mem.startsWith(u8, visible_text, "#")) {
                            break;
                        } else if (std.mem.startsWith(u8, visible_text, "//")) {
                            break;
                        }
                    }
                }
            }
            t.offset.y = (c.__app__.terminal.output.size.y >> 1) - (c.__app__.terminal.output.size.y >> 2);
        }
    // # __AppEditorViewsFolded_goToNextLine__
        fn __AppEditorViewsFolded_goToNextLine__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const next_tree_link: *c.__MemListLink__ = t.line.*.tree.link.next orelse return;
            const next_tree:      *c.__MemTree__       = @fieldParentPtr("link", next_tree_link);
            const next:           *c.__AppEditorLine__       = @fieldParentPtr("tree", next_tree);
            
            t.line = next;
            __AppEditorViewsFolded_bakup__(t);
            t.need_redraw = true;
            if (t.offset.y < c.__app__.terminal.output.size.y - 1) t.offset.y += 1;
        }
    // # __AppEditorViewsFolded_goToNextParagraph__
        fn __AppEditorViewsFolded_goToNextParagraph__(t: *c.__AppEditorViewsFolded__) !void {
            // go to next line while not empty line
            while (true) {
                __AppEditorViewsFolded_goToNextLine__(t);
                if (t.line.*.text_len > 0) {
                    const text = t.line.*.text[0..t.line.*.text_len];
                    var visible_text_ptr: [*c]const u8 = undefined; _=&visible_text_ptr;
                    var visible_text_len: usize = undefined; _=&visible_text_len;
                    if (c.__TextAscii_getNonIndent__(&visible_text_ptr, &visible_text_len, text.ptr, text.len) == false) break;
                    if (t.line.*.tree.link.next == null) return;
                } else {
                    break;
                }
            }
            
            // go to next line while empty line
            while (true) {
                __AppEditorViewsFolded_goToNextLine__(t);
                if (t.line.*.text_len > 0) {
                    const text = t.line.*.text[0..t.line.*.text_len];
                    var visible_text_ptr: [*c]const u8 = undefined; _=&visible_text_ptr;
                    var visible_text_len: usize = undefined; _=&visible_text_len;
                    if (c.__TextAscii_getNonIndent__(&visible_text_ptr, &visible_text_len, text.ptr, text.len) != false) break;
                }
                if (t.line.*.tree.link.next == null) return;
            }
        }
    // # __AppEditorViewsFolded_goToNextSymbol__
        fn __AppEditorViewsFolded_goToNextSymbol__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const used = t.line.*.text_len;
            
            // inc symbol
            if (t.symbol >= c.__AppEditorLineLen_max__ - 1) return;
            if (t.symbol >= used) return;
            t.symbol += 1;
            t.need_redraw = true;
            
            // inc offset
            const rs = c.__app__.terminal.output.size.x - (c.__app__.terminal.output.size.x >> 2);
            if (t.offset.x >= rs) return;
            t.offset.x += 1;
        }
    // # __AppEditorViewsFolded_goToOut__
        fn __AppEditorViewsFolded_goToOut__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const parent_tree: *allowzero c.__MemTree__ = c.__MemTree_getParentOrNull__(&t.line.*.tree);
            if (@intFromPtr(parent_tree) != @intFromPtr(c.NULL)) {
                if (parent_tree == &t.lines) {
                    __AppEditorViewsFolded_goToRoot__(t);
                    __AppEditorViewsFolded_bakup__(t);
                    t.need_redraw = true;
                    return;
                }
                const parent: *c.__MemTree__ = @ptrCast(parent_tree);
                const line:   *c.__AppEditorLine__ = @fieldParentPtr("tree", parent);
                t.line = line;
                var indent: usize = 0;
                if (line.text_len > 0) {
                    const text = line.text[0..line.text_len];
                    indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                }
                __AppEditorViewsFolded_goToSymbol__(t, indent);
                t.offset.y = (c.__app__.terminal.output.size.y >> 1) - (c.__app__.terminal.output.size.y >> 3);
                __AppEditorViewsFolded_bakup__(t);
                t.need_redraw = true;
            } else {
                return;
            }
        }
    // # __AppEditorViewsFolded_goToPrevComment__
        fn __AppEditorViewsFolded_goToPrevComment__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            var last_line = t.line;
            while (true) {
                __AppEditorViewsFolded_goToPrevLine__(t);
                if (last_line == t.line) return;
                last_line = t.line;
                
                if (t.line.*.text_len > 0) {
                    const text = t.line.*.text[0..t.line.*.text_len];
                    var visible_text_ptr: [*c]const u8 = undefined; _=&visible_text_ptr;
                    var visible_text_len: usize = undefined; _=&visible_text_len;
                    if (c.__TextAscii_getNonIndent__(&visible_text_ptr, &visible_text_len, text.ptr, text.len)) {
                        const visible_text: []const u8 = visible_text_ptr[0..visible_text_len];
                        if (std.mem.startsWith(u8, visible_text, "#")) {
                            return;
                        } else if (std.mem.startsWith(u8, visible_text, "//")) {
                            return;
                        }
                    }
                }
            }
        }
    // # __AppEditorViewsFolded_goToPrevLine__
        fn __AppEditorViewsFolded_goToPrevLine__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const prev_tree_link: *c.__MemListLink__ = t.line.*.tree.link.prev orelse return;
            const prev_tree:      *c.__MemTree__       = @fieldParentPtr("link", prev_tree_link);
            const prev:           *c.__AppEditorLine__       = @fieldParentPtr("tree", prev_tree);
            
            t.line = prev;
            t.need_redraw = true;
            
            if (t.offset.y > 10) {
                t.offset.y -= 1;
            }
            __AppEditorViewsFolded_bakup__(t);
        }
    // # __AppEditorViewsFolded_goToPrevParagraph__
        fn __AppEditorViewsFolded_goToPrevParagraph__(t: *c.__AppEditorViewsFolded__) !void {
            while (true) { // go to prev line while empty line
                const prev_tree_link: *c.__MemListLink__ = t.line.*.tree.link.prev orelse return;
                const prev_tree: *c.__MemTree__ = @fieldParentPtr("link", prev_tree_link);
                const prev: *c.__AppEditorLine__ = @fieldParentPtr("tree", prev_tree);
                if (prev.text_len > 0) {
                    const prev_text = prev.text[0..prev.text_len];
                    var visible_text_ptr: [*c]const u8 = undefined; _=&visible_text_ptr;
                    var visible_text_len: usize = undefined; _=&visible_text_len;
                    if (c.__TextAscii_getNonIndent__(&visible_text_ptr, &visible_text_len, prev_text.ptr, prev_text.len)) {
                        // const visible_text: []const u8 = visible_text_ptr[0..visible_text_len];
                        break;
                    }
                }
                __AppEditorViewsFolded_goToPrevLine__(t);
            }
            
            while (true) { // go to prev line while not empty line
                const prev_tree_link: *c.__MemListLink__ = t.line.*.tree.link.prev orelse return;
                const prev_tree: *c.__MemTree__ = @fieldParentPtr("link", prev_tree_link);
                const prev: *c.__AppEditorLine__ = @fieldParentPtr("tree", prev_tree);
                if (prev.text_len > 0) {
                    const prev_text = prev.text[0..prev.text_len];
                    var visible_text_ptr: [*c]const u8 = undefined; _=&visible_text_ptr;
                    var visible_text_len: usize = undefined; _=&visible_text_len;
                    if (c.__TextAscii_getNonIndent__(&visible_text_ptr, &visible_text_len, prev_text.ptr, prev_text.len) == false) break;
                    __AppEditorViewsFolded_goToPrevLine__(t);
                } else {
                    break;
                }
            }
        }
    // # __AppEditorViewsFolded_goToPrevSymbol__
        fn __AppEditorViewsFolded_goToPrevSymbol__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const used = t.line.*.text_len;
            
            // inc symbol
            if (t.symbol == 0) return;
            if (t.symbol > used) {
                t.symbol = used;
                if (used < c.__app__.terminal.output.size.x - 1) t.offset.x = t.line.*.text_len;
                t.need_redraw = true;
                return;
            }
            if (t.symbol > 0) t.symbol -= 1;
            t.need_redraw = true;
            
            // inc offset
            const rs = c.__app__.terminal.output.size.x >> 2;
            if (t.offset.x == 0) return;
            if (t.symbol >= t.offset.x and t.offset.x < rs) return;
            t.offset.x -= 1;
        }
    // # __AppEditorViewsFolded_goToRoot__
        fn __AppEditorViewsFolded_goToRoot__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            const r_tree_link: *c.__MemListLink__ = t.lines.childs.first orelse return;
            const r_tree: *c.__MemTree__ = @fieldParentPtr("link", r_tree_link);
            const r: *c.__AppEditorLine__ = @fieldParentPtr("tree", r_tree);
            t.line = r;
            t.offset.y = 5;
            __AppEditorViewsFolded_goToStartOfText__(t);
            t.need_redraw = true;
            __AppEditorViewsFolded_bakup__(t);
        }
    // # __AppEditorViewsFolded_goToStartOfLine__
        fn __AppEditorViewsFolded_goToStartOfLine__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            t.symbol = 0;
            t.offset.x = 0;
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_goToStartOfText__
        fn __AppEditorViewsFolded_goToStartOfText__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            if (t.line.*.text_len > 0) {
                const text = t.line.*.text[0..t.line.*.text_len];
                __AppEditorViewsFolded_goToSymbol__(t, c.__TextAscii_countIndent__(text.ptr, text.len, 1));
            } else {
                __AppEditorViewsFolded_goToSymbol__(t, 0);
            }
        }
    // # __AppEditorViewsFolded_goToSymbol__
        fn __AppEditorViewsFolded_goToSymbol__(t: *c.__AppEditorViewsFolded__, pos: usize) callconv(.c) void {
            t.symbol = pos;
            if (t.symbol > c.__app__.terminal.output.size.x - 3) {
                t.offset.x = 8;
            } else {
                t.offset.x = t.symbol;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_indentToCutieLine__
        fn __AppEditorViewsFolded_indentToCutieLine__(
            t: *c.__AppEditorViewsFolded__, 
            line: *c.__AppEditorLine__
        ) !void { // todo not bool
            var new_indent: usize = 0;
            if (@intFromPtr(line.tree.parent) != @intFromPtr(c.NULL)) {
                const parent_tree: *c.__MemTree__ = @ptrCast(line.tree.parent);
                if (parent_tree != &t.lines) {
                    const parent: *c.__AppEditorLine__ = @fieldParentPtr("tree", parent_tree);
                    new_indent = 0;
                    if (parent.text_len > 0) {
                        const text = parent.text[0..parent.text_len];
                        new_indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1) + 4;
                    }
                }
                if (c.__AppEditorLine_setIndent__(line, new_indent) == false) return error.Unexpected;
            }
        }
    // # __AppEditorViewsFolded_indentToCutie__
        fn __AppEditorViewsFolded_indentToCutie__(t: *c.__AppEditorViewsFolded__, line: *c.__AppEditorLine__) !void {
            t.need_redraw = true;
            
            // get indent_delta
            var indent_delta: isize = 0;
            var line_indent: usize = 0;
            if (line.text_len > 0) {
                const line_text: []const u8 = line.text[0..line.text_len];
                line_indent = c.__TextAscii_countIndent__(line_text.ptr, line_text.len, 1);
            }
            var around_indent: usize = 0;
            {
                if (__AppEditorViewsFolded_Line_getNextLine__(t, line)) |next_line| {
                    if (next_line.text_len > 0) {
                        const next_line_text = next_line.text[0..next_line.text_len];
                        around_indent = c.__TextAscii_countIndent__(next_line_text.ptr, next_line_text.len, 1);
                    }
                } else if (__AppEditorViewsFolded_Line_getPrevLine__(t, line)) |prev_line| {
                    if (prev_line.text_len > 0) {
                        const prev_line_text = prev_line.text[0..prev_line.text_len];
                        around_indent = c.__TextAscii_countIndent__(prev_line_text.ptr, prev_line_text.len, 1); // i can take in last symbol and add indent but its bad for indent specific languages
                    }
                } else if (__AppEditorViewsFolded_Line_getParentLine__(t, line)) |parent_line| {
                    if (parent_line.text_len > 0) {
                        const parent_line_text = parent_line.text[0..parent_line.text_len];
                        around_indent = c.__TextAscii_countIndent__(parent_line_text.ptr, parent_line_text.len, 1); // do not add automate indent inside blocks. use empty line with needed indents
                    }
                }
            }
            indent_delta = @as(isize, @intCast(around_indent)) - @as(isize, @intCast(line_indent));
            if (indent_delta == 0) return;
            try __AppEditorViewsFolded_fixIndent__(t, line, indent_delta);
        }
    // # __AppEditorViewsFolded_init__
        fn __AppEditorViewsFolded_init__(t: *c.__AppEditorViewsFolded__) !void {
            t.need_redraw          = true;
            t.need_draw_line_num   = true;
            t.marked_line          = null;
            t.symbol               = 0;
            t.offset               = .{ .x = 0, .y = 0 }; // __math_d2_U_Pos__
            
            c.__MemTree_init__(&t.lines);
            c.__MemTree_init__(&t.cutted);
            c.__AppEditorLine_init__(&t.bakup_line);
        }
    // # __AppEditorViewsFolded_insertFindedText__
        fn __AppEditorViewsFolded_insertFindedText__(t: *c.__AppEditorViewsFolded__) !void {
            const text: []const u8 = __AppEditorViewsFind_get__(&c.__app__.editor.views.find) orelse return;
            for (text) |rune| {
                __AppEditorViewsFolded_insertSymbol__(t, rune) catch {};
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_insertSymbol__
        fn __AppEditorViewsFolded_insertSymbol__(t: *c.__AppEditorViewsFolded__, rune: u8) !void {
            if (t.symbol > t.line.*.text_len) {
                __AppEditorViewsFolded_goToSymbol__(t, t.line.*.text_len);
            }
            if (t.line.*.text_len < c.__AppEditorLineLen_max__) {
                c.__Buffer_push__(&t.line.*.text[0], &t.line.*.text_len, t.symbol, rune);
                __AppEditorViewsFolded_goToNextSymbol__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_joinLines__
        fn __AppEditorViewsFolded_joinLines__(t: *c.__AppEditorViewsFolded__) !void {
            try __AppEditorViewsFolded_unFold__(t);
            const flat = &c.__app__.editor.views.flat;
            try __AppEditorViewsFlat_joinLines__(flat);
        }
    // # __AppEditorViewsFolded_manyIndent__
        fn __AppEditorViewsFolded_manyIndent__(t: *c.__AppEditorViewsFolded__) !void { // TODO rename to decrease indent
            var indent: usize = 0;
            if (t.line.*.text_len > 0) {
                const text = t.line.*.text[0..t.line.*.text_len];
                indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
            }
            if (indent < 4) return;
            if (c.__AppEditorLine_setIndent__(t.line, indent - 4) == false) return error.Unexpected;
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_markThisLine__
        fn __AppEditorViewsFolded_markThisLine__(t: *c.__AppEditorViewsFolded__) !void {
            t.marked_line = t.line;
            __AppEditor_changeStatus__("marked.");
        }
    // # __AppEditorViewsFolded_moveBlockOutside__
        fn __AppEditorViewsFolded_moveBlockOutside__(t: *c.__AppEditorViewsFolded__) !void {
            const current_tree = &t.line.*.tree;
            if (c.__MemTree_isChild__(current_tree)) {
                var parent_tree: *c.__MemTree__ = undefined;
                c.__MemTree_getParent__(@ptrCast(&parent_tree), current_tree);
                const next_tree:   *c.__MemTree__ = select: {
                    if (@intFromPtr(current_tree.link.next) != @intFromPtr(c.NULL)) {
                        const next_link: *c.__MemListLink__ = current_tree.link.next;
                        break :select @fieldParentPtr("link", next_link);
                    } else if (@intFromPtr(current_tree.link.prev) != @intFromPtr(c.NULL)) {
                        const prev_link: *c.__MemListLink__ = current_tree.link.prev;
                        break :select @fieldParentPtr("link", prev_link);
                    } else {
                        c.__MemTree_getParent__(@ptrCast(&parent_tree), current_tree);
                        break :select parent_tree;
                    }
                };
                
                // move
                c.__MemTree_pop__(current_tree);
                c.__MemTree_pushPrev__(parent_tree, current_tree);
                try __AppEditorViewsFolded_indentToCutie__(t, t.line);
                const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", next_tree);
                t.line = line;
                
                __AppEditor_changeStatus__("moved up");
                __AppEditorViewsFolded_cursorMoveToCurrent__(t) catch {};
            }
        }
    // # __AppEditorViewsFolded_moveBlockToMarkedInWithAddIndent__
        fn __AppEditorViewsFolded_moveBlockToMarkedInWithAddIndent__(t: *c.__AppEditorViewsFolded__) !void {
            const block = t.line;
            try __AppEditorViewsFolded_moveBlockToMarkedIn__(t);
            try __AppEditorViewsFolded_fixIndent__(t, block, 4);
        }
    // # __AppEditorViewsFolded_moveBlockToMarkedIn__
        fn __AppEditorViewsFolded_moveBlockToMarkedIn__(t: *c.__AppEditorViewsFolded__) !void {
            if (@intFromPtr(t.marked_line) != @intFromPtr(c.NULL)) {
                const marked: *c.__AppEditorLine__ = @ptrCast(t.marked_line);
                if (marked == t.line) return;
                { // check current block is not a parent of marked:
                    var parent_tree: *c.__MemTree__ = &marked.tree;
                    const line_tree: *c.__MemTree__ = &t.line.*.tree;
                    if (parent_tree == line_tree) return;
                    while (true) {
                        if (c.__MemTree_isChild__(parent_tree)) {
                            c.__MemTree_getParent__(@ptrCast(&parent_tree), parent_tree);
                            if (parent_tree == line_tree) return;
                        } else {
                            break;
                        }
                    }
                }
                
                // move
                const next_line = blk: {
                    const last_line = t.line;
                    if (__AppEditorViewsFolded_Line_getNextLine__(t, last_line)) |ptr| {
                        break: blk ptr;
                    } else if (__AppEditorViewsFolded_Line_getPrevLine__(t, last_line)) |ptr| {
                        break: blk ptr;
                    } else if (__AppEditorViewsFolded_Line_getParentLine__(t, last_line)) |ptr| {
                        break: blk ptr;
                    } else return;
                };
                
                c.__MemTree_pop__(&t.line.*.tree);
                c.__MemTree_pushChild__(&marked.tree, &t.line.*.tree);
                
                // fix indent
                var indent: usize = 0;
                if (t.line.*.text_len > 0) {
                    const text = t.line.*.text[0.. t.line.*.text_len];
                    indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                }
                var marked_indent: usize = 0;
                if (marked.text_len > 0) {
                    const marked_text   = marked.text[0..marked.text_len];
                    marked_indent = c.__TextAscii_countIndent__(marked_text.ptr, marked_text.len, 1);
                }
                const indent_delta: isize = @as(isize, @intCast(marked_indent)) - @as(isize, @intCast(indent));
                try __AppEditorViewsFolded_fixIndent__(t, t.line, indent_delta);
                
                t.line = next_line;
                t.need_redraw = true;
                __AppEditor_changeStatus__("block moved to in marked.");
                __AppEditorViewsFolded_cursorMoveToCurrent__(t) catch {};
            }
        }
    // # __AppEditorViewsFolded_moveBlockToMarkedOut__
        fn __AppEditorViewsFolded_moveBlockToMarkedOut__(t: *c.__AppEditorViewsFolded__) !void {
            const marked = t.marked_line orelse return;
            if (marked == t.line) return;
            { // check block is not a parent of marked:
                var parent_tree = &marked.*.tree;
                const line_tree = &t.line.*.tree;
                if (parent_tree == line_tree) return;
                while (true) {
                    if (c.__MemTree_isChild__(parent_tree)) {
                        c.__MemTree_getParent__(@ptrCast(&parent_tree), parent_tree);
                        if (parent_tree == line_tree) return;
                    } else {
                        break;
                    }
                }
            }
            
            // move
            var next_tree: *c.__MemTree__ = undefined; {
                const current_tree = &t.line.*.tree;
                if (@intFromPtr(current_tree.link.next) != @intFromPtr(c.NULL)) {
                    const next_link: *c.__MemListLink__ = current_tree.link.next;
                    next_tree = @fieldParentPtr("link", next_link);
                } else if (@intFromPtr(current_tree.link.prev) != @intFromPtr(c.NULL)) {
                    const prev_link: *c.__MemListLink__ = current_tree.link.prev;
                    next_tree = @fieldParentPtr("link", prev_link);
                } else {
                    c.__MemTree_getParent__(@ptrCast(&next_tree), current_tree);
                }
            }
            const line_tree = &t.line.*.tree;
            c.__MemTree_pop__(line_tree);
            c.__MemTree_pushPrev__(&marked.*.tree, line_tree);
            
            try __AppEditorViewsFolded_indentToCutie__(t, t.line);
            const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", next_tree);
            t.line = line;
            t.need_redraw = true;
            __AppEditor_changeStatus__("moved to marked.");
            __AppEditorViewsFolded_cursorMoveToCurrent__(t) catch {};
        }
    // # __AppEditorViewsFolded_moveDownToSort__
        fn __AppEditorViewsFolded_moveDownToSort__(t: *c.__AppEditorViewsFolded__) !void {
            const cursor_pos_x = t.symbol;
            const base_line = t.line;
            const base_line_text = base_line.*.text_len;
            if (cursor_pos_x <= base_line_text) {
                const base_text        = &base_line.*.text[cursor_pos_x];
                const base_text_len    = base_line_text - cursor_pos_x;
                const base_end_of_word = c.__TextAscii_findBreakOfWord__(base_text, base_text_len);
                if (base_end_of_word > 0) {
                    var iter_count: usize = 0;
                    var next_line_link: [*c]c.__MemListLink__ = base_line.*.tree.link.next;
                    while(next_line_link != 0) {
                        const next_line = next_line_link.*.next;
                        {
                            const line_tree: *c.__MemTree__       = @fieldParentPtr("link", @as(*c.__MemListLink__, @ptrCast(next_line_link)));
                            const line:      *c.__AppEditorLine__ = @fieldParentPtr("tree", line_tree);
                            if (line.text_len >= cursor_pos_x) {
                                const line_text        = &line.text[cursor_pos_x];
                                const line_text_len    = line.text_len - cursor_pos_x;
                                const line_end_of_word = c.__TextAscii_findBreakOfWord__(line_text, line_text_len);
                                if (line_end_of_word > 0) {
                                    const compare_size = if (base_end_of_word < line_end_of_word) base_end_of_word else line_end_of_word; // just min
                                    const compare_result: i8 = @bitCast(c.__TextAscii_compare__(base_text, line_text, compare_size));
                                    if (compare_result > 0) {
                                        try __AppEditorViewsFolded_swapWithBottom__(t);
                                    } else {
                                        break;
                                    }
                                } else {
                                    break;
                                }
                            } else {
                                break;
                            }
                        }
                        iter_count+=1;
                        next_line_link = next_line;
                    }
                    while(iter_count > 0):(iter_count -= 1) {
                        __AppEditorViewsFolded_goToPrevLine__(t);
                    }
                }
            }
        }
    // # __AppEditorViewsFolded_moveUpToSort__
        fn __AppEditorViewsFolded_moveUpToSort__(t: *c.__AppEditorViewsFolded__) !void {
            const cursor_pos_x = t.symbol;
            const base_line = t.line;
            const base_line_text = base_line.*.text_len;
            if (cursor_pos_x <= base_line_text) {
                const base_text        = &base_line.*.text[cursor_pos_x];
                const base_text_len    = base_line_text - cursor_pos_x;
                const base_end_of_word = c.__TextAscii_findBreakOfWord__(base_text, base_text_len);
                if (base_end_of_word > 0) {
                    var iter_count: usize = 0;
                    var next_line_link: [*c]c.__MemListLink__ = base_line.*.tree.link.prev;
                    while(next_line_link != 0) {
                        const prev_line = next_line_link.*.prev;
                        {
                            const line_tree: *c.__MemTree__       = @fieldParentPtr("link", @as(*c.__MemListLink__, @ptrCast(next_line_link)));
                            const line:      *c.__AppEditorLine__ = @fieldParentPtr("tree", line_tree);
                            if (line.text_len >= cursor_pos_x) {
                                const line_text        = &line.text[cursor_pos_x];
                                const line_text_len    = line.text_len - cursor_pos_x;
                                const line_end_of_word = c.__TextAscii_findBreakOfWord__(line_text, line_text_len);
                                if (line_end_of_word > 0) {
                                    const compare_size = if (base_end_of_word < line_end_of_word) base_end_of_word else line_end_of_word;
                                    const compare_result: i8 = @bitCast(c.__TextAscii_compare__(base_text, line_text, compare_size));
                                    if (compare_result < 0) {
                                        try __AppEditorViewsFolded_swapWithUpper__(t);
                                    } else {
                                        break;
                                    }
                                } else {
                                    break;
                                }
                            } else {
                                break;
                            }
                        }
                        iter_count+=1;
                        next_line_link = prev_line;
                    }
                    while(iter_count > 0):(iter_count -= 1) {
                        __AppEditorViewsFolded_goToNextLine__(t);
                    }
                }
            }
        }
    // # __AppEditorViewsFolded_onKey__
        fn __AppEditorViewsFolded_onKey__(t: *c.__AppEditorViewsFolded__, cik: c.__ConsoleAnsiInputKey__) callconv(.c) void {
            __AppEditorViewsFolded_onkeyWrap__(t, cik) catch {};
        }
    // # __AppEditorViewsFolded_onkeyWrap__
        fn __AppEditorViewsFolded_onkeyWrap__(t: *c.__AppEditorViewsFolded__, cik: c.__ConsoleAnsiInputKey__) !void {
            switch (cik) {
                c.__ConsoleAnsiInputKey_alt_w__                                => __AppEditorViewsFolded_moveUpToSort__(t) catch {},
                c.__ConsoleAnsiInputKey_alt_s__                                => __AppEditorViewsFolded_moveDownToSort__(t) catch {},
                c.__ConsoleAnsiInputKey_escape__                               => __AppEditorViewsFolded_goToOut__(t),
                c.__ConsoleAnsiInputKey_tab__                                  => __AppEditorViewsFolded_goToIn__(t),
                c.__ConsoleAnsiInputKey_ctrl_e__                               => try __AppEditorViewsFolded_unFold__(t),
                c.__ConsoleAnsiInputKey_ctrl_q__                               => try __AppEditor_stop__(&c.__app__.editor),
                c.__ConsoleAnsiInputKey_ctrl_s__                               => __AppEditorViewsFolded_save__(t) catch {},
                c.__ConsoleAnsiInputKey_ctrl_j__                               => try __AppEditorViewsFolded_joinLines__(t),
                c.__ConsoleAnsiInputKey_enter__                                => __AppEditorViewsFolded_divide__(t) catch {},
                c.__ConsoleAnsiInputKey_back_space__                           => try __AppEditorViewsFolded_deletePrevSymbol__(t),
                c.__ConsoleAnsiInputKey_ctrl_bs__                              => try __AppEditorViewsFolded_deletePrevSymbol__(t),
                c.__ConsoleAnsiInputKey_ctrl_d__                               => try __AppEditorViewsFolded_duplicate__(t),
                c.__ConsoleAnsiInputKey_ctrl_x__                               => try __AppEditorViewsFolded_cut__(t),
                c.__ConsoleAnsiInputKey_ctrl_c__                               => try __AppEditorViewsFolded_duplicateAndCut__(t),
                c.__ConsoleAnsiInputKey_ctrl_v__                               => __AppEditorViewsFolded_pasteLine__(t) catch {},
                c.__ConsoleAnsiInputKey_ctrl_t__                               => __AppEditorViewsFolded_insertSymbol__(t, '\t') catch {},
                c.__ConsoleAnsiInputKey_ctrl_w__                               => try __AppEditorViewsFolded_deleteWord__(t),
                c.__ConsoleAnsiInputKey_ctrl_z__                               => try __AppEditorViewsFolded_restore__(t),
                c.__ConsoleAnsiInputKey_ctrl_f__                               => __AppEditorViewsFolded_toFind__(t) catch {},
                c.__ConsoleAnsiInputKey_ctrl_g__                               => __AppEditorViewsFolded_toGoTo__(t),
                c.__ConsoleAnsiInputKey_up__                                   => __AppEditorViewsFolded_goToPrevLine__(t),
                c.__ConsoleAnsiInputKey_down__                                 => __AppEditorViewsFolded_goToNextLine__(t),
                c.__ConsoleAnsiInputKey_left__                                 => __AppEditorViewsFolded_goToPrevSymbol__(t),
                c.__ConsoleAnsiInputKey_right__                                => __AppEditorViewsFolded_goToNextSymbol__(t),
                c.__ConsoleAnsiInputKey_ctrl_shift_left__                      => __AppEditorViewsFolded_CtrlShiftLeft__(t),
                c.__ConsoleAnsiInputKey_ctrl_shift_right__                     => __AppEditorViewsFolded_CtrlShiftRight__(t),
                c.__ConsoleAnsiInputKey_ctrl_left__                            => __AppEditorViewsFolded_ctrlLeft__(t),
                c.__ConsoleAnsiInputKey_ctrl_right__                           => __AppEditorViewsFolded_ctrlRight__(t),
                c.__ConsoleAnsiInputKey_ctrl_up__                              => __AppEditorViewsFolded_goToFirstLine__(t),
                c.__ConsoleAnsiInputKey_ctrl_down__                            => __AppEditorViewsFolded_goToLastLine__(t),
                c.__ConsoleAnsiInputKey_page_up__                              => __AppEditorViewsFolded_pageUp__(t),
                c.__ConsoleAnsiInputKey_page_down__                            => __AppEditorViewsFolded_pageDown__(t),
                c.__ConsoleAnsiInputKey_alt_e__                                => try __AppEditorViewsFolded_easyMotionV__(t),
                c.__ConsoleAnsiInputKey_alt_q__                                => try __AppEditorViewsFolded_easyMotionH__(t),
                c.__ConsoleAnsiInputKey_delete__                               => __AppEditorViewsFolded_deleteSymbol__(t),
                c.__ConsoleAnsiInputKey_shift_delete__                         => __AppEditorViewsFolded_clearLine__(t),
                c.__ConsoleAnsiInputKey_end__                                  => __AppEditorViewsFolded_goToEndOfLine__(t),
                c.__ConsoleAnsiInputKey_home__                                 => __AppEditorViewsFolded_goToStartOfLine__(t),
                c.__ConsoleAnsiInputKey_alt_up__                               => try __AppEditorViewsFolded_swapWithUpper__(t),
                c.__ConsoleAnsiInputKey_alt_down__                             => try __AppEditorViewsFolded_swapWithBottom__(t),
                c.__ConsoleAnsiInputKey_alt_1__                                => try __AppEditorViewsFolded_copyWordToFind__(t),
                c.__ConsoleAnsiInputKey_alt_2__                                => __AppEditorViewsFolded_alt2__(t) catch {},
                c.__ConsoleAnsiInputKey_alt_3__                                => __AppEditorViewsFolded_alt3__(t) catch {},
                c.__ConsoleAnsiInputKey_alt_4__                                => try __AppEditorViewsFolded_insertFindedText__(t),
                c.__ConsoleAnsiInputKey_alt_5__                                => __AppEditorViewsFolded_toReplace__(t),
                c.__ConsoleAnsiInputKey_alt_6__                                => __AppEditorViewsFolded_replace__(t) catch {},
                c.__ConsoleAnsiInputKey_alt_g__                                => __AppEditorViewsFolded_goToMarked__(t),
                c.__ConsoleAnsiInputKey_alt_m__                                => try __AppEditorViewsFolded_markThisLine__(t),
                c.__ConsoleAnsiInputKey_alt_o__                                => try __AppEditorViewsFolded_moveBlockOutside__(t),
                c.__ConsoleAnsiInputKey_alt_8__                                => try __AppEditorViewsFolded_moveBlockToMarkedIn__(t),
                c.__ConsoleAnsiInputKey_alt_9__                                => try __AppEditorViewsFolded_moveBlockToMarkedInWithAddIndent__(t),
                c.__ConsoleAnsiInputKey_alt_0__                                => try __AppEditorViewsFolded_moveBlockToMarkedOut__(t),
                c.__ConsoleAnsiInputKey_alt_c__                                => __AppEditorViewsFolded_externalCopy__(t) catch {},
                c.__ConsoleAnsiInputKey_alt_v__                                => __AppEditorViewsFolded_externalPaste__(t) catch {},
                c.__ConsoleAnsiInputKey_alt_z__                                => try __AppEditorViewsFolded_deleteCutted__(t),
                c.__ConsoleAnsiInputKey_ctrl_enter__                           => try __AppEditorViewsFolded_joinLines__(t),
                c.__ConsoleAnsiInputKey_alt_open_bracket__                     => __AppEditorViewsFolded_goToPrevComment__(t),
                c.__ConsoleAnsiInputKey_alt_close_bracket__                    => __AppEditorViewsFolded_goToNextComment__(t),
                c.__ConsoleAnsiInputKey_ctrl_triangular_open_quotation_mark__  => __AppEditorViewsFolded_manyIndent__(t) catch {},
                c.__ConsoleAnsiInputKey_ctrl_triangular_close_quotation_mark__ => __AppEditorViewsFolded_addIndent__(t) catch {},
                c.__ConsoleAnsiInputKey_alt_semicolon__                        => try __AppEditorViewsFolded_goToPrevParagraph__(t),
                c.__ConsoleAnsiInputKey_alt_apostrophe__                       => try __AppEditorViewsFolded_goToNextParagraph__(t),
                c.__ConsoleAnsiInputKey_f4__                                   => try __AppEditorViewsFolded_drawCountLineNum__(t),
                else => {
                    if (cik > 255) return;
                    const byte: u8 = @truncate(cik);
                    __AppEditorViewsFolded_insertSymbol__(t, byte) catch {};
                    t.need_redraw = true;
                },
            }
        }
    // # __AppEditorViewsFolded_pageDown__
        fn __AppEditorViewsFolded_pageDown__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            var pos: usize = 0;
            while (pos < 10) : (pos += 1) {
                __AppEditorViewsFolded_goToNextLine__(t);
            }
        }
    // # __AppEditorViewsFolded_pageUp__
        fn __AppEditorViewsFolded_pageUp__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            var pos: usize = 0;
            while (pos < 10) : (pos += 1) {
                __AppEditorViewsFolded_goToPrevLine__(t);
            }
        }
    // # __AppEditorViewsFolded_pasteLine__
        fn __AppEditorViewsFolded_pasteLine__(t: *c.__AppEditorViewsFolded__) !void {
            const line_tree_link: *c.__MemListLink__ = t.cutted.childs.last orelse return;
            const line_tree: *c.__MemTree__ = @fieldParentPtr("link", line_tree_link);
            c.__MemTree_pop__(line_tree);
            c.__MemTree_pushPrev__(&t.line.*.tree, line_tree);
            
            const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", line_tree);
            try __AppEditorViewsFolded_indentToCutie__(t, line);
            
            t.offset.y += 1;
            __AppEditorViewsFolded_goToPrevLine__(t);
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_replace__
        fn __AppEditorViewsFolded_replace__(t: *c.__AppEditorViewsFolded__) !void {
            const find_line    = &c.__app__.editor.views.find.line;
            if (find_line.text_len > 0) {
                const find_text    = find_line.text[0..find_line.text_len];
                
                const replace_line: *c.__AppEditorLine__ = &c.__app__.editor.views.replace.line;
                const replace_text = replace_line.text[0..replace_line.text_len];
                
                if (t.line.*.text_len - t.symbol < find_text.len) return;
                const dest = t.line.*.text[t.symbol .. t.symbol + find_text.len];
                if (std.mem.eql(u8, find_text, dest) == false) return;
                
                // delete old text
                for (find_text) |_| {
                    __AppEditorViewsFolded_deleteSymbol__(t);
                }
                
                for (replace_text) |rune| {
                    __AppEditorViewsFolded_insertSymbol__(t, rune) catch {};
                }
                
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsFolded_restore__
        fn __AppEditorViewsFolded_restore__(t: *c.__AppEditorViewsFolded__) !void {
            const bakup_line = &t.bakup_line;
            if (bakup_line.text_len > 0) {
                const text = bakup_line.text[0..bakup_line.text_len];
                c.__AppEditorLine_setText__(t.line, text.ptr, text.len);
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsFolded_saveTreeToFile__
        fn __AppEditorViewsFolded_saveTreeToFile__(root: *c.__MemTree__, file_name: []const u8, root_skip: enum { not_skip_root, skip_root }) !void {
            var ok: bool = true;
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_notification__, c.__AppEditorTheme_notification__.len); {
                    c.__ConsoleOutput_cursorHide__(&c.__app__.console.output);
                        __AppEditor_changeStatus__("saving file...");
                            var full_len: usize = 0;
                            { // count full len
                                __AppEditor_changeStatus__("counting...");
                                var maybe_tree: ?*c.__MemTree__ = root; // tree in c.__AppEditorLine__.tree
                                if (root_skip == .skip_root) {
                                    maybe_tree = c.__MemTree_traverse__(root);
                                }
                                
                                if (maybe_tree) |first_tree| { // first line
                                    const first_line: *c.__AppEditorLine__ = @fieldParentPtr("tree", first_tree);
                                    if (first_line.text_len > 0) {
                                        const first_line_text: []const u8 = first_line.text[0..first_line.text_len];
                                        full_len += first_line_text.len;
                                    }
                                    
                                    maybe_tree = c.__MemTree_traverse__(first_tree); // go to next
                                    while (maybe_tree) |tree| { // write any other lines with "\n" in start
                                        full_len += c.__app__.editor.__AppEditor_endLine_len__;
                                        
                                        const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", tree);
                                        if (line.text_len > 0) {
                                            const text = line.text[0..line.text_len];
                                            full_len += text.len;
                                        }
                                        
                                        maybe_tree = c.__MemTree_traverse__(tree);
                                    } // end while
                                }
                            }
                            
                            if (full_len > 0) { // write
                                __AppEditor_changeStatus__("allocating...");
                                var buffer: [*c]u8 = undefined;
                                if (c.__AlignedPtr_allocAny__(&buffer, 4, full_len)) { // use aligned just for speed
                                    // save to buffer
                                    __AppEditor_changeStatus__("defragmentation...");
                                    var writed: usize = 0;
                                        var maybe_tree: ?*c.__MemTree__ = root; // tree in c.__AppEditorLine__.tree
                                        if (root_skip == .skip_root) {
                                            maybe_tree = c.__MemTree_traverse__(root);
                                        }
                                        
                                        if (maybe_tree) |first_tree| { // just write first line
                                            const first_line: *c.__AppEditorLine__ = @fieldParentPtr("tree", first_tree);
                                            if (first_line.text_len > 0) {
                                                const first_line_text: []const u8 = first_line.text[0..first_line.text_len];
                                                c.__Mem_copy__(&buffer[writed], first_line_text.ptr, first_line_text.len);
                                                    writed += first_line_text.len;
                                            }
                                            
                                            maybe_tree = c.__MemTree_traverse__(first_tree); // go to next
                                            while (maybe_tree) |tree| { // write any other lines with "\n" in start
                                                c.__Mem_copy__(&buffer[writed], c.__app__.editor.__AppEditor_endLine__, c.__app__.editor.__AppEditor_endLine_len__);
                                                    writed += c.__app__.editor.__AppEditor_endLine_len__;
                                                
                                                const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", tree);
                                                if (line.text_len > 0) {
                                                    const text = line.text[0..line.text_len];
                                                    c.__Mem_copy__(&buffer[writed], text.ptr, text.len);
                                                        writed += text.len;
                                                }
                                                    
                                                maybe_tree = c.__MemTree_traverse__(tree);
                                            } // end while
                                        }
                                    
                                    // writing
                                    __AppEditor_changeStatus__("writing...");
                                    if (c.__FileComplete_write__(file_name.ptr, file_name.len, buffer, writed)) {
                                    } else { // file not writed
                                        __AppEditor_changeStatus__("file not writed");
                                        ok = false;
                                    }
                                    
                                    c.__AlignedPtr_freeAny__(buffer, full_len);
                                } else { // memory not allocated
                                    __AppEditor_changeStatus__("memory not allocated");
                                    ok = false;
                                }
                            } else { // clear
                                ok = c.__FileComplete_clear__(file_name.ptr, file_name.len);
                            }
                            
                            __AppEditor_changeStatus__("file saved");
                        c.__Console_showCursor__(&c.__app__.console);
                    c.__Terminal_resetColors__(&c.__app__.terminal);
                }
            if (!ok) return error.Unexpected;
            //return ok;
        }
    // # __AppEditorViewsFolded_save__
        fn __AppEditorViewsFolded_save__(t: *c.__AppEditorViewsFolded__) !void {
            { // write text
                const tt: []const u8 = "- - unfolding... - -";
                c.__Terminal_writeToOutput__(&c.__app__.terminal, tt.ptr, tt.len);
            }
            try __AppEditorViewsFolded_unFold__(t);
            const flat = &c.__app__.editor.views.flat;
            try __AppEditorViewsFlat_save__(flat);
            flat.need_redraw = true;
        }
    // # __AppEditorViewsFolded_setAsView__
        fn __AppEditorViewsFolded_setAsView__(t: *c.__AppEditorViewsFolded__) !void {
            c.__app__.editor.do_ptr          = @ptrCast(&__AppEditorViewsFolded_do__);
            c.__app__.editor.onKey_ptr       = @ptrCast(&__AppEditorViewsFolded_onKey__);
            c.__app__.editor.current_ctx     = t;
            c.__app__.editor.current_vtable  = &c.__AppEditorViewsVtable_folded__;
            __AppEditorViewsFolded_bakup__(t);
            if (t.offset.y < 10) t.offset.y = 10;
            try __AppEditorViewsFolded_draw__(t);
            __AppEditor_changeStatus__("Views.Folded mode.");
        }
    // # __AppEditorViewsFolded_swapWithBottom__
        fn __AppEditorViewsFolded_swapWithBottom__(t: *c.__AppEditorViewsFolded__) !void {
            if (t.line.*.tree.link.next == null) {
                return;
            }
            __AppEditorViewsFolded_goToNextLine__(t);
            try __AppEditorViewsFolded_swapWithUpper__(t);
            __AppEditorViewsFolded_goToNextLine__(t);
        }
    // # __AppEditorViewsFolded_swapWithUpper__
        fn __AppEditorViewsFolded_swapWithUpper__(t: *c.__AppEditorViewsFolded__) !void {
            if (t.line.*.tree.link.next == null) {
                try __AppEditorViewsFolded_cut__(t);
                try __AppEditorViewsFolded_pasteLine__(t);
            } else {
                try __AppEditorViewsFolded_cut__(t);
                __AppEditorViewsFolded_goToPrevLine__(t);
                try __AppEditorViewsFolded_pasteLine__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsFolded_toFind__
        fn __AppEditorViewsFolded_toFind__(t: *c.__AppEditorViewsFolded__) !void {
            __AppEditorViewsFind_setAsView__(&c.__app__.editor.views.find, t, &c.__AppEditorViewsVtable_folded__);
        }
    // # __AppEditorViewsFolded_toGoTo__
        fn __AppEditorViewsFolded_toGoTo__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            __AppEditorViewsGoToLine_setAsView__(&c.__app__.editor.views.go_to_line, t, &c.__AppEditorViewsVtable_folded__);
        }
    // # __AppEditorViewsFolded_toReplace__
        fn __AppEditorViewsFolded_toReplace__(t: *c.__AppEditorViewsFolded__) callconv(.c) void {
            __AppEditorViewsReplace_setAsView__(&c.__app__.editor.views.replace, t, &c.__AppEditorViewsVtable_folded__);
        }
    // # __AppEditorViewsFolded_unFold__
        fn __AppEditorViewsFolded_unFold__(t: *c.__AppEditorViewsFolded__) !void {
            const vf = &c.__app__.editor.views.flat;
            const lines = &vf.lines;
            if (lines.count > 0) unreachable;
            
            { // move to flat (from tree to link)
                const root: *c.__MemTree__  = &t.lines;
                var tree:   ?*c.__MemTree__ = c.__MemTree_traverse__(root); // skip root // maybe more skip?
                while (tree) |tree_r| {
                    const line: *c.__AppEditorLine__ = @fieldParentPtr("tree", tree_r);
                    c.__MemList_pushLast__(&vf.lines, &line.link);
                    tree = c.__MemTree_traverse__(tree_r);
                }
            }
            
            { // pop all lines from tree
                var link_r: *allowzero c.__MemListLink__ =  lines.first;
                while (@intFromPtr(link_r) != @intFromPtr(c.NULL)) {
                    const link: *c.__MemListLink__ =  @ptrCast(link_r);
                    const line: *c.__AppEditorLine__       = @fieldParentPtr("link", link);
                    c.__MemTree_pop__(&line.tree);
                    link_r = link.next;
                }
            }
            
            { // change Views.Flat
                vf.line        = t.line;
                vf.symbol      = t.symbol;
                vf.offset      = t.offset;
                vf.marked_line = t.marked_line;
                try __AppEditorViewsFlat_setAsView__(vf);
            }
        }
    // # __AppEditorViewsGoToLine_CtrlShiftLeft__
        fn __AppEditorViewsGoToLine_CtrlShiftLeft__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            if (t.line.text_len > 0) {
                const text = t.line.text[0..t.line.text_len];
                const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                if (t.symbol > indent) {
                    t.goToSymbol(indent);
                } else t.goToStartOfLine();
            } else t.goToStartOfLine();
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_CtrlShiftRight__
        fn __AppEditorViewsGoToLine_CtrlShiftRight__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            if (t.line.text_len > 0) {
                const text = t.line.text[0..t.line.text_len];
                const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                if (t.symbol < indent) t.goToSymbol(indent) else t.goToEndOfLine();
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsGoToLine_cancel__
        fn __AppEditorViewsGoToLine_cancel__(t: *c.__AppEditorViewsGoToLine__) !void {
            t.context_vtable.*.setAsView.?(t.context);
        }
    // # __AppEditorViewsGoToLine_clearLine__
        fn __AppEditorViewsGoToLine_clearLine__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            t.line.text_len = 0;
            __AppEditorViewsGoToLine_goToStartOfText__(t);
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_correctOffset__
        fn __AppEditorViewsGoToLine_correctOffset__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            const predel = (c.__app__.terminal.output.size.y >> 1) - (c.__app__.terminal.output.size.y >> 4);
            if (t.symbol >= predel) t.offset.x = predel;
        }
    // # __AppEditorViewsGoToLine_ctrlLeft__
        fn __AppEditorViewsGoToLine_ctrlLeft__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            __AppEditorViewsGoToLine_goToSymbol__(t, 0);
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_ctrlRight__
        fn __AppEditorViewsGoToLine_ctrlRight__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            if (t.line.text_len > 0) {
                const full_text = t.line.text[0..t.line.text_len];
                __AppEditorViewsGoToLine_goToSymbol__(t, full_text.len);
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsGoToLine_cursorMoveToCurrent__
        fn __AppEditorViewsGoToLine_cursorMoveToCurrent__(t: *c.__AppEditorViewsGoToLine__) !void {
            c.__Terminal_cursorMove__(&c.__app__.terminal, t.offset.x, t.offset.y);
        }
    // # __AppEditorViewsGoToLine_deletePrevSymbol__
        fn __AppEditorViewsGoToLine_deletePrevSymbol__(t: *c.__AppEditorViewsGoToLine__) !void {
            if (t.symbol == 0) {
                return;
            } else if (t.symbol > t.line.text_len) {
                __AppEditorViewsGoToLine_goToPrevSymbol__(t);
            } else {
                if (t.line.text_len == 0) return;
                __AppEditorViewsGoToLine_goToPrevSymbol__(t);
                __AppEditorViewsGoToLine_deleteSymbol__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_deleteSymbol__
        fn __AppEditorViewsGoToLine_deleteSymbol__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            if (t.line.text_len == 0) return;
            
            if (c.__Buffer_pop_check__(t.line.text_len, t.symbol)) {
                _=c.__Buffer_pop__(&t.line.text[0], &t.line.text_len, t.symbol);
            }
            
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_deleteWord__
        fn __AppEditorViewsGoToLine_deleteWord__(t: *c.__AppEditorViewsGoToLine__) !void {
            if (t.symbol > t.line.text_len) {
                return;
            }
            while (true) { // delete current symbol
                if (t.symbol == t.line.text_len) {
                    break;
                }
                const next_symbol = t.line.text[t.symbol];
                if (c.__TextAscii_isLetter__(next_symbol)) {
                    t.deleteSymbol();
                } else {
                    break;
                }
            }
            while (true) { // delete prev    symbol
                if (t.symbol == 0) {
                    break;
                }
                const prev_symbol = t.line.text[t.symbol - 1];
                if (c.__TextAscii_isLetter__(prev_symbol)) {
                    try t.deletePrevSymbol();
                } else {
                    break;
                }
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_do__
        fn __AppEditorViewsGoToLine_do__(ctx: *anyopaque) callconv(.c) void {
            const t = __AppEditorViewsGoToLine_getModel__(ctx);
            
            if (t.need_redraw == true) {
                t.need_redraw = false;
                __AppEditorViewsGoToLine_draw__(t) catch unreachable;
                __AppEditorViewsGoToLine_cursorMoveToCurrent__(t) catch unreachable;
            }
        }
    // # __AppEditorViewsGoToLine_drawEditedLine__
        fn __AppEditorViewsGoToLine_drawEditedLine__(t: *c.__AppEditorViewsGoToLine__) !void {
            // change color
            c.__Terminal_resetColors__(&c.__app__.terminal);
            
            if (t.line.text_len > 0) {
                const text = t.line.text[0..t.line.text_len];
                // draw left-to-right from first visible rune
                c.__Terminal_moveCursorToStartOfLine__(&c.__app__.terminal);
                var pos: usize = t.symbol - t.offset.x;
                var offset_x: usize = 0;
                // left arrow
                if (pos > 0) { // draw '<'
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_arrows__, c.__AppEditorTheme_arrows__.len);
                    _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "<");
                    pos += 1;
                    offset_x += 1;
                }
                // left symbols
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_current__, c.__AppEditorTheme_current__.len);
                while (true) {
                    if (offset_x >= t.offset.x) break;
                    if (offset_x >= c.__app__.terminal.output.size.x - 1) break;
                    if (pos >= text.len) break;
                    c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[pos], 1);
                    pos += 1;
                    offset_x += 1;
                }
                // current symbol. maybe inverse cursour?
                if (offset_x >= c.__app__.terminal.output.size.x - 2) return;
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_current_rune__, c.__AppEditorTheme_current_rune__.len);
                if (pos < text.len) {
                    c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[pos], 1);
                }
                pos += 1;
                offset_x += 1;
                // right symbols
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_current__, c.__AppEditorTheme_current__.len);
                while (true) {
                    if (offset_x >= c.__app__.terminal.output.size.x - 2) break;
                    if (pos >= text.len) break;
                    c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[pos], 1);
                    pos += 1;
                    offset_x += 1;
                }
                // right arrow
                if (pos < text.len) { // draw '>'
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_arrows__, c.__AppEditorTheme_arrows__.len);
                    _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, ">");
                } else {
                    _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
                }
            } else {
                c.__Console_clearLine__(&c.__app__.console);
            }
        }
    // # __AppEditorViewsGoToLine_draw__
        fn __AppEditorViewsGoToLine_draw__(t: *c.__AppEditorViewsGoToLine__) !void {
            defer {
                __AppEditorViewsGoToLine_cursorMoveToCurrent__(t) catch {};
            }
            
            __AppEditorViewsGoToLine_correctOffset__(t);
            if (t.offset.x >= c.__app__.terminal.output.size.x) t.offset.x = 0;
            if (t.offset.y >= c.__app__.terminal.output.size.y) t.offset.y = 0;
            if (t.symbol < t.offset.x) { // unexpected
                t.offset.x = 0;
                t.symbol = 0;
            }
            
            c.__ConsoleOutput_cursorHide__(&c.__app__.console.output);
            defer c.__Console_showCursor__(&c.__app__.console);
    
            t.offset.y = 1;
            { // draw banner
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, 0);
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_headers__, c.__AppEditorTheme_headers__.len);
                const tt = "enter the line you want to jump to:";
                _=c.__Terminal_writeToOutput__(&c.__app__.terminal, tt.ptr, tt.len);
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
            }
            { // draw edit line
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, 1);
                try __AppEditorViewsGoToLine_drawEditedLine__(t);
            }
            var pos_y: usize = 2;
            while (true) { // clear other downer lines
                if (pos_y >= c.__app__.terminal.output.size.y) return;
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                c.__Console_clearLine__(&c.__app__.console);
                pos_y += 1;
            }
        }
    // # __AppEditorViewsGoToLine_getModel__
        fn __AppEditorViewsGoToLine_getModel__(ptr: *anyopaque) callconv(.c) *c.__AppEditorViewsGoToLine__ {
            return @alignCast(@ptrCast(ptr));
        }
    // # __AppEditorViewsGoToLine_goToEndOfLine__
        fn __AppEditorViewsGoToLine_goToEndOfLine__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            t.symbol = t.line.text_len;
            if (t.symbol > c.__app__.terminal.output.size.x - 2) {
                t.offset.x = c.__app__.terminal.output.size.x - 2;
            } else {
                t.offset.x = t.symbol;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_goToLineFromInput__
        fn __AppEditorViewsGoToLine_goToLineFromInput__(t: *c.__AppEditorViewsGoToLine__) !void {
            var ok: bool = true;
                if (t.line.text_len > 0) {
                    if (t.line.text_len > 0) {
                        const text = t.line.text[0..t.line.text_len];
                        if (true
                            and text.len > 0 
                            and text.len <= c.__u64FromTextDec_maxLen__
                        ) {
                            const num: usize = @truncate(c.__u64FromTextDec__(text.ptr, text.len));
                            t.context_vtable.*.goToLineFromNumber.?(t.context, num);
                            try __AppEditorViewsGoToLine_cancel__(t);
                        } else {
                            ok = false;
                        }
                    } else {
                        ok = false;
                    }
                } else {
                    ok = false;
                }
            if (!ok) {
                t.context_vtable.*.goToLineFromNumber.?(t.context, 0);
                try __AppEditorViewsGoToLine_cancel__(t);
                return error.Unexpected;
            }
        }
    // # __AppEditorViewsGoToLine_goToNextSymbol__
        fn __AppEditorViewsGoToLine_goToNextSymbol__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            const used = t.line.text_len;
            if (t.symbol >= used) {
                if (true) return;
                if (t.line.next) |_| {
                    t.goToNextLine();
                    t.goToStartOfText();
                }
                return;
            }
            if (t.symbol < c.__AppEditorLineLen_max__ - 1) t.symbol += 1;
            if (used - t.symbol >= 10) {
                if (t.offset.x < c.__app__.terminal.output.size.x - 12) t.offset.x += 1;
            } else {
                if (t.offset.x < c.__app__.terminal.output.size.x - 2) t.offset.x += 1;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_goToPrevSymbol__
        fn __AppEditorViewsGoToLine_goToPrevSymbol__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            const used = t.line.text_len;
            if (t.symbol == 0) {
                if (true) return;
                if (t.line.prev) |_| {
                    t.goToPrevLine();
                    t.goToEndOfLine();
                }
                return;
            }
            if (t.symbol > used) {
                t.symbol = used;
                if (used < c.__app__.terminal.output.size.x - 1) t.offset.x = t.line.text_len;
                t.need_redraw = true;
                return;
            }
            if (t.symbol > 0) t.symbol -= 1;
            if (t.symbol >= 10) {
                if (t.offset.x > 10) {
                    t.offset.x -= 1;
                }
            } else {
                if (t.offset.x > 0) t.offset.x -= 1;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_goToStartOfLine__
        fn __AppEditorViewsGoToLine_goToStartOfLine__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            t.symbol = 0;
            t.offset.x = 0;
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_goToStartOfText__
        fn __AppEditorViewsGoToLine_goToStartOfText__(t: *c.__AppEditorViewsGoToLine__) callconv(.c) void {
            if (t.line.text_len > 0) {
                const text = t.line.text[0..t.line.text_len];
                const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                __AppEditorViewsGoToLine_goToSymbol__(t, indent);
            } else __AppEditorViewsGoToLine_goToSymbol__(t, 0);
        }
    // # __AppEditorViewsGoToLine_goToSymbol__
        fn __AppEditorViewsGoToLine_goToSymbol__(t: *c.__AppEditorViewsGoToLine__, pos: usize) callconv(.c) void {
            t.symbol = pos;
            if (t.symbol > c.__app__.terminal.output.size.x - 3) {
                t.offset.x = 8;
            } else {
                t.offset.x = t.symbol;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_init__
        fn __AppEditorViewsGoToLine_init__(t: *c.__AppEditorViewsGoToLine__) !void {
            t.need_redraw = true;
            t.offset.x = 0;
            t.offset.y = 3;
            t.symbol = 0;
            c.__AppEditorLine_init__(&t.line);
        }
    // # __AppEditorViewsGoToLine_insertSymbol__
        fn __AppEditorViewsGoToLine_insertSymbol__(t: *c.__AppEditorViewsGoToLine__, rune: u8) !void {
            if (t.symbol > t.line.text_len) __AppEditorViewsGoToLine_goToSymbol__(t, t.line.text_len);
            if (t.line.text_len < c.__AppEditorLineLen_max__) {
                c.__Buffer_push__(&t.line.text[0], &t.line.text_len, t.symbol, rune);
                __AppEditorViewsGoToLine_goToNextSymbol__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsGoToLine_onKey__
        fn __AppEditorViewsGoToLine_onKey__(ctx: ?*anyopaque, cik: c.__ConsoleAnsiInputKey__) callconv(.c) void {
            __AppEditorViewsGoToLine_onkeyWrap__(ctx, cik) catch {};
        }
    // # __AppEditorViewsGoToLine_onkeyWrap__
        fn __AppEditorViewsGoToLine_onkeyWrap__(ctx: ?*anyopaque, cik: c.__ConsoleAnsiInputKey__) !void {
            const t = __AppEditorViewsGoToLine_getModel__(ctx.?);
            switch (cik) {
                c.__ConsoleAnsiInputKey_ctrl_left__    => __AppEditorViewsGoToLine_ctrlLeft__(t),
                c.__ConsoleAnsiInputKey_ctrl_right__   => __AppEditorViewsGoToLine_ctrlRight__(t),
                c.__ConsoleAnsiInputKey_delete__       => __AppEditorViewsGoToLine_deleteSymbol__(t),
                c.__ConsoleAnsiInputKey_shift_delete__ => __AppEditorViewsGoToLine_clearLine__(t),
                c.__ConsoleAnsiInputKey_ctrl_w__       => __AppEditorViewsGoToLine_clearLine__(t),
                c.__ConsoleAnsiInputKey_left__         => __AppEditorViewsGoToLine_goToPrevSymbol__(t),
                c.__ConsoleAnsiInputKey_right__        => __AppEditorViewsGoToLine_goToNextSymbol__(t),
                c.__ConsoleAnsiInputKey_escape__       => try __AppEditorViewsGoToLine_cancel__(t),
                c.__ConsoleAnsiInputKey_ctrl_q__       => try __AppEditorViewsGoToLine_cancel__(t),
                c.__ConsoleAnsiInputKey_back_space__   => try __AppEditorViewsGoToLine_deletePrevSymbol__(t),
                c.__ConsoleAnsiInputKey_ctrl_bs__      => try __AppEditorViewsGoToLine_deletePrevSymbol__(t),
                c.__ConsoleAnsiInputKey_ctrl_j__       => try __AppEditorViewsGoToLine_goToLineFromInput__(t),
                c.__ConsoleAnsiInputKey_enter__        => try __AppEditorViewsGoToLine_goToLineFromInput__(t),
                
                else => {
                    const byte: u8 = @truncate(cik);
                    switch (byte) {
                        '0'...'9' => __AppEditorViewsGoToLine_insertSymbol__(t, byte) catch {},
                        else => {},
                    }
                },
            }
        }
    // # __AppEditorViewsGoToLine_setAsView__
        fn __AppEditorViewsGoToLine_setAsView__(t: *c.__AppEditorViewsGoToLine__, last_context: *anyopaque, last_vtable: *const c.__AppEditorViewsVTable__) callconv(.c) void {
            t.context = last_context;
            t.context_vtable = last_vtable;
            
            c.__app__.editor.do_ptr = @ptrCast(&__AppEditorViewsGoToLine_do__);
            c.__app__.editor.onKey_ptr = &__AppEditorViewsGoToLine_onKey__;
            c.__app__.editor.current_ctx = t;
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_CtrlShiftLeft__
        fn __AppEditorViewsReplace_CtrlShiftLeft__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            if (t.line.text_len > 0) {
                const text = t.line.text[0..t.line.text_len];
                const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                if (t.symbol > indent) {
                    t.goToSymbol(indent);
                } else t.goToStartOfLine();
            } else t.goToSymbol(0);
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_CtrlShiftRight__
        fn __AppEditorViewsReplace_CtrlShiftRight__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            if (t.line.text_len > 0) {
                const text = t.line.text[0..t.line.text_len];
                const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                if (t.symbol < indent) t.goToSymbol(indent) else t.goToEndOfLine();
            } else t.goToSymbol(0);
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_cancel__
        fn __AppEditorViewsReplace_cancel__(t: *c.__AppEditorViewsReplace__) !void {
            t.context_vtable.*.setAsView.?(t.context);
        }
    // # __AppEditorViewsReplace_clearLine__
        fn __AppEditorViewsReplace_clearLine__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            t.line.text_len = 0;
            __AppEditorViewsReplace_goToStartOfText__(t);
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_correctOffset__
        fn __AppEditorViewsReplace_correctOffset__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            const predel = (c.__app__.terminal.output.size.y >> 1) - (c.__app__.terminal.output.size.y >> 4);
            if (t.symbol >= predel) t.offset.x = predel;
        }
    // # __AppEditorViewsReplace_ctrlLeft__
        fn __AppEditorViewsReplace_ctrlLeft__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            __AppEditorViewsReplace_goToPrevSymbol__(t);
            if (t.symbol > 0) {
                var jump_symbol: usize = 0;
                    const line: *c.__AppEditorLine__ = &t.line;
                    if (line.text_len > 0) {
                        const full_text = line.text[0..line.text_len];
                        const text = full_text[0 .. t.symbol];
                        const spaces = c.__TextAscii_countIndentReverse__(text.ptr, text.len, 1);
                        if (spaces > 0) {
                            __AppEditorViewsReplace_goToSymbol__(t, t.symbol - spaces);
                            t.need_redraw = true;
                            return;
                        }
                        const dest_pos = c.__TextAscii_findBreakOfWordReverse__(text.ptr, text.len) + 1;
                        jump_symbol = dest_pos;
                    } 
                __AppEditorViewsReplace_goToSymbol__(t, jump_symbol);
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsReplace_ctrlRight__
        fn __AppEditorViewsReplace_ctrlRight__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            __AppEditorViewsReplace_goToNextSymbol__(t);
            if (t.line.text_len > 0) {
                const full_text = t.line.text[0..t.line.text_len];
                if (t.symbol >= full_text.len) return;
                const text = full_text[t.symbol..];
                const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                if (indent > 0) {
                    __AppEditorViewsReplace_goToSymbol__(t, t.symbol + indent);
                    t.need_redraw = true;
                    return;
                }
                __AppEditorViewsReplace_goToSymbol__(t, c.__TextAscii_findBreakOfWord__(text.ptr, text.len) + t.symbol);
                t.need_redraw = true;
            }
        }
    // # __AppEditorViewsReplace_cursorMoveToCurrent__
        fn __AppEditorViewsReplace_cursorMoveToCurrent__(t: *c.__AppEditorViewsReplace__) !void {
            c.__Terminal_cursorMove__(&c.__app__.terminal, t.offset.x, t.offset.y);
        }
    // # __AppEditorViewsReplace_deletePrevSymbol__
        fn __AppEditorViewsReplace_deletePrevSymbol__(t: *c.__AppEditorViewsReplace__) !void {
            if (t.symbol == 0) {
                return;
            } else if (t.symbol > t.line.text_len) {
                __AppEditorViewsReplace_goToPrevSymbol__(t);
            } else {
                if (t.line.text_len == 0) return;
                __AppEditorViewsReplace_goToPrevSymbol__(t);
                __AppEditorViewsReplace_deleteSymbol__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_deleteSymbol__
        fn __AppEditorViewsReplace_deleteSymbol__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            if (t.line.text_len == 0) return;
            
            if (c.__Buffer_pop_check__(t.line.text_len, t.symbol)) {
                _=c.__Buffer_pop__(&t.line.text[0], &t.line.text_len, t.symbol);
            } 
            
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_deleteWord__
        fn __AppEditorViewsReplace_deleteWord__(t: *c.__AppEditorViewsReplace__) !void {
            if (t.symbol > t.line.text_len) {
                return;
            }
            while (true) { // delete current symbol
                if (t.symbol == t.line.text_len) {
                    break;
                }
                const next_symbol = t.line.text[t.symbol];
                if (c.__TextAscii_isLetter__(next_symbol)) {
                    __AppEditorViewsReplace_deleteSymbol__(t);
                } else {
                    break;
                }
            }
            while (true) { // delete prev    symbol
                if (t.symbol == 0) {
                    break;
                }
                const prev_symbol = t.line.text[t.symbol - 1];
                if (c.__TextAscii_isLetter__(prev_symbol)) {
                    try __AppEditorViewsReplace_deletePrevSymbol__(t);
                } else {
                    break;
                }
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_do__
        fn __AppEditorViewsReplace_do__(ctx: *anyopaque) callconv(.c) void {
            const t = __AppEditorViewsReplace_getModel__(ctx);
            
            if (t.need_redraw == true) {
                t.need_redraw = false;
                __AppEditorViewsReplace_draw__(t) catch unreachable;
                __AppEditorViewsReplace_cursorMoveToCurrent__(t) catch unreachable;
            }
        }
    // # __AppEditorViewsReplace_drawEditedLine__
        fn __AppEditorViewsReplace_drawEditedLine__(t: *c.__AppEditorViewsReplace__) !void {
            if (t.line.text_len > 0) {
                const text = t.line.text[0..t.line.text_len];
                c.__Terminal_moveCursorToStartOfLine__(&c.__app__.terminal);
                
                // change color
                c.__Terminal_resetColors__(&c.__app__.terminal);
                const text_color: [*]const u8 = c.__AppEditorTheme_current__;
                const text_color_len: usize = c.__AppEditorTheme_current__.len;
                
                // draw left-to-right from first visible rune
                var pos: usize = t.symbol - t.offset.x;
                var offset_x: usize = 0;
                
                // left arrow
                if (pos > 0) { // draw '<'
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_arrows__, c.__AppEditorTheme_arrows__.len);
                    _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "<");
                    pos += 1;
                    offset_x += 1;
                }
                
                // left symbols
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, text_color, text_color_len);
                while (true) {
                    if (offset_x >= t.offset.x) break;
                    if (offset_x >= c.__app__.terminal.output.size.x - 1) break;
                    if (pos >= text.len) break;
                    c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[pos], 1);
                    pos += 1;
                    offset_x += 1;
                }
                
                // current symbol. maybe inverse cursour?
                if (offset_x >= c.__app__.terminal.output.size.x - 2) return;
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_current_rune__, c.__AppEditorTheme_current_rune__.len);
                if (pos < text.len) {
                    c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[pos], 1);
                }
                pos += 1;
                offset_x += 1;
                
                // right symbols
                c.__Terminal_setFontStyle__(&c.__app__.terminal, text_color, text_color_len);
                while (true) {
                    if (offset_x >= c.__app__.terminal.output.size.x - 2) break;
                    if (pos >= text.len) break;
                    c.__Terminal_writeToOutput__(&c.__app__.terminal, &text[pos], 1);
                    pos += 1;
                    offset_x += 1;
                }
                
                // right arrow
                if (pos < text.len) { // draw '>'
                    c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_arrows__, c.__AppEditorTheme_arrows__.len);
                    const tt: []const u8 = ">";
                    _=c.__Terminal_writeToOutput__(&c.__app__.terminal, tt.ptr, tt.len);
                } else {
                    _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
                }
            } else {
                c.__Terminal_resetColors__(&c.__app__.terminal);
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_line__, 0);
            }
        }
    // # __AppEditorViewsReplace_draw__
        fn __AppEditorViewsReplace_draw__(t: *c.__AppEditorViewsReplace__) !void {
            defer __AppEditorViewsReplace_cursorMoveToCurrent__(t) catch {};
            
            __AppEditorViewsReplace_correctOffset__(t);
            if (t.offset.x >= c.__app__.terminal.output.size.x) t.offset.x = 0;
            if (t.offset.y >= c.__app__.terminal.output.size.y) t.offset.y = 0;
            if (t.symbol < t.offset.x) { // unexpected
                t.offset.x = 0;
                t.symbol = 0;
            }
            c.__ConsoleOutput_cursorHide__(&c.__app__.console.output);
            defer c.__Console_showCursor__(&c.__app__.console);
    
            t.offset.y = 1;
            { // draw banner
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, 0);
                c.__Terminal_setFontStyle__(&c.__app__.terminal, c.__AppEditorTheme_headers__, c.__AppEditorTheme_headers__.len);
                _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "text for replace:");
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_to_end_line__, 0);
            }
            { // draw edit line
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, 1);
                defer __AppEditorViewsReplace_cursorMoveToCurrent__(t) catch {};
                try __AppEditorViewsReplace_drawEditedLine__(t);
            }
            var pos_y: usize = 2;
            while (true) { // clear other downer lines
                if (pos_y >= c.__app__.terminal.output.size.y) return;
                c.__Terminal_cursorMove__(&c.__app__.terminal, 0, pos_y);
                c.__Console_clearLine__(&c.__app__.console);
                pos_y += 1;
            }
        }
    // # __AppEditorViewsReplace_find__
        fn __AppEditorViewsReplace_find__(t: *c.__AppEditorViewsReplace__) !void {
            _ = t;
            const view = &c.__app__.editor.views.flat;
            try view.setAsView();
            try view.findNext();
        }
    // # __AppEditorViewsReplace_getModel__
        fn __AppEditorViewsReplace_getModel__(ptr: *anyopaque) callconv(.c) *c.__AppEditorViewsReplace__ {
            return @alignCast(@ptrCast(ptr));
        }
    // # __AppEditorViewsReplace_get__
        fn __AppEditorViewsReplace_get__(t: *c.__AppEditorViewsReplace__) callconv(.c) []const u8 {
            return t.line.text[0 .. t.line.text_len];
        }
    // # __AppEditorViewsReplace_goToEndOfLine__
        fn __AppEditorViewsReplace_goToEndOfLine__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            t.symbol = t.line.text_len;
            if (t.symbol > c.__app__.terminal.output.size.x - 2) {
                t.offset.x = c.__app__.terminal.output.size.x - 2;
            } else {
                t.offset.x = t.symbol;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_goToNextSymbol__
        fn __AppEditorViewsReplace_goToNextSymbol__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            const used = t.line.text_len;
            if (t.symbol >= used) {
                if (true) return;
                if (t.line.next) |_| {
                    t.goToNextLine();
                    t.goToStartOfText();
                }
                return;
            }
            if (t.symbol < c.__AppEditorLineLen_max__ - 1) t.symbol += 1;
            if (used - t.symbol >= 10) {
                if (t.offset.x < c.__app__.terminal.output.size.x - 12) t.offset.x += 1;
            } else {
                if (t.offset.x < c.__app__.terminal.output.size.x - 2) t.offset.x += 1;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_goToPrevSymbol__
        fn __AppEditorViewsReplace_goToPrevSymbol__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            const used = t.line.text_len;
            if (t.symbol == 0) {
                if (true) return;
                if (t.line.prev) |_| {
                    t.goToPrevLine();
                    t.goToEndOfLine();
                }
                return;
            }
            if (t.symbol > used) {
                t.symbol = used;
                if (used < c.__app__.terminal.output.size.x - 1) t.offset.x = t.line.text_len;
                t.need_redraw = true;
                return;
            }
            if (t.symbol > 0) t.symbol -= 1;
            if (t.symbol >= 10) {
                if (t.offset.x > 10) {
                    t.offset.x -= 1;
                }
            } else {
                if (t.offset.x > 0) t.offset.x -= 1;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_goToStartOfLine__
        fn __AppEditorViewsReplace_goToStartOfLine__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            t.symbol = 0;
            t.offset.x = 0;
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_goToStartOfText__
        fn __AppEditorViewsReplace_goToStartOfText__(t: *c.__AppEditorViewsReplace__) callconv(.c) void {
            if (t.line.text_len > 0) {
                const text = t.line.text[0..t.line.text_len];
                const indent = c.__TextAscii_countIndent__(text.ptr, text.len, 1);
                __AppEditorViewsReplace_goToSymbol__(t, indent);
            } else __AppEditorViewsReplace_goToSymbol__(t, 0);
        }
    // # __AppEditorViewsReplace_goToSymbol__
        fn __AppEditorViewsReplace_goToSymbol__(t: *c.__AppEditorViewsReplace__, pos: usize) callconv(.c) void {
            t.symbol = pos;
            if (t.symbol > c.__app__.terminal.output.size.x - 3) {
                t.offset.x = 8;
            } else {
                t.offset.x = t.symbol;
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_init__
        fn __AppEditorViewsReplace_init__(t: *c.__AppEditorViewsReplace__) !void {
            t.offset.x    = 0;
            t.offset.y    = 3;
            t.symbol      = 0;
            t.need_redraw = true;
            c.__AppEditorLine_init__(&t.line);
        }
    // # __AppEditorViewsReplace_insertFindedText__
        fn __AppEditorViewsReplace_insertFindedText__(t: *c.__AppEditorViewsReplace__) !void {
            const text: []const u8 = __AppEditorViewsFind_get__(&c.__app__.editor.views.find) orelse return;
            for (text) |rune| {
                __AppEditorViewsReplace_insertSymbol__(t, rune) catch {};
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_insertSymbol__
        fn __AppEditorViewsReplace_insertSymbol__(t: *c.__AppEditorViewsReplace__, rune: u8) !void {
            if (t.symbol > t.line.text_len) __AppEditorViewsReplace_goToSymbol__(t, t.line.text_len);
            if (t.line.text_len < c.__AppEditorLineLen_max__) {
                c.__Buffer_push__(&t.line.text[0], &t.line.text_len, t.symbol, rune);
                __AppEditorViewsReplace_goToNextSymbol__(t);
            }
            t.need_redraw = true;
        }
    // # __AppEditorViewsReplace_onKey__
        fn __AppEditorViewsReplace_onKey__(ctx: ?*anyopaque, cik: c.__ConsoleAnsiInputKey__) callconv(.c) void {
            __AppEditorViewsReplace_onkeyWrap__(ctx, cik) catch {};
        }
    // # __AppEditorViewsReplace_onkeyWrap__
        fn __AppEditorViewsReplace_onkeyWrap__(ctx: ?*anyopaque, cik: c.__ConsoleAnsiInputKey__) !void {
            const t: *c.__AppEditorViewsReplace__ = @ptrCast(@alignCast(ctx));
            switch (cik) {
                c.__ConsoleAnsiInputKey_ctrl_left__    => __AppEditorViewsReplace_ctrlLeft__(t),
                c.__ConsoleAnsiInputKey_ctrl_right__   => __AppEditorViewsReplace_ctrlRight__(t),
                c.__ConsoleAnsiInputKey_delete__       => __AppEditorViewsReplace_deleteSymbol__(t),
                c.__ConsoleAnsiInputKey_shift_delete__ => __AppEditorViewsReplace_clearLine__(t),
                c.__ConsoleAnsiInputKey_left__         => __AppEditorViewsReplace_goToPrevSymbol__(t),
                c.__ConsoleAnsiInputKey_right__        => __AppEditorViewsReplace_goToNextSymbol__(t),
                c.__ConsoleAnsiInputKey_escape__       => try __AppEditorViewsReplace_cancel__(t),
                c.__ConsoleAnsiInputKey_ctrl_w__       => try __AppEditorViewsReplace_deleteWord__(t),
                c.__ConsoleAnsiInputKey_back_space__   => try __AppEditorViewsReplace_deletePrevSymbol__(t),
                c.__ConsoleAnsiInputKey_ctrl_bs__      => try __AppEditorViewsReplace_deletePrevSymbol__(t),
                c.__ConsoleAnsiInputKey_ctrl_j__       => try __AppEditorViewsReplace_cancel__(t),
                c.__ConsoleAnsiInputKey_ctrl_q__       => try __AppEditorViewsReplace_cancel__(t),
                c.__ConsoleAnsiInputKey_enter__        => try __AppEditorViewsReplace_cancel__(t),
                c.__ConsoleAnsiInputKey_alt_4__        => try __AppEditorViewsReplace_insertFindedText__(t),
                else => {
                    const byte: u8 = @truncate(cik);
                    __AppEditorViewsReplace_insertSymbol__(t, byte) catch {};
                },
            }
        }
    // # __AppEditorViewsReplace_setAsView__
        fn __AppEditorViewsReplace_setAsView__(t: *c.__AppEditorViewsReplace__, last_context: *anyopaque, last_vtable: *const c.__AppEditorViewsVTable__) callconv(.c) void {
            t.context                     = last_context;
            t.context_vtable              = last_vtable;
            c.__app__.editor.do_ptr      = @ptrCast(&__AppEditorViewsReplace_do__);
            c.__app__.editor.onKey_ptr   = &__AppEditorViewsReplace_onKey__;
            c.__app__.editor.current_ctx = t;
            t.need_redraw                 = true;
        }
    // # __AppEditorViews_deinit__
        fn __AppEditorViews_deinit__(t: *c.__AppEditorViews__) callconv(.c) void {
            __zig_fuck__(t);
            //t.find.deinit(); // todo
            //t.go_to_line.deinit();
            //t.replace.deinit();
            //t.folded.deinit();
            //t.flat.deinit();
        }
    // # __AppEditorViews_init__
        fn __AppEditorViews_init__(views: *c.__AppEditorViews__) !void {
            try __AppEditorViewsFlat_init__  (&views.flat);
            try __AppEditorViewsFolded_init__(&views.folded);
            try __AppEditorViewsGoToLine_init__(&views.go_to_line);
            try __AppEditorViewsReplace_init__(&views.replace);
            try __AppEditorViewsFind_init__(&views.find);
        }
    // # __AppEditor_changeStatus__
        fn __AppEditor_changeStatus__(text: []const u8) void {
            c.__AppEditor_changeStatus__(text.ptr, text.len);
        }
    // # __AppEditor_deinit__
        fn __AppEditor_deinit__(t: *c.__AppEditor__) callconv(.c) void {
            if (t.inited == false) return;
            __AppEditorViews_deinit__(&t.views);
        }
    // # __AppEditor_do__
        fn __AppEditor_do__(t: *c.__AppEditor__) !bool {
            if (t.do_ptr) |do_ptr| do_ptr(t.current_ctx.?);
            if (t.working == false) return false;
            return true;
        }
    // # __AppEditor_init__
        fn __AppEditor_init__(t: *c.__AppEditor__) !void {
            __AppEditorViewsFlatVtable_init__(&c.__AppEditorViewsVtable_flat__);
            __AppEditorViewsFoldedVtable_init__(&c.__AppEditorViewsVtable_folded__);
            
            t.do_ptr             = null;
            t.onKey_ptr          = null;
            t.current_ctx        = &t.views.flat;
            t.current_vtable     = &c.__AppEditorViewsVtable_flat__;
            t.working            = true;
            t.__AppEditor_endLine__      = "\n";
            t.__AppEditor_endLine_len__  = "\n".len;
            
            t.lines_drawing = 0;
            c.__MemList_init__(&t.history);
            t.start_record_link   = @alignCast(@ptrCast(c.NULL));
            t.stop_record_link    = @alignCast(@ptrCast(c.NULL));
            t.recording_macro     = false;
            
            try __AppEditor_updatePathToClipboard__(t);
            try __AppEditorViews_init__(&t.views);
            t.inited = true;
        }
    // # __AppEditor_onKey__
        fn __AppEditor_onKey__(t: *c.__AppEditor__, key: c.__ConsoleAnsiInputKey__) callconv(.c) void {
            __AppEditor_onKeyWrap__(t, key) catch {};
        }
        
        fn __AppEditor_onKeyWrap__(t: *c.__AppEditor__, key: c.__ConsoleAnsiInputKey__) !void {
            switch (key) {
                c.__ConsoleAnsiInputKey_f1__ => _=c.__AppEditor_startRecordMacro__(t),
                c.__ConsoleAnsiInputKey_f2__ => _=c.__AppEditor_stopRecordMacro__(t), // ignore error
                c.__ConsoleAnsiInputKey_f3__ => try __AppEditor_playMacro__(t),
                
                else => {
                    if (c.__AppEditor_addKeyToHistory__(t, key)) {
                        const on_key = t.onKey_ptr orelse return;
                        on_key(t.current_ctx, key);
                    } else {
                        return error.Unexpected;
                    }
                },
            }
        }
    // # __AppEditor_parse_text_to_lines__
        fn __AppEditor_parse_text_to_lines__(
            t:         *c.__AppEditor__,
            list:      *c.__MemList__, // list for store c.__AppEditorLine__.link
            text_ptr:  [*]const u8,
            text_len:  usize
        ) !void {
            var ok: bool = true;
                var line_num:     usize  = 0;
                var unparsed_len: usize  = text_len;
                while (ok and unparsed_len > 0) {
                    line_num += 1;
                    const line_pos: usize = text_len - unparsed_len;
                    
                    var line_text_len: usize = 0;
                    if (unparsed_len > "\n".len and c.__Mem_findFast__(&line_text_len, text_ptr[line_pos..], unparsed_len, "\n", 1)) {
                        unparsed_len -= line_text_len + "\n".len;
                        
                        const line_text: []const u8 = text_ptr[line_pos .. line_pos + line_text_len];
                        if (line_text_len > 0 and line_text[line_text_len - 1] == '\r') {
                            t.__AppEditor_endLine__     = "\r\n";
                            t.__AppEditor_endLine_len__ = "\r\n".len;
                            line_text_len -= "\r".len;
                        }
                    } else {
                        line_text_len = unparsed_len;
                        unparsed_len = 0;
                    }
                    
                    const line_text: []const u8 = text_ptr[line_pos .. line_pos + line_text_len];
                    if (line_text_len < c.__AppEditorLineLen_max__) {
                        var line: *c.__AppEditorLine__ = undefined;
                        if ( c.__AppEditorLine_alloc__(@ptrCast(&line)) ) {
                            c.__AppEditorLine_init__(line);
                            line.text_len = line_text_len;
                            c.__Mem_copy__(&line.text[0], line_text.ptr, line_text_len);
                            c.__MemList_pushLast__(list, &line.link);
                                if (!ok) {
                                    const link: *c.__MemListLink__  = list.last.?;
                                    c.__MemList_pop__(list, link);
                                }
                            //if (!ok) c.__AppEditorLine_free__(line);
                        } else {
                            _=c.printf("%d, line not allocated", @src().line, line_num);
                            ok = false;
                        }
                    } else {
                        _=c.printf("%d, line %d is too long", @src().line, line_num);
                        ok = false;
                    }
                }
                
                if (!ok) {
                    while(list.count > 0) { // deallocating lines
                        const link: *c.__MemListLink__ = list.first.?;
                        c.__MemList_pop__(list, link);
                        const line: *c.__AppEditorLine__ = @fieldParentPtr("link", link);
                        c.__AppEditorLine_free__(line);
                    }
                }
            if (!ok) return error.Unexpected;
            return; // ok;
        }
    // # __AppEditor_playMacro__
        fn __AppEditor_playMacro__(t: *c.__AppEditor__) !void {
            if (t.recording_macro != true) {
                if ( true
                    and (@intFromPtr(t.start_record_link) != @intFromPtr(c.NULL))
                    and (@intFromPtr(t.stop_record_link)  != @intFromPtr(c.NULL))
                ) {
                    const sr:  *c.__MemListLink__  = @ptrCast(t.start_record_link);
                    // const lr:  *c.__MemListLink__  = @ptrCast(t.stop_record_link);
                    
                    var next_link: *allowzero c.__MemListLink__ = sr.next; // skipped start recording itself
                    while ( true
                        and ( @intFromPtr(next_link) != @intFromPtr(c.NULL) )
                        and (next_link != t.stop_record_link)
                    ) {
                        const next_r:       *c.__MemListLink__          = @ptrCast(next_link);
                        const history_note: *c.__AppEditorHistoryNote__ = @alignCast(@fieldParentPtr("link", next_r));
                        const key:          c.__ConsoleAnsiInputKey__   = history_note.key;
                        __AppEditor_onKey__(t, key);
                        next_link = next_r.next;
                    }
                } else {
                   __AppEditor_changeStatus__("macro not recorded.");
                }
            } else {
                __AppEditor_changeStatus__("not aviable while recording");
            }
        }
    // # __AppEditor_stop__
        fn __AppEditor_stop__(t: *c.__AppEditor__) !void {
            c.__Terminal_cursorMove__(&c.__app__.terminal, 0, t.lines_drawing);
            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "\n", 0);
            _ = c.printf("file: {%.*s}", t.__AppEditor_fileName_len__ , @intFromPtr(&t.__AppEditor_fileName__[0]));
            
            draw_line_num: {
                const ctx = t.current_ctx orelse break :draw_line_num;
                const vt = t.current_vtable orelse break :draw_line_num;
                const cln = vt.*.countLineNum orelse break :draw_line_num;
                const current_line = cln(ctx);
                _ = c.printf(" {%d}", current_line); // todo not use printf
            }
            
            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "\r\n", 0);
            t.working = false;
        }
    // # __AppEditor_updatePathToClipboard__
        fn __AppEditor_updatePathToClipboard__(t: *c.__AppEditor__) !void {
            var ok: bool = true;
                
                // full path: "{HOME}/clipboard.tmp"
                var writed: usize = 0;
                const buffer: [*c]u8 = &t.__AppEditor_pathToClipboard__[0];
                
                const home_len = c.__OsEnvHome_getLen__();
                if (home_len < c.__OsFilePathLen_max__) {
                    c.__OsEnvHome_write__(&buffer[writed]);
                        writed += home_len;
                    
                    if ((@as(usize, c.__OsFilePathLen_max__) - writed) > c.__OsFilePath_separator__.len) {
                        c.__Mem_copy__(&buffer[writed], c.__OsFilePath_separator__.ptr, c.__OsFilePath_separator__.len);
                            writed += c.__OsFilePath_separator__.len;
                        
                        const t2: []const u8 = "clipboard.tmp";
                        if ((@as(usize, c.__OsFilePathLen_max__) - writed) > t2.len) {
                            c.__Mem_copy__(&buffer[writed], t2.ptr, t2.len);
                                writed += t2.len;
                            t.__AppEditor_pathToClipboard_len__ = writed;
                        } else {
                            ok = false;
                        }
                    } else {
                        ok = false;
                    }
                } else {
                    ok = false;
                }
            if (!ok) return error.NotOk;
        }
    // # __App_deinit__
        fn __App_deinit__(app: *c.__App__) callconv(.c) bool {
            var ok: bool = true;
                __AppEditor_deinit__(&app.editor);
                if (c.__Terminal_deinit__(&app.terminal)) {
                    c.__OsHelper_deinit__(&app.__App_osHelper__);
                } else {ok = false;}
            return ok;
        }
    // # __App_init__
        fn __App_init__(app: *c.__App__) callconv(.c) bool {
            var ok: bool = true;
            
            if(c.__OsHelper_init__(&app.__App_osHelper__)) {
                c.__Console_init__(&app.console, app.__App_osHelper__.console_input_handle, app.__App_osHelper__.console_output_handle);
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, c.__ConsoleAnsi_output_clear_line__, 0);
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "\r", 0);
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "- - - OwO - - -", 0);
                const flat   = &app.editor.views.flat;
                const folded = &app.editor.views.folded;
                if (c.__Terminal_init__(&app.terminal, &app.console)) {
                    if (__AppEditor_init__(&app.editor)) {
                        if (__App_parseArgsAndDo__(app)) {
                            if (__AppEditorViewsFlat_setAsView__(flat)){
                                if (__AppEditorViewsFlat_fold__(flat)) {
                                    if (__AppEditorViewsFolded_markThisLine__(folded)) {
                                        app.working = true;
                                    } else |_| {
                                        ok = false;
                                        _=c.__OsConsoleOutput_write__(&c.__app__.console.output, " fail markThisLine\r\n", 0);
                                    }
                                } else |_| {
                                    ok = false;
                                    _=c.__OsConsoleOutput_write__(&c.__app__.console.output, " fail flat.fold\r\n", 0);
                                }
                            } else |_| {
                                ok = false;
                                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, " fail flat.setAsView\r\n", 0);
                            }
                        } else |_| {
                            ok = false;
                            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, " fail parse args\r\n", 0);
                        }
                        
                        if (!ok) __AppEditor_deinit__(&app.editor);
                    } else |_| {
                        ok = false;
                        _=c.__OsConsoleOutput_write__(&c.__app__.console.output, " fail __AppEditor_init__\r\n", 0);
                    }
                    
                    if (!ok) {
                        if (c.__Terminal_deinit__(&app.terminal)) {
                        } else {
                            ok = false;
                            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, " fail c.__Terminal_deinit__\r\n", 0);
                        }
                    }
                } else {
                    ok = false;
                    _=c.__OsConsoleOutput_write__(&c.__app__.console.output, " fail c.__Terminal_init__\r\n", 0);
                }
                
                if (!ok) c.__OsHelper_deinit__(&app.__App_osHelper__);
            } else {
                ok = false;
                _=c.__Text_formatU64__(@ptrCast(&c.__OsFallbackConsole_write__), null, @src().line, 1);
                _=c.__ZText_writeToWriteFn__(@ptrCast(&c.__OsFallbackConsole_write__), null, " fail App_Os_Helper_init...\r\n".ptr);
            }
            
            return ok;
        }
    // # __App_loop__
        fn __App_loop__(app: *c.__App__) !void {
            app.tick = std.time.milliTimestamp();
            while (app.working) {
                // app.__App_osHelper__
                c.__OsHelper_process__(&app.__App_osHelper__);
                if (app.working == false) break;
                
                // update terminal
                c.__Terminal_updateOutputSize__(&app.terminal);
                
                // terminal keyboard
                while(true) {
                    c.__Terminal_updateInputBuffer__(&app.terminal);
                    var key: c.__ConsoleAnsiInputKey__ = undefined;
                    if (c.__TerminalInput_grab__(&key, &app.terminal.input)) {
                        __AppEditor_onKey__(&app.editor, key); // todo rename to onConsoleKey
                    } else {
                        break;
                    }
                }
                
                const editor_result = try __AppEditor_do__(&app.editor);
                if (editor_result != true) break;
                
                // sleep to next frame
                const expected_frame_end_time  = app.tick + c.__Time_msPerS__ / c.__App_expectedFps__;
                const resulting_frame_end_time = std.time.milliTimestamp();
                const delay_sleep              = if (resulting_frame_end_time < expected_frame_end_time) expected_frame_end_time - resulting_frame_end_time else 1;
                c.__Os_sleep__(@intCast(delay_sleep));
                app.tick = resulting_frame_end_time + delay_sleep;
            }
        }
    // # __App_parseArgsAndDo__
        fn __App_parseArgsAndDo__(t: *c.__App__) !void {
            var ok: bool = true;
            var argIterator = std.process.ArgIteratorPosix.init();
            _ = argIterator.skip(); // skip name of programm
            
            if (argIterator.next()) |name_arg| { // first arg: file name
                c.__Console_clearLine__(&c.__app__.console);
                c.__Terminal_moveCursorToStartOfLine__(&t.terminal);
                // print("opening file {name_arg}");
                    _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "opening file ");
                    c.__Terminal_writeToOutput__(&c.__app__.terminal, name_arg.ptr, name_arg.len);
                
                if (name_arg.len < c.__OsFilePathLen_max__) {
                    c.__Mem_copy__(&t.editor.__AppEditor_fileName__[0], name_arg.ptr, name_arg.len);
                    t.editor.__AppEditor_fileName_len__ = name_arg.len;
                    
                    if (c.__OsFile_exist__(name_arg.ptr, name_arg.len)) {
                        var file: c.__OsFileHandle__ = undefined;
                        if (c.__OsFile_open__(&file, name_arg.ptr, name_arg.len)) {
                            const file_size: usize = c.__OsFile_getSize__(file);
                            if (file_size < c.__MemSize_gb__) {
                                c.__Console_clearLine__(&c.__app__.console);
                                c.__Terminal_moveCursorToStartOfLine__(&t.terminal);
                                _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "file opened... ");
                                
                                var text_ptr: [*c]u8 = undefined;
                                if (c.__OsMem_allocAny__(&text_ptr, file_size)) {
                                    c.__Console_clearLine__(&c.__app__.console);
                                    c.__Terminal_moveCursorToStartOfLine__(&t.terminal);
                                    _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "memory allocated... ");
                                    
                                    if (c.__OsFile_readToBuffer__(file, text_ptr, file_size, 0)) {
                                        c.__Console_clearLine__(&c.__app__.console);
                                        c.__Terminal_moveCursorToStartOfLine__(&t.terminal);
                                        _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "readed to memory... ");
                                        
                                        if (__AppEditor_parse_text_to_lines__(&t.editor, &t.editor.views.flat.lines, text_ptr, file_size)) {
                                            c.__Console_clearLine__(&c.__app__.console);
                                            c.__Terminal_moveCursorToStartOfLine__(&t.terminal);
                                            _=__writeTextToWriteFnVoid__(@ptrCast(&c.__Terminal_writeToOutput__), &c.__app__.terminal, "parsed to lines... ");
                                            
                                            const fll: *c.__MemListLink__ = t.editor.views.flat.lines.first;
                                            if (@intFromPtr(fll) != @intFromPtr(c.NULL)) {
                                                const line: *c.__AppEditorLine__ = @fieldParentPtr("link", fll);
                                                t.editor.views.flat.line  = line;
                                            } else {
                                                var line: *c.__AppEditorLine__ = undefined;
                                                if (c.__AppEditorLine_alloc__( @ptrCast(&line) ) ) {
                                                    t.editor.views.flat.line = line;
                                                    c.__AppEditorLine_init__(line);
                                                    c.__MemList_pushLast__(&t.editor.views.flat.lines, &t.editor.views.flat.line.*.link);
                                                    if (!ok) c.__AppEditorLine_free__(line);
                                                }
                                            }
                                            
                                            if (ok) { // second arg: line number
                                                if (argIterator.next()) |number_arg| {
                                                    // write to go_to_line.line
                                                        const line: *c.__AppEditorLine__ = &t.editor.views.go_to_line.line;
                                                        line.text_len = number_arg.len;
                                                        c.__Mem_copy__(&line.text[0], number_arg.ptr, number_arg.len);
                                                    
                                                    if (number_arg.len > 0 and number_arg.len <= c.__u64FromTextDec_maxLen__) {
                                                        const line_number = c.__u64FromTextDec__(number_arg.ptr, number_arg.len);
                                                        __AppEditorViewsFlat_goToLineFromNumber__(&t.editor.views.flat, @intCast(line_number));
                                                    } else {
                                                        ok = false;
                                                        _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  \r\n", 0);
                                                        _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  second argument used only for set LINE_NUMBER\r\n", 0);
                                                    }
                                                }
                                            }
                                        } else |err| {
                                            ok = false;
                                            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  \r\n", 0);
                                            _=c.printf("  error: {%s}\r\n", @errorName(err).ptr);
                                            _=c.printf("  line num: {%d}\r\n", t.editor.views.flat.lines.count);
                                            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  \r\n", 0);
                                        }
                                        
                                        if (!ok) { // free editor lines
                                            const list_lines: *c.__MemList__ = &t.editor.views.flat.lines;
                                            while (list_lines.count > 0) {
                                                const link: *c.__MemListLink__ = list_lines.first orelse unreachable;
                                                c.__MemList_pop__(list_lines, link);
                                                const line: *c.__AppEditorLine__ = @fieldParentPtr("link", link);
                                                c.__AppEditorLine_free__(line);
                                            }
                                        }
                                    } else {
                                        ok = false;
                                        _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  \r\n", 0);
                                        _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  ScalpiEditor not have super cow power.\r\n", 0);
                                    }
                                    
                                    c.__OsMem_freeAny__(text_ptr);
                                } else {
                                    ok = false;
                                }
                            } else {
                                ok = false;
                                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  \r\n", 0);
                                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  error: file is too large\r\n", 0);
                            }
                            
                            c.__OsFile_close__(file);
                        } else {
                            ok = false;
                            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  \r\n", 0);
                            _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  error: file not opened\r\n", 0);
                        }
                    } else {
                        ok = false;
                        _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  \r\n", 0);
                        _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  error: file not exist.\r\n", 0);
                    }
                } else {
                    ok = false;
                    _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  \r\n", 0);
                    _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  error: strange file path\r\n", 0);
                }
            } else {
                ok = false;
            }
            
            if (!ok) {
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  \r\n", 0);
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  usage: $ ScalpiEditor FILE_NAME LINE_NUMBER\r\n", 0);
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  Insert coin and try again!\r\n", 0);
                _=c.__OsConsoleOutput_write__(&c.__app__.console.output, "  \r\n", 0);
            }
            
            if (!ok) return error.Unexpected;
        }
    // # __writeTextToWriteFnVoid__
        fn __writeTextToWriteFnVoid__(write: c.__WriteFnPtrVoid__, context: *anyopaque, text: []const u8) usize {
            // use callconv(.c) for target function
            write.?(context, text.ptr, text.len);
            return text.len;
        }
    // # __zig_fuck__
        fn __zig_fuck__(whom: anytype) void {
            _ = whom;
        }
    // # __zig_writeToBuffer__
        fn __zig_writeToBuffer__(buffer: [*c]u8, text: []const u8) usize {
            c.__Mem_copy__(buffer, text.ptr, text.len);
            return text.len;
        }
    // # main
        pub fn main() u8 {
            @setRuntimeSafety(false);
            const ok: bool = real_main();
            if (ok) {return 0;}
            return 1;
        }
    // # real_main
        fn real_main() callconv(.c) bool {
            var ok: bool = true;
                _=c.__Text_formatU64__(@ptrCast(&c.__OsFallbackConsole_write__), null, @src().line, 1);
                _=c.__ZText_writeToWriteFn__(@ptrCast(&c.__OsFallbackConsole_write__), null, " testing...\r".ptr);
                
                if (c.tests()) {
                    if (__App_init__(&c.__app__)) {
                        __App_loop__(&c.__app__) catch return;
                        if (__App_deinit__(&c.__app__)) {
                        } else {
                            ok = false;
                            // print("%d: app_deinit failed \r\n", @src().line);
                                _=c.__Text_formatU64__(@ptrCast(&c.__OsFallbackConsole_write__), null, @src().line, 1);
                                _=c.__ZText_writeToWriteFn__(@ptrCast(&c.__OsFallbackConsole_write__), null, " app deinit failed...\r\n".ptr);
                        }
                    } else {
                        ok = false;
                        // c.printf("%d: fail __App_init__\r\n", @src().line);
                            _=c.__Text_formatU64__(@ptrCast(&c.__OsFallbackConsole_write__), null, @src().line, 1);
                            _=c.__ZText_writeToWriteFn__(@ptrCast(&c.__OsFallbackConsole_write__), null, " fail __App_init__\r\n".ptr);
                    }
                } else {
                    ok = false;
                    // _=c.printf("%d: tests failed \r\n", @src().line);
                        _=c.__Text_formatU64__(@ptrCast(&c.__OsFallbackConsole_write__), null, @src().line, 1);
                        _=c.__ZText_writeToWriteFn__(@ptrCast(&c.__OsFallbackConsole_write__), null, " tests fail\r\n".ptr);
                }
            return ok;
        }