Class: Uh::Layout

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/uh/layout.rb,
lib/uh/layout/bar.rb,
lib/uh/layout/tag.rb,
lib/uh/layout/column.rb,
lib/uh/layout/dumper.rb,
lib/uh/layout/screen.rb,
lib/uh/layout/version.rb,
lib/uh/layout/container.rb,
lib/uh/layout/geo_accessors.rb,
lib/uh/layout/column/arranger.rb

Defined Under Namespace

Modules: GeoAccessors Classes: Bar, Column, Container, Dumper, Screen, Tag

Constant Summary collapse

VERSION =
'0.1.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLayout

Returns a new instance of Layout.



22
23
24
25
# File 'lib/uh/layout.rb', line 22

def initialize
  @screens  = Container.new
  @widgets  = []
end

Instance Attribute Details

#screensObject (readonly)

Returns the value of attribute screens.



20
21
22
# File 'lib/uh/layout.rb', line 20

def screens
  @screens
end

#widgetsObject (readonly)

Returns the value of attribute widgets.



20
21
22
# File 'lib/uh/layout.rb', line 20

def widgets
  @widgets
end

Instance Method Details

#<<(client) ⇒ Object Also known as: push



52
53
54
55
56
57
58
59
60
# File 'lib/uh/layout.rb', line 52

def <<(client)
  current_tag.current_column_or_create << client
  current_column.current_client = client
  current_column.arrange_clients
  current_column.show_hide_clients
  client.focus
  update_widgets
  self
end

#arranger_for_current_tagObject



39
40
41
# File 'lib/uh/layout.rb', line 39

def arranger_for_current_tag
  Column::Arranger.new(current_tag.columns, current_tag.geo)
end

#current_clientObject



31
32
33
# File 'lib/uh/layout.rb', line 31

def current_client
  current_column and current_column.current_client
end

#handle_client_column_set(direction, arranger: arranger_for_current_tag) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/uh/layout.rb', line 128

def handle_client_column_set(direction, arranger: arranger_for_current_tag)
  return unless current_client
  arranger.move_current_client(direction).update_geos
  current_tag.each_column &:arrange_clients
  current_tag.each_column &:show_hide_clients
  update_widgets
end

#handle_client_sel(direction) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/uh/layout.rb', line 114

def handle_client_sel(direction)
  return unless current_client
  current_column.clients.sel direction
  current_column.show_hide_clients
  current_client.focus
  update_widgets
end

#handle_client_swap(direction) ⇒ Object



122
123
124
125
126
# File 'lib/uh/layout.rb', line 122

def handle_client_swap(direction)
  return unless current_client
  current_column.clients.set direction
  update_widgets
end

#handle_column_sel(direction) ⇒ Object



107
108
109
110
111
112
# File 'lib/uh/layout.rb', line 107

def handle_column_sel(direction)
  return unless current_tag.columns.any?
  current_tag.columns.sel direction
  current_client.focus
  update_widgets
end

#handle_kill_currentObject



136
137
138
# File 'lib/uh/layout.rb', line 136

def handle_kill_current
  current_client and current_client.kill
end

#handle_screen_sel(direction) ⇒ Object



73
74
75
76
77
# File 'lib/uh/layout.rb', line 73

def handle_screen_sel(direction)
  screens.sel direction
  current_client.focus if current_client
  update_widgets
end

#handle_screen_set(direction) ⇒ Object



79
80
81
82
83
84
# File 'lib/uh/layout.rb', line 79

def handle_screen_set(direction)
  return unless current_client
  remove client = current_client
  screens.sel direction
  push client
end

#handle_tag_sel(tag_id) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/uh/layout.rb', line 86

def handle_tag_sel(tag_id)
  return unless current_tag.id != tag_id
  current_tag.hide
  current_screen.tags.current = find_tag_or_create tag_id
  current_tag.each_column &:show_hide_clients
  current_client.focus if current_client
  update_widgets
end

#handle_tag_set(tag_id) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/uh/layout.rb', line 95

def handle_tag_set(tag_id)
  return unless current_client && current_tag.id != tag_id
  remove client = current_client
  client.hide
  tag = find_tag_or_create tag_id
  tag.current_column_or_create << client
  Column::Arranger.new(tag.columns, tag.geo).redraw
  tag.each_column &:arrange_clients
  current_client.focus if current_client
  update_widgets
end

#include?(client) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/uh/layout.rb', line 35

def include?(client)
  screens.any? { |screen| screen.include? client }
end

#remove(client) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/uh/layout.rb', line 63

def remove(client)
  screen, tag, column = find_client client
  column.remove client
  Column::Arranger.new(tag.columns, tag.geo).redraw
  tag.each_column &:arrange_clients
  column.show_hide_clients
  current_client.focus if current_client
  update_widgets
end

#suggest_geoObject



48
49
50
# File 'lib/uh/layout.rb', line 48

def suggest_geo
  (current_column or current_tag).geo.dup
end

#to_sObject



27
28
29
# File 'lib/uh/layout.rb', line 27

def to_s
  Dumper.new(self).to_s
end

#update_widgetsObject



43
44
45
46
# File 'lib/uh/layout.rb', line 43

def update_widgets
  @widgets.each &:update
  @widgets.each &:redraw
end