Пример #1
0
def print_view(asker, view):
    clear()
    lines = fields.get(asker, lines_field(), view)
    for line in lists.iterator(asker, lines):
        s = strings.to_str(asker, line)
        print(s)
    return asker.reply()
Пример #2
0
def interpret_list(asker, view, l):
    #TODO if I had better mapping, this would be fine...
    #for now I have to do it in this terrible way...
    result = representations.make(T.empty_list.head)
    for x in reversed(list(lists.iterator(asker, l))):
        result = representations.make(T.cons.head, head=x, tail=result)
    return asker.reply(answer=result)
Пример #3
0
def render_list(asker, x):
    result = T.from_str("[")
    first = True
    for item in lists.iterator(asker, x):
        item_printed = asker.ask_firmly(render(item))
        if not first:
            item_printed = strings.concat(T.from_str(", "), item_printed)
        first = False
        result = strings.concat(result, item_printed)
    result = strings.concat(result, T.from_str("]"))
    return asker.reply(answer=result)
Пример #4
0
def add_children_on_expanded(asker, old, new, bindings):
    children = []
    for p in lists.iterator(asker, lists.from_dict(bindings)):
        k = asker.ask(fields.get_field(first(), p)).firm_answer
        v = asker.ask(fields.get_field(second(), p)).firm_answer
        prefix = strings.string_concat(k, T.from_str(": "))
        new_node = node_from_term(asker, v)
        new_node = updates.update(
            updates.apply_to(headline(), strings.prepend_str(prefix)),
            new_node
        )
        children.append(new_node)
    return asker.reply(answer=updates.update(
        fields.set_field(all_children(), T.from_list(children)), 
        new
    ))
Пример #5
0
def outline_to_lines(asker, root):
    debug()
    result = asker.ask(fields.get_field(cached_lines(), root)).answer
    if result is not None:
        return asker.reply(answer=result)
    base_headline = asker.ask(fields.get_field(headline(), root)).firm_answer
    root = asker.refresh(root)
    prefix = "* " if convert.check_hard(asker, is_pointer(), root) else "  "
    full_headline = strings.string_concat(T.from_str(prefix), base_headline)
    root = asker.refresh(root)
    children = asker.ask(fields.get_field(visible_children(), root)).firm_answer
    body = empty_lines()
    for child in lists.iterator(asker, children):
        section = asker.ask(outline_to_lines(child)).firm_answer
        body = concat_lines(body, section)
    result = concat_lines(one_line(full_headline), indent_lines(body))
    asker.update(updates.set_field(cached_lines(), result), root)
    return asker.reply(answer=result)
Пример #6
0
def item_iterator(asker, d):
    return lists.iterator(asker, lists.from_dict(d))
Пример #7
0
def process_char(asker, root, c, parents):
    c = convert.to_char(asker, c)
    if convert.check_hard(asker, is_pointer(), root):
        if c == 'q':
            return asker.reply(value=quit)
        elif c == 'j':
            children = asker.ask(fields.get_field(visible_children(), root)).firm_answer
            if convert.check_hard(asker, lists.is_empty(), children):
                asker.pass_through(moved(down))
            else:
                children = asker.refresh(children)
                first_child = asker.ask(fields.get_fields(lists.first(), children)).firm_answer
                asker.update(has_pointer_now(), root)
                asker.update(is_pointer_now(), first_child)
            return asker.reply()
        elif c == 'k':
            return asker.reply(value=moved(up))
        elif c == 'z':
            asker.update(toggle_expanded(), root)
            return asker.reply()
        elif c == 'h':
            return asker.reply(value=moved(left))
        elif c == 'l':
            #FIXME zoom out one by one instead of all of the way...
            #this is pretty straightforward if we are willing to go into and out of python
            #but it would surely be nicer to do it the 'right' way
            #I'm also pretty happy to wait
            asker.ask(explore_outline(root, parents)) 
            return asker.reply(value=moved(left))
    elif convert.check_hard(asker, has_pointer(), root):
        children = asker.ask(field.get_field(visible_children(), root)).firm_answer
        def make_handler(above, below):
            handler = Dispatcher("exploration child handler", ("question",))
            @handler(moved.head)
            def move(asker, question, direction):
                if direction.head == down.head:
                    if below is None:
                        asker.pass_through(moved(direction))
                    else:
                        asker.update(now_is_pointer(), below)
                        asker.update(remove_pointer(), child)
                if direction.head == up.head:
                    if above is None:
                        asker.update(now_is_pointer(), root)
                        asker.update(remove_pointer(), child)
                    else:
                        asker.update(add_pointer_to_bottom(), above)
                        asker.update(remove_pointer(), child)
                elif direction.head == left.head:
                    asker.update(remove_pointer(), child)
                    asker.update(now_is_pointer(), root)
                return properties.trivial()
            #TODO insert a handler for changing underlying terms *etc*
            #I think that this is going to require some thought,
            #but I can wait
            return handler
        child_list = list(lists.iterator(asker, children))
        new_parents = lists.snoc(parents, root)
        for i in range(len(child_list)):
            child = child_list[i]
            if i > 0:
                below = child_list[i-1]
            else:
                below = None
            if i < len(child_list) - 1:
                above = child_list[i+1]
            else:
                above = None
            asker.ask(process_char(child, c, new_parents), handler=make_handler(above, below))
        return asker.reply()