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/history.rb,
lib/uh/layout/version.rb,
lib/uh/layout/container.rb,
lib/uh/layout/registrant.rb,
lib/uh/layout/arrangers/stack.rb,
lib/uh/layout/arrangers/vert_tile.rb,
lib/uh/layout/client_column_mover.rb,
lib/uh/layout/arrangers/fixed_width.rb

Defined Under Namespace

Modules: Arrangers, Registrant Classes: Bar, ClientColumnMover, Column, Container, Dumper, History, Screen, Tag

Constant Summary collapse

Error =
Class.new(StandardError)
RuntimeError =
Class.new(RuntimeError)
ArgumentError =
Class.new(Error)
COLORS =
{
  fg:   'rgb:d0/d0/d0'.freeze,
  bg:   'rgb:0c/0c/0c'.freeze,
  sel:  'rgb:d7/00/5f'.freeze,
  hi:   'rgb:82/00/3a'.freeze
}.freeze
VERSION =
'0.3.2'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Layout

Returns a new instance of Layout.



37
38
39
40
41
42
43
44
# File 'lib/uh/layout.rb', line 37

def initialize **options
  @screens  = Container.new
  @widgets  = []
  @colors   = COLORS
  @history  = History.new

  @colors = @colors.merge options[:colors] if options.key? :colors
end

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



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

def colors
  @colors
end

#historyObject (readonly)

Returns the value of attribute history.



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

def history
  @history
end

#screensObject (readonly)

Returns the value of attribute screens.



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

def screens
  @screens
end

#widgetsObject (readonly)

Returns the value of attribute widgets.



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

def widgets
  @widgets
end

Instance Method Details

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



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

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

#current_clientObject



54
55
56
# File 'lib/uh/layout.rb', line 54

def current_client
  current_column and current_column.current_client
end

#expose(window) ⇒ Object



95
96
97
# File 'lib/uh/layout.rb', line 95

def expose(window)
  update_widgets
end

#handle_client_column_set(direction, mover: client_mover_for_current_tag) ⇒ Object



160
161
162
163
164
165
166
# File 'lib/uh/layout.rb', line 160

def handle_client_column_set(direction, mover: client_mover_for_current_tag)
  return unless current_client
  mover.move_current direction
  current_tag.arrange_columns
  current_tag.each_column &:show_hide_clients
  update_widgets
end

#handle_client_sel(direction) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/uh/layout.rb', line 146

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



154
155
156
157
158
# File 'lib/uh/layout.rb', line 154

def handle_client_swap(direction)
  return unless current_client && current_column.clients.size >= 2
  current_column.client_swap direction
  update_widgets
end

#handle_column_mode_toggleObject



139
140
141
142
143
144
# File 'lib/uh/layout.rb', line 139

def handle_column_mode_toggle
  return unless current_column
  current_column.mode_toggle
  current_column.arrange_clients
  current_column.show_hide_clients
end

#handle_column_sel(direction) ⇒ Object



132
133
134
135
136
137
# File 'lib/uh/layout.rb', line 132

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

#handle_history_tag_predObject



168
169
170
# File 'lib/uh/layout.rb', line 168

def handle_history_tag_pred
  handle_tag_sel @history.last_tag.id
end

#handle_kill_currentObject



172
173
174
# File 'lib/uh/layout.rb', line 172

def handle_kill_current
  current_client and current_client.kill
end

#handle_screen_sel(direction) ⇒ Object



99
100
101
102
103
# File 'lib/uh/layout.rb', line 99

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

#handle_screen_set(direction) ⇒ Object



105
106
107
108
109
110
# File 'lib/uh/layout.rb', line 105

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



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

def handle_tag_sel(tag_id)
  tag_id = tag_id.to_s
  return unless current_tag.id != tag_id
  @history.record_tag current_tag
  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



123
124
125
126
127
128
129
130
# File 'lib/uh/layout.rb', line 123

def handle_tag_set(tag_id)
  return unless current_client && current_tag.id != tag_id
  previous_tag_id = current_tag.id
  remove client = current_client
  handle_tag_sel tag_id
  push client
  handle_tag_sel previous_tag_id
end

#include?(client) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/uh/layout.rb', line 58

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

#register(display) ⇒ Object



46
47
48
# File 'lib/uh/layout.rb', line 46

def register(display)
  Registrant.register self, display
end

#remove(client) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/uh/layout.rb', line 82

def remove(client)
  screen, tag, column = find_client client
  column.remove client
  tag.arrange_columns
  column.show_hide_clients
  current_client.focus if current_client
  update_widgets
end

#suggest_geoObject



67
68
69
# File 'lib/uh/layout.rb', line 67

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

#to_sObject



50
51
52
# File 'lib/uh/layout.rb', line 50

def to_s
  Dumper.new(self).to_s
end

#update(client) ⇒ Object



91
92
93
# File 'lib/uh/layout.rb', line 91

def update(client)
  update_widgets unless client.hidden?
end

#update_widgetsObject



62
63
64
65
# File 'lib/uh/layout.rb', line 62

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