Module: IdHeader

Included in:
Id
Defined in:
lib/id-header.rb

Instance Method Summary collapse

Instance Method Details

#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

#header(node, top = true, indent = 0) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/id-header.rb', line 65

def header node, top = true , indent = 0
  if not @raw
    if top
      bg = "black"
    else
      bg = "grey"
    end
    if top
      back node if not @nodes[node]
      system("clear") 
      print_location node
      puts @msg.style("yellow", bg)
    else
      return if not @nodes[node]
      puts (node + ":").style "blue", bg
    end
    
    
      @included_nodes << node
      display_node node, indent, top, bg
      puts if @nodes[node].length == 0 and not top
      puts if top
    @included_nodes = []
  else
    system("clear")
    print_location node
    puts
    @nodes[node].each do |n|
      printf @prefix
      puts n
    end
    puts
  end
end


2
3
4
5
# File 'lib/id-header.rb', line 2

def print_location node
  @path.each {|node| printf (node + "/").style("purple", "black") }
  puts node.style("cyan", "black")
end