Method: IdHeader#display_node

Defined in:
lib/id-header.rb

#display_node(node, indent, top, bg) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/id-header.rb', line 7

def display_node node, indent, top,  bg
  @nodes["a"] = `ls`.split("\n")
  @prefix = "   "
  name = node
  node = @nodes[node].dup
  #preprocess node bef
  if contains?("s", name)
    node.sort!
  end
  if contains?("n", name)
    node.collect! { |line| 
      num = ((node.find_index(line)+1).to_s+".")
      (num + " " * (5 - num.length)).style("green", bg) + line
    }
  end
  if @promptnode
    @c1w = @nodes[@node].collect{|n| n.length}.max
    @prefix = ""
    node.collect! {|line|
      pre = @nodes[@promptnode][node.find_index(line)]
      if pre
        line + " : ".style("grey", "black") + pre.ljust(@c1w).style("green", "black")
      else
        line
      end
    }
  end
  node.each do |l|
    line = l
    printf @prefix
    printf ("   " * indent).style("white", bg) if not top
    # print line
    if is_node? line
      printf line.style "uscore", bg
      if line[-1] == ":" and @nodes[line][0]
        puts  " " + (@nodes[line][0]).style("green", "black")
      else
        puts
      end
    elsif line[0] == "@"  and not @included_nodes.find_index(node)
      @included_nodes << node
      header line[1..-1], false, indent + 1
      @included_nodes = []
    elsif line[0] == "%"
      if @nodes[line[1..-1]]
        puts @nodes[line[1..-1]][0].style("green", bg) if @nodes[line[1..-1]][0]
      end
    elsif line[0] == "&"
      res = []
      @nodes.keys.each { |n| res << n if contains?(n, line[1..-1])}
      puts line[1..-1].style("bold", "black") + " is in:".style("white", "black")
      res.each { |r| puts @prefix*2 + r.style("white", "black")}
    else
      puts line.style "white", bg
    end
  end
end