Sorry flip my zeros and ones above ... keys 0..127 (not 255 :) and 32-bit keys start with 1. So your examples above are more deeply nested trees than you think:
openacs46=# select tree_level('00000100000000000000001100000000');
tree_level
------------
4
(1 row)
openacs46=#
Also if you calculate the indention string directly in your query you don't need to extend or db_foreach, just build a string with the right number of spaces:
lpad(' ',(tree_level(fs_tree.tree_sortkey) - 1), ' ') as spaces