impl printing tree of a task

This commit is contained in:
Spaghettificated 2024-07-08 15:41:06 +02:00
parent 3cc96ed39b
commit 44ae363f58

30
todo.pl
View File

@ -6,7 +6,11 @@
all_tasks(L):- findall(X, task(X, _), L). all_tasks(L):- findall(X, task(X, _), L).
all_tasks(L, STATE):- findall(X, task(X, STATE), L). all_tasks(L, STATE):- findall(X, task(X, STATE), L).
print_task(X):-
task(X,ISDONE),
write(ISDONE),
write(': '),
write(X).
print_task_list([],_). print_task_list([],_).
print_task_list([H|T],N) :- print_task_list([H|T],N) :-
M is N+1, M is N+1,
@ -14,10 +18,8 @@ print_task_list([H|T],N) :-
asserta(idx(N, H)), asserta(idx(N, H)),
write(N), write(N),
write(". "), write(". "),
task(H,ISDONE), print_task(H),
write(ISDONE), nl,
write(': '),
write(H),nl,
print_task_list(T, M). print_task_list(T, M).
list_all :- all_tasks(L), print_task_list(L,1). list_all :- all_tasks(L), print_task_list(L,1).
@ -86,6 +88,24 @@ check(X) :-
write("no such task as "), write("no such task as "),
write(X). write(X).
indent(0).
indent(N):-
write(" "),
M is N-1,
indent(M).
tree_branch([],_).
tree_branch([X|T],N):-
indent(N),
print_task(X),
nl,
findall(Y, requires(Y,X), L),
M is N+1,
tree_branch(L,M),
tree_branch(T,N).
tree(X):- task(X,_), tree_branch([X],0).
tree(X):- idx(X,Y), tree(Y).
uncheck(X) :- idx(X, Task), uncheck(Task). uncheck(X) :- idx(X, Task), uncheck(Task).
uncheck(X):- uncheck(X):-
task(X, done), task(X, done),