Search in sources :

Example 1 with FixieFun3

use of suite.adt.pair.Fixie_.FixieFun3 in project suite by stupidsing.

the class DevMain method run.

private void run() {
    String input = FileUtil.read("src/main/java/suite/dev/DevMain.java");
    Text inputText = text(IRope.ropeList(input));
    try (Termios termios = new Termios(libc)) {
        termios.clear();
        Keyboard keyboard = new Keyboard(libc);
        Sink<State> redraw = state -> state.apply((st, undo, redo, text, oc, cc) -> cc.apply((cx, cy) -> oc.apply((ox, oy) -> {
            String[] lines = // 
            Ints_.range(// 
            viewSizeY).map(// 
            screenY -> text.get(ox, oy + screenY, viewSizeX).replace('\t', ' ')).toArray(String.class);
            termios.cursor(false);
            for (int screenY = 0; screenY < viewSizeY; screenY++) {
                termios.gotoxy(0, screenY);
                termios.puts(lines[screenY]);
            }
            termios.gotoxy(cx - ox, cy - oy);
            termios.cursor(true);
            return null;
        })));
        State state0 = new State(null, null, inputText, c(0, 0), c(0, 0));
        redraw.sink(state0);
        FixieFun3<VK, Character, State, State> mutate = (vk, ch, state) -> // 
        state.apply((st, undo, redo, text, oc, cc) -> oc.apply((ox, oy) -> cc.apply((cx, cy) -> {
            int ci = text.index(cx, cy);
            if (vk == VK.LEFT_)
                return st.cursor(ci - 1);
            else if (vk == VK.RIGHT)
                return st.cursor(ci + 1);
            else if (vk == VK.UP___)
                return st.cursor(cx, cy - 1);
            else if (vk == VK.DOWN_)
                return st.cursor(cx, cy + 1);
            else if (vk == VK.PGUP_)
                return st.cursor(cx, cy - viewSizeY);
            else if (vk == VK.PGDN_)
                return st.cursor(cx, cy + viewSizeY);
            else if (vk == VK.HOME_)
                return st.cursor(text.startOfLine(ci));
            else if (vk == VK.END__)
                return st.cursor(text.endOfLine(ci));
            else if (vk == VK.CTRL_HOME_)
                return st.cursor(0);
            else if (vk == VK.CTRL_END__)
                return st.cursor(text.length());
            else if (vk == VK.CTRL_LEFT_)
                return st.cursor(text.scanNext(ci, -1, ch_ -> !Character.isJavaIdentifierPart(ch_)));
            else if (vk == VK.CTRL_RIGHT)
                return st.cursor(text.scanNext(ci, 1, ch_ -> !Character.isJavaIdentifierPart(ch_)));
            else if (vk == VK.CTRL_UP___)
                return st.offset(ox, oy - 1).cursor(cx, cy - 1);
            else if (vk == VK.CTRL_DOWN_)
                return st.offset(ox, oy + 1).cursor(cx, cy + 1);
            else if (vk == VK.F7___)
                return st.offset(ox, max(cy - viewSizeY + 1, 0));
            else if (vk == VK.F8___)
                return st.offset(ox, min(cy, text.nLines()));
            else if (vk == VK.ALT_J____) {
                int index = text.endOfLine(ci);
                Text text1 = text.splice(index, index + 1, empty);
                return st.text(text1).cursor(index);
            } else if (vk == VK.BKSP_) {
                int index = ci;
                return 0 < index ? st.splice(index - 1, index, empty) : st;
            } else if (vk == VK.ALT_UP___) {
                int i1 = text.startOfLine(ci);
                if (0 < i1) {
                    int i0 = text.prevLine(i1);
                    int i2 = text.nextLine(i1);
                    return st.splice(i2, i2, text.text.subList(i0, i1)).splice(i0, i1, empty);
                } else
                    return st;
            } else if (vk == VK.ALT_DOWN_) {
                int i0 = text.startOfLine(ci);
                int i1 = text.nextLine(i0);
                if (i1 < text.length()) {
                    int i2 = text.nextLine(i1);
                    return st.splice(i1, i2, empty).splice(i0, i0, text.text.subList(i1, i2));
                } else
                    return st;
            } else if (vk == VK.DEL__)
                return st.splice(1, empty);
            else if (vk == VK.CTRL_K____)
                return st.splice(ci, text.endOfLine(ci), empty);
            else if (vk == VK.CTRL_U____)
                return st.splice(text.startOfLine(ci), ci, empty);
            else if (vk == VK.CTRL_D____)
                return st.splice(text.startOfLine(ci), text.nextLine(ci), empty);
            else if (vk == VK.CTRL_Y____)
                return redo != null ? redo : st;
            else if (vk == VK.CTRL_Z____) {
                State undo1 = undo != null ? undo : st;
                return new State(undo1.undo, st, undo1.text, oc, undo1.cursorCoord);
            } else if (vk == VK.CTRL_C____)
                return Fail.t();
            else if (ch != null)
                if (ch == 13) {
                    int i0 = text.startOfLine(ci);
                    int ix = i0;
                    char ch_;
                    while ((ch_ = text.at(ix)) == ' ' || ch_ == '\t') ix++;
                    return st.splice(0, IRope.ropeList("\n").concat(text.text.subList(i0, ix)));
                } else
                    return st.splice(0, IRope.ropeList(Character.toString(ch)));
            else
                return st;
        }))).apply((st, undo, redo, text, oc, cc) -> oc.apply((ox, oy) -> cc.apply((cx, cy) -> {
            IntIntPair cc_ = text.coord(sat(text.index(cx, cy), 0, text.length()));
            return st.cursor(cc_.t0, cc_.t1);
        }))).apply((st, undo, redo, text, oc, cc) -> oc.apply((ox, oy) -> cc.apply((cx, cy) -> {
            int x0 = Math.max(0, cx - viewSizeX + 1);
            int y0 = Math.max(0, cy - viewSizeY + 1);
            int ox_ = sat(ox, x0, cx);
            int oy_ = sat(oy, y0, cy);
            return st.offset(ox_, oy_);
        })));
        keyboard.loop(signal -> // 
        signal.fold(state0, // 
        (state, pair_) -> pair_.map((vk, ch) -> mutate.apply(vk, ch, state))).wire(redraw));
    }
}
Also used : LibcJna(suite.ansi.LibcJna) Termios(suite.ansi.Termios) Friends.min(suite.util.Friends.min) Native(com.sun.jna.Native) IntIntPair(suite.primitive.adt.pair.IntIntPair) Predicate(java.util.function.Predicate) IRope(suite.immutable.IRope) Friends.max(suite.util.Friends.max) IntSink(suite.primitive.IntPrimitives.IntSink) Keyboard(suite.ansi.Keyboard) IRopeList(suite.immutable.IRope.IRopeList) FixieFun6(suite.adt.pair.Fixie_.FixieFun6) VK(suite.ansi.Keyboard.VK) FixieFun3(suite.adt.pair.Fixie_.FixieFun3) Sink(suite.util.FunUtil.Sink) FileUtil(suite.os.FileUtil) Chars_(suite.primitive.Chars_) IntsBuilder(suite.primitive.Ints.IntsBuilder) Ints_(suite.primitive.Ints_) IntMutable(suite.primitive.IntMutable) Fail(suite.util.Fail) Keyboard(suite.ansi.Keyboard) VK(suite.ansi.Keyboard.VK) Termios(suite.ansi.Termios) IntIntPair(suite.primitive.adt.pair.IntIntPair)

