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.2.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLayout

Returns a new instance of Layout.



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

def initialize
  @screens  = Container.new
  @widgets  = []
  @colors   = COLORS
  @history  = History.new
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



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

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



52
53
54
# File 'lib/uh/layout.rb', line 52

def current_client
  current_column and current_column.current_client
end

#handle_client_column_set(direction, mover: client_mover_for_current_tag) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/uh/layout.rb', line 150

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



136
137
138
139
140
141
142
# File 'lib/uh/layout.rb', line 136

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



144
145
146
147
148
# File 'lib/uh/layout.rb', line 144

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



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

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



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

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



158
159
160
# File 'lib/uh/layout.rb', line 158

def handle_history_tag_pred
  handle_tag_sel @history.last_tag.id
end

#handle_kill_currentObject



162
163
164
# File 'lib/uh/layout.rb', line 162

def handle_kill_current
  current_client and current_client.kill
end

#handle_screen_sel(direction) ⇒ Object



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

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

#handle_screen_set(direction) ⇒ Object



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

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



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

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



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

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)


56
57
58
# File 'lib/uh/layout.rb', line 56

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

#register(display) ⇒ Object



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

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

#remove(client) ⇒ Object



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

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



65
66
67
# File 'lib/uh/layout.rb', line 65

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

#to_sObject



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

def to_s
  Dumper.new(self).to_s
end

#update_widgetsObject



60
61
62
63
# File 'lib/uh/layout.rb', line 60

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