Example 2 with FixieFun3

use of suite.adt.pair.Fixie_.FixieFun3 in project suite by stupidsing.

the class MapObject_ method list.

public static <T extends MapObject<T>> List<?> list(Object object) {
    Class<?> clazz = object.getClass();
    Method m = // 
    Read.from(// 
    clazz.getMethods()).filter(// 
    method -> String_.equals(method.getName(), "apply")).uniqueResult();
    Class<?> type = m.getParameters()[0].getType();
    Object p;
    if (type == FixieFun0.class)
        p = (FixieFun0<?>) List::of;
    else if (type == FixieFun1.class)
        p = (FixieFun1<?, ?>) List::of;
    else if (type == FixieFun2.class)
        p = (FixieFun2<?, ?, ?>) List::of;
    else if (type == FixieFun3.class)
        p = (FixieFun3<?, ?, ?, ?>) List::of;
    else if (type == FixieFun4.class)
        p = (FixieFun4<?, ?, ?, ?, ?>) List::of;
    else if (type == FixieFun5.class)
        p = (FixieFun5<?, ?, ?, ?, ?, ?>) List::of;
    else if (type == FixieFun6.class)
        p = (FixieFun6<?, ?, ?, ?, ?, ?, ?>) List::of;
    else if (type == FixieFun7.class)
        p = (FixieFun7<?, ?, ?, ?, ?, ?, ?, ?>) List::of;
    else if (type == FixieFun8.class)
        p = (FixieFun8<?, ?, ?, ?, ?, ?, ?, ?, ?>) List::of;
    else if (type == FixieFun9.class)
        p = (FixieFun9<?, ?, ?, ?, ?, ?, ?, ?, ?, ?>) List::of;
    else if (type == FixieFunA.class)
        p = (FixieFunA<?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?>) List::of;
    else
        p = Fail.t();
    return (List<?>) Rethrow.ex(() -> m.invoke(object, p));
}
Also used : Read(suite.streamlet.Read) Iterator(java.util.Iterator) FixieFunA(suite.adt.pair.Fixie_.FixieFunA) Objects(java.util.Objects) List(java.util.List) FixieFun9(suite.adt.pair.Fixie_.FixieFun9) FixieFun7(suite.adt.pair.Fixie_.FixieFun7) FixieFun8(suite.adt.pair.Fixie_.FixieFun8) FixieFun5(suite.adt.pair.Fixie_.FixieFun5) FixieFun6(suite.adt.pair.Fixie_.FixieFun6) FixieFun3(suite.adt.pair.Fixie_.FixieFun3) FixieFun4(suite.adt.pair.Fixie_.FixieFun4) FixieFun1(suite.adt.pair.Fixie_.FixieFun1) FixieFun2(suite.adt.pair.Fixie_.FixieFun2) Method(java.lang.reflect.Method) FixieFun0(suite.adt.pair.Fixie_.FixieFun0) FixieFunA(suite.adt.pair.Fixie_.FixieFunA) Method(java.lang.reflect.Method) FixieFun9(suite.adt.pair.Fixie_.FixieFun9) FixieFun8(suite.adt.pair.Fixie_.FixieFun8) FixieFun7(suite.adt.pair.Fixie_.FixieFun7) FixieFun6(suite.adt.pair.Fixie_.FixieFun6) FixieFun1(suite.adt.pair.Fixie_.FixieFun1) FixieFun0(suite.adt.pair.Fixie_.FixieFun0) List(java.util.List) FixieFun5(suite.adt.pair.Fixie_.FixieFun5) FixieFun4(suite.adt.pair.Fixie_.FixieFun4) FixieFun3(suite.adt.pair.Fixie_.FixieFun3) FixieFun2(suite.adt.pair.Fixie_.FixieFun2)

Aggregations

FixieFun3 (suite.adt.pair.Fixie_.FixieFun3)2 FixieFun6 (suite.adt.pair.Fixie_.FixieFun6)2 Native (com.sun.jna.Native)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Objects (java.util.Objects)1 Predicate (java.util.function.Predicate)1 FixieFun0 (suite.adt.pair.Fixie_.FixieFun0)1 FixieFun1 (suite.adt.pair.Fixie_.FixieFun1)1 FixieFun2 (suite.adt.pair.Fixie_.FixieFun2)1 FixieFun4 (suite.adt.pair.Fixie_.FixieFun4)1 FixieFun5 (suite.adt.pair.Fixie_.FixieFun5)1 FixieFun7 (suite.adt.pair.Fixie_.FixieFun7)1 FixieFun8 (suite.adt.pair.Fixie_.FixieFun8)1 FixieFun9 (suite.adt.pair.Fixie_.FixieFun9)1 FixieFunA (suite.adt.pair.Fixie_.FixieFunA)1 Keyboard (suite.ansi.Keyboard)1 VK (suite.ansi.Keyboard.VK)1 LibcJna (suite.ansi.LibcJna)